7 Commits
Author SHA1 Message Date
unsc9 9f1724e3df fix(diff): 改动块内的 ---/+++ 不再当文件头,删掉 -- … 行不再截断 diff
删除行的 diff 原文是 `-` 加源码原文,所以删掉一行以「`-- `」(两个减号加
一个空格)开头的内容——SQL / Lua / Haskell 注释、文档或脚本里的命令行参数
行——会产出 `--- foo`,与文件头分隔行 `--- a/路径` 逐字节同形。解析器把
「在 hunk 内」那道闸门排在 `---`/`+++` 两个分支之后,等于没保护它们:命中
后当前 hunk 当场被截断(该行之后没有 `@@` 可重新同步时,剩下的改动整段不
显示),并把被删文本盖到 oldPath 上。新增行原文以 `++ ` 开头(C 的
`++ i;`)同理会把 newPath 改成 `i;` 并丢掉那一行。

git 从不在 hunk 内写 `---`/`+++`,所以判据是「在不在 hunk 内」:两个分支
各加 !inHunk 守卫(等价于把它们挪到那道闸门之后)。

实测(同一份 fixture,修复前 → 修复后,直接跑真实 parseUnifiedDiff):

  删掉 `-- foo`:oldPath `"foo"` → `"a/sample.txt"`;hunk 1 行 → 3 行
  新增 `++ i;`:newPath `"i;"` → `"b/loop.c"`;新增行丢失 → 保留
  统计与 `git diff --numstat` 一致(0/1 与 1/0)

用例:`tests/diff-rows.spec.ts` 新增一组 3 例(删除行、新增行,以及 hunk
之后的真文件头仍要认得——守护这道守卫别把正常头也挡掉)。
2026-10-10 20:34:23 +08:00
Menghuan1918 4a03e131e5 fix(diff): 会话镜头 diff 的超大输入退化为全删全增,不再建稠密 LCS 表(#734)
rows.ts 的 lcsTable 是无护栏的稠密普通数组矩阵(每单元约 8 字节),成本
完全由输入行数乘积决定。实测:1000×1000 → 8MB、3000×3000 → 71MB、
5000×5000 → 193MB、10000×10000 → heapDelta 765MB(峰值 RSS 865MB)。
会话镜头把上一次 write 的完整文件内容当 prior 传进 diffOf(ops.ts 对
content 无字节/行数截断),选中一个 op 就在 useMemo 里同步跑完,因此一份
万行文件的改动预览会一次性吃掉数百 MB 主线程内存。

护栏落在 diffLines 内部、lcsTable 调用之前(它是会话镜头唯一的 LCS 入口,
一处覆盖 diffOf 的三个分支):新增导出常量 MAX_LCS_CELLS = 4_000_000
(≈32MB,仍精确覆盖 2000×2000 的重写配对),判定
oldLines.length * newLines.length;超限不建表,直接产出全删(oldLines
顺序,oldLine 1..n)+ 全增(newLines 顺序,newLine 1..m)。

退化路径同时跳过 pairMods:在没有找到任何对齐的情况下,del 段与 add 段
会被成对标成 mod,那不是「已判定为改写」。所以退化语义是无 context、无
mod,只有 del/add。10000×10000(中间改一行制造错位)实测 0.44–0.96ms,
原实现为 592ms/765MB;渲染侧既有 MAX_ROWS = 600 截断,无需新增提示文案。

测试新增规模用例(20000 行、kind 全为 del/add、两侧行号严格递增
1..10000、单次耗时 < 2000ms,阈值按慢 CI 放宽)与边界用例(恰好
MAX_LCS_CELLS 时仍走表路径)。

Refs #734
2026-10-05 01:29:00 +08:00
HuanLinOTO a5c3befc57 Merge PR #664: fix(diff): 二进制/纯重命名/仅改模式的文件行补回路径,并关掉 git 路径 C 转义 2026-10-01 17:18:09 +08:00
ymac 43a209939c fix(diff): count a rewritten line once in the +n/-m chips
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.
2026-09-14 00:11:40 +08:00
ymac e4b189b7b5 fix(diff): name the rows git sends without ---/+++
git emits no ---/+++ for a binary file, a pure rename and a mode-only
change, and parseUnifiedDiff only ever read paths from those two lines.
The section therefore kept oldPath/newPath === '', so DiffFiles drew a
header carrying just the binary badge and no file name (sandwiched
between two .md rows, which is exactly how it reads as if those .md files
were the binary ones), and a pure rename / mode-only change collapsed to
an empty disabled button (no path, and fileTag cannot see a rename).

Recover the paths in order of authority: ---/+++ when present, else the
section's own `rename from|to`, `Binary files A and B differ`, or the
`diff --git` header. Only the mode-only shape needs the last one: it takes
the ` b/` whose two sides name the same file, and leaves the path empty
rather than guessing. ---/+++ values also lose the TAB git appends to a
spaced path, and decodeGitPath undoes git's C-quoting so diff text from a
default-quotePath source still renders the real file name.

runGit gains `-c core.quotePath=false` for the same reason at the source:
git's default turns a space/CJK path into an octal-escaped quoted string,
which every diff surface then renders as the file name. The `-z`-framed
porcelain callers are unaffected (git never quotes NUL-framed output).

Verified against taktop_redo 8b4b933, the commit whose three .jpg rows
rendered as bare badges: all three now carry their full path, and real git
output for space/CJK paths parses with no escapes and no trailing TAB.
New tests: tests/diff-binary-row.spec.tsx (rendered rows) and the path
matrix in tests/diff-rows.spec.ts; tests/git-spawn.spec.ts now derives the
subcommand from runGit's prefix instead of counting its flags.

tests/git.spec.ts had pinned the empty path (`oldPath === ''`) as the known
behaviour of a mode/rename-only section; it now asserts the recovered paths
instead, and the binary section there asserts its own name too.
2026-09-14 00:08:38 +08:00
haruhi d990c10e59 feat(diff): 折叠行异步展开状态机与内容切片
- src/client/api.ts: 仿 gitCommitDiff 新增 gitShow 封装,走既有 git.show 服务路由(payload {rev, path},返回 content 或 null),服务端零改动
- src/client/diff/rows.ts: 新增 foldRowsFromContents 纯函数——old 侧按 fold 行号切片为 context 行(new 侧经区间偏移映射,落界才带行号),new 侧补纯增行;越界截断、\r 保留
- src/client/diff/DiffRows.tsx: 新增 resolveFold prop;foldData/foldLoading/foldFailed 三态,加载中不可点,失败降级静态标记;foldEpoch 使 segments 重置后 in-flight 回调失效
- src/client/diff/DiffFiles.tsx: resolveFold 下传各文件 DiffRows,fold 级 Promise 缓存去重并发点击与重挂载
- tests/diff-rows.spec.ts: foldRowsFromContents 六用例(对称/纯删/纯增/\r\n/空内容/越界)

背景:git -U3 不输出 hunk 间未改动行,gap fold 只有行号范围没有 rows,渲染复用「点击展开」文案却无交互;展开能力建为独立状态机(含 api 封装),git lens 只需注入取数 loader。
设计 docs/plans/2026-09-07-git-fold-expand-design.md §4.1-4.4。
2026-09-07 23:51:06 +08:00
Menghuan1918 24a3813c63 feat!: 合并 Git 面板与文件追踪为统一「文件变动」tab(双视角 + 统一 diff 栈)
在 PR #471(file-trace)基础上的演进:

- 合并 tab:git tab(id 保留,兼容持久化布局)升级为「文件变动」双视角
  tab——Git 视角(原 GitView 全部能力:staged/unstaged/提交/历史/worktree·
  子仓库选择/右键菜单/确认弹窗)+ 本轮文件视角(原 file-trace:会话事件
  日志实时折叠的模型读写编辑记录,按文件分组、新增类型筛选 chips、相对
  时间);file-trace tab 移除(未随任何版本发布)。
- 统一 diff 组件:新 src/client/diff/ 模块(rows.ts 引擎 + DiffRows/
  DiffFiles 渲染器 + highlight.ts 语法着色)——git diff 与会话操作 diff
  共用一套渲染:mod 改写配对(del-run/add-run 对半标蓝)、行内字符级
  高亮(修复了旧实现旧侧失配不高亮的问题,改为行对象身份键)、上下文
  hunk 折叠、git hunk 间未输出区间按行号范围生成不可展开折叠、语法着色
  色相落位 diff 三色空档、+n −m 统计 chips、行底色 tint;DiffTab 改用
  该栈(git diff tab 从此也有高亮)。
- 交互:两视角共用底部可拖拽预览面板(点击文件/提交/操作即预览,不再
  直接开 diff tab;面板可刷新、可键盘/拖拽调高、git 目标可一键展开为
  独立 diff tab);视角选择与面板高度持久化在 tab.meta;git 行 XY 徽章
  按状态字母着色;选中行高亮。
- i18n:fileTrace* 十键重命名为 changes* 前缀,git 键值更新为「文件
  变动」,新增 7 键(视角/筛选/面板操作),全部 21 个词典同步。
- 结构:src/client/changes/(ChangesTab/GitLens/SessionLens/DiffPane/
  ops)+ src/client/diff/;GitView/DiffView/filetrace/ 删除;git 样式
  从 sidebar.module.css 迁至 changes.module.css。
- 测试:builtins 8→7(git tab 承接 badge pin)、diff-rows(unified
  转换/mod 配对/间隙折叠/统计)、changes-tab(壳交互 jsdom)、
  diff-files-collapse(原 DiffView 折叠行为钉住)、changes-ops(原
  filetrace 数据层)、git-view-worktree 迁移至 GitLens;全量 1122 通过。
- 文档:README ×2 功能矩阵合并、external-plugin-guide §4.4 与内置清单
  7 tab、mount e2e 菜单标题同步。
2026-08-31 01:31:22 +08:00