Repository navigation
fix(diff): 头部 +n/−m 改为 git 口径,一处改写不再两侧各计一次 - #665
Merged
Menghuan1918 merged 1 commit intoOct 4, 2026
Merged
Conversation
diffStats counted ROWS, treating every `mod` row as both an insertion and a deletion — but pairMods turns one rewritten line into two `mod` rows (one per side), so a single-line rewrite reported +2 -2. Neither reference agrees with that: `git diff --numstat` says 1/1, and the renderer draws exactly one `-old` plus one `+new` line for it. Count sides instead: an `add` row, or the new side of a `mod` row, is one insertion; a `del` row, or the old side, is one deletion. On the commit that surfaced this (taktop_redo 8b4b933) the changes-tab header read +3300 -2 while `git show --shortstat` printed "3299 insertions(+), 1 deletion(-)"; it now reads +3299 -1, and CURRENT_STATUS.md's chip reads +8 -1 against numstat's `8 1`. The session-op lane (the same function over diffLines rows) moves to the same accounting. tests/diff-rows.spec.ts replaces the "mods on both sides" expectation (5/4 -> 3/2 for the same fixture) and adds a single-line-rewrite case plus a session-op case.
This was referenced Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
diffStats(src/client/diff/rows.ts:504)数的是渲染行,而pairMods(rows.ts:48-64)把一处改写拆成两行mod(旧侧一行、新侧一行),函数对每一行都added += 1; deleted += 1—— 一处改写被记成 +2 −2。两个参照都不支持这个数字:
git diff --numstat-old+ 一行+new= 1 删 1 增连它自己 JSDoc 声称的「行数」口径也不自洽:一对改写只有 2 行,却使
added和deleted各 +2(合计 4)。测试里那条counts header stats with mods on both sides(tests/diff-rows.spec.ts:96)是把现状写成了期望,不是外部契约。用户可见的影响是头部数字与 git 对不上账。实测
taktop_redo8b4b933,git show --shortstat是3299 insertions(+), 1 deletion(-),插件头部显示+3300 −2;该 commit 的CURRENT_STATUS.md芯片显示+9 −2,numstat 是8 1。差值恰好等于改写行数(1 处 → 每列各多 1)。头部数字来自
DiffPane.tsx:403-413对diffStats的求和,不是 git 的 shortstat,所以这 1 是插件自己算出来的。修复
按「行在哪一侧」计数,而不是每行乘 2:
pairMods不动:一处改写仍然渲染两行(旧侧、新侧,带 intra-line 高亮),只是头部不再把一对当两对。修后 8b4b933 头部 =+3299 −1,CURRENT_STATUS.md芯片 =+8 −1;同一函数的会话 op 摘要(DiffPane.tsx:346)随之落到同一口径(单行改写+2 −2→+1 −1)。测试
tests/diff-rows.spec.ts的mods on both sides期望{5, 4}→{3, 2}(同一 fixture:两处改写 + 1 行纯新增),用例名与注释改为描述 git 口径;{1, 1}(回归主断言,注释里写明 numstat 对照值);会话 op 车道(diffLines)→{1, 1}与{1, 0};{2, 0}不变。验证
pnpm vitest run tests/diff-rows.spec.ts;pnpm typecheck/pnpm lint/pnpm build绿pnpm test:1315 passed,33 failed 全部是tests/agent-pty.spec.ts+tests/smoke.spec.ts的posix_spawnp failed(PTY 在本机沙箱起不来,origin/main裸基线重跑同样 33 个失败)git show --shortstat一致文档同步
无。