Skip to content

feat(diff3,sdiff): GNU diffutils 3.10 alignment on the shared diff engine (issue #1127 P1) - #1164

Merged
caomengxuan666 merged 1 commit into
mainfrom
feat/diff3-sdiff
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
feat/diff3-sdiff

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes the P1 item of #1127 (partial: P1 only — diff3/sdiff GNU alignment; P2+ untouched).

What

diff3 — rebuilt on a faithful port of GNU diffutils' three-way merge (diff3.c make_3way_diff / using_to_diff3_block):

  • default report with GNU's odd-one-out section rules (====N, content suppression for the odd file, skew order 1→3→2), adjacent-hunk folding and ==== conflict blocks
  • ed scripts: -A/--show-all, -e/--ed, -E/--show-overlap, -3/--easy-only, -x/--overlap-only, -X with GNU's block-selection rules, <<<<<<</|||||||/=======/>>>>>>> bracketing, leading-dot doubling and -i final w/q
  • -m/--merge (bare -m implies -A), -L/--label (up to 3), -T/--initial-tab, -a/--text, --strip-trailing-cr, --diff-program (spawns PROGRAM with GNU's exact read_diff argv and parses its normal output)
  • - stdin operands with GNU's common-file swap, GNU exit statuses (0 ok / 1 conflicts / 2 trouble) and byte-verified usage diagnostics (incompatible options, missing operand after '<last arg>', subsidiary program 'diff' failed)

sdiff — the display is now exactly diff --side-by-side output (GNU sdiff execs diff for it):

  • GNU side.c semantics: gutter formula, |/</>/(/) row markers, / and \ separators when a row's sides disagree on the trailing newline, common rows for equal inputs
  • -l/--left-column, -s/--suppress-common-lines, -w/--width, -t/--expand-tabs, --tabsize
  • ignore-option family forwarded into matching only, with GNU's exact normalization: -i, -E (full tab expansion), -Z (isspace line-end strip), -b (runs collapse, trailing run dropped), -W, -B/-I (ignored hunks drop from the script and their lines realign positionally), -a, --strip-trailing-cr, -d, -H, --diff-program
  • -o/--output writes a merged file non-interactively (per the P1 item's 自动合并 requirement): one-sided changes take their only side, overlapping rows keep the left column; a completed merge exits 0 like GNU's completed interactive merge

diff — adopts the shared engine header (diff_engine.h): side-by-side gains GNU's row rules, -E/-B/-I match GNU semantics, and a final line without a newline only compares equal to the other side's incomplete last line (GNU io.c equivalence classes).

Verification

  • WSL oracle (GNU diffutils 3.10) byte-comparison harness: 87 cases PASS covering every diff3 mode (default/ed/-A/-E/-3/-x/-X/-m combinations, labels, -T, --strip-trailing-cr, - stdin, --diff-program, usage/compat errors) and every sdiff surface (widths 20/30/40/80/130, -l/-s, tabs/--tabsize/-t, long-line truncation, the whole ignore family, /+\ no-newline rows, -o merges, missing operands). The only 5 diffs are -o cases where GNU's interactive % prompt/EOF-quit differs from this PR's auto-merge — the documented deviation requested by the issue.
  • Unit suites rewritten byte-exact: diff 17/17, diff3 19/19, sdiff 17/17; full suite 2809/2811 with the only 2 failures being the pre-existing symlink-privilege grep tests (identical on a pristine origin/main build).
  • Differential gate: regressions/30-sdiff-output-file.case whitelisted with the -o deviation reason; corpus/sdiff/01 display stays byte-identical.
  • i18n: diff3/sdiff option help synced to unixwin/winuxcmd-i18n (zh-CN) and released as 0.6.18.

Notes

…gine (issue #1127 P1)

- diff3: rebuild on a real three-way merge (diff3.c make_3way_diff):
  default report with GNU's odd-one-out section rules and skew order,
  ed scripts for -A/-e/-E/-3/-x/-X with -i final write and dot-doubling,
  -m merged output (-m alone implies -A; -L labels, -T initial tab,
  --strip-trailing-cr, --diff-program with GNU's read_diff argv),
  '-' stdin operands with the common-file swap, and GNU exit statuses
  (0 ok / 1 conflicts / 2 trouble) plus byte-verified usage diagnostics.
- sdiff: display is exactly diff --side-by-side (side.c gutter formula,
  |/<>/(/) markers, //\ separators for missing trailing newlines,
  common rows for equal inputs); -l/-s, -w/--tabsize/-t display control;
  ignore family forwarded into matching only with GNU semantics
  (-E full tab expansion, -b trailing-run drop, -Z isspace strip,
  -B/-I drop ignored hunks and realign positionally); -o writes an
  auto-merged file non-interactively (overlaps keep the left column),
  the documented deviation from GNU's interactive prompt (issue #1127).
- diff: adopts the shared engine header (diff_engine.h); side-by-side
  gains GNU's row rules; -E/-B/-I match GNU semantics; the incomplete
  last line only compares equal to the other side's incomplete last line.
- tests: diff3/sdiff suites rewritten byte-exact against GNU diffutils
  3.10 (WSL oracle, 92-case harness); differential case 30 whitelisted
  for the -o auto-merge deviation; zh-CN catalog synced (i18n 0.6.18).
@caomengxuan666
caomengxuan666 merged commit a12651c into main Oct 10, 2026
5 checks passed
@caomengxuan666
caomengxuan666 deleted the feat/diff3-sdiff branch October 10, 2026 08:54
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