Skip to content

WIP: feat(diff): diff3/sdiff GNU alignment (#1127 P1) - #1459

Merged
caomengxuan666 merged 3 commits into
mainfrom
fix/1127-diff3-sdiff
Oct 31, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
fix/1127-diff3-sdiff

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Refs #1127 (P1 wave only — the plan issue stays open for P2–P5).

diff 家族收尾波:sdiff 的四个 KNOWN_DIFF 全部按 GNU diffutils 3.10 逐字节对齐,diff3 补 -A -L 标签金标。

sdiff -o 交互合并(原自动合并与 GNU 在 % 提示上分歧,corpus 18/19 + regressions/30 因此挂 whitelist):

  • 实现 GNU sdiff.c 的 interact + edit 协议:逐 hunk 展示、% 提示、l/r 选边、s/v 通行行展示开关、e* 家族($EDITOR,未设时 "ed",含 ed 的 --- / +++ 装饰头)、q → 退出码 2 且输出文件保留已合并前缀;非法命令把帮助文本打到 stderr 并重问。
  • 保留一条已裁定的偏离(📋 后续工作计划:diff3/sdiff 对齐、help 覆盖修复、测试框架、性能轮 #1127 P1 本身的口径 + 单元测试契约):提示处遇 EOF 时 GNU 按 q 退出,本实现切换为自动合并剩余 hunk 并报完成裁决(成对/多余删除取左、右溢出插入取右)。stdin 给出命令时与 GNU 完全一致。

定位分节渲染(corpus 11 的根因):-B/-I 忽略的 hunk 不再走 drop_ignored_hunks 的 1:1 重配对(会吞掉单侧 common 行,如 f1=x/空/y/A vs f2=x/y/B 中 y 的 ( 行),改为在 diff_engine 新增 SdiffSection 定位渲染器:common 跨度按两文件各自原始行界位置配对( /)/( 行),与 GNU analyze.c + side.c 一致。sdiff 的显示与 -o 合并共用同一分节行走。

--strip-trailing-cr(corpus 15):GNU 在 io.c 读入时即剥 CR,显示行同步剥除(原实现仅比较时剥);合并输出仍逐行复制原始字节(GNU 的 line filter 直读原文件),corpus 29 钉住这一不对称。

diff3:实现已完备(前波落地),本波只补金标 27(-A + -L 标签的 ed 脚本冲突标记形状),其余 P1 选项与既有 26 例一一对应。

测试:新增 corpus 金标 sdiff 21–29、diff3 27;单元测试补交互 r/q/非法命令三例(tests/unit/sdiff)。baseline.json 已按 CI 裁定更新(11/15/18/19 翻 PASS、十条新例登记 PASS),whitelist 五条失效条目(regressions/30 + corpus/sdiff 11/15/18/19)已摘除。

CI 裁定(HEAD 0cb1d38):构建 CI run 41169462203 双架构全绿(含 ctest);差分 run 41169462185 的 oracle/compare 全绿、baseline 中 diff 家族 57 例全 PASS——全语料唯一红点是 regressions/70-env-ignore-environment-child-block(main 上既存的常设噪声,与本 PR 无关)。中途 case 22 曾 OUT_DIFF:GNU give_help 文本并无前导换行(od 逐字节核对),已随 0cb1d38 修正。

i18n:本波未改动任何用户可见字符串(--help/选项文案未动),无 catalog 影响。sdiff.cpp 头注释已按新语义订正(非用户可见)。

…sections, stripped-CR display

- sdiff -o now runs GNU's interactive merge (sdiff.c edit loop):
  per-hunk display, '%' prompts, l/r choices, s/v display toggles,
  the e*  family, q -> exit 2 with the output file partial.
  EOF at a prompt keeps the recorded #1127 P1 auto-merge fallback
  (completed-merge verdict), preserving the unit-test contract.
- Side-by-side rendering and merging now walk positional sections
  over the raw script (new diff_engine SdiffSection renderer):
  -B/-I-ignored hunks rejoin the common spans and pair positionally
  ('('/ ')' rows), matching GNU analyze.c + side.c - the old
  drop_ignored_hunks realignment lost one-sided common rows.
- --strip-trailing-cr now strips the display lines too (GNU strips
  on input in io.c); the merged output still copies the raw lines.
- Goldens: sdiff corpus 21-29 (quit/help/toggles/right/delete/
  insert/-B pairing/strip-CR merge) + diff3 27 (-A with -L labels);
  unit tests for the interactive r / q / invalid-command paths.
…list收尾

- corpus/sdiff/22 OUT_DIFF root cause: GNU sdiff's give_help text
  starts directly with 'ed:' (verified byte-exact with od against
  diffutils 3.10); drop the spurious leading newline from
  kInteractHelp and from the unit expectation.
- baseline.json: corpus/sdiff 11/15/18/19 flip KNOWN_DIFF -> PASS
  (CI run 41166929035 adjudicated), entries added for the ten new
  wave cases (diff3/27, sdiff/21-29), all PASS.
- whitelist.txt: remove the five entries whose divergences are
  fixed (regressions/30, corpus/sdiff 11/15/18/19).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 05:05
@caomengxuan666
caomengxuan666 merged commit e051440 into main Oct 31, 2026
9 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1127-diff3-sdiff branch November 2, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant