Skip to content

WIP: sdiff -o exit status (#1441), diff/sdiff -I as BRE (#1449), tac -r empty-matching separator (#1447) - #1451

Merged
caomengxuan666 merged 3 commits into
mainfrom
fix/1441-1449-1447-sdiff-tac
Oct 30, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
fix/1441-1449-1447-sdiff-tac

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Three small GNU-compat fixes for the diff family and tac, one commit each. Draft for CI adjudication — the main session closes the issues after verification.

#1441 — sdiff -o exit status (commit 1)

The -o path unconditionally returned 0 after a completed merge, and the unit test sdiff_output_file_auto_merges_non_interactively pinned 0 under a wrong "like GNU's completed interactive merge" comment. GNU diffutils 3.10: merging two different files exits 1 (paired, insertion-only, and deletion-only differences alike); identical inputs exit 0; trouble stays 2. The merge now reports the subsidiary diff's verdict — 1 exactly when the final edit script (after any -B/-I hunks are dropped) still holds a non-KEEP edit. The named test's expectation and comment are corrected, as are the two sibling -o tests that pinned the same wrong 0 (takes_right_for_right_only_changes, keeps_left_for_conflicting_rows), plus a new identical-inputs -o pin for the 0 face. Corpus whitelist entries for cases 18/19 are updated: the exit-status divergence is gone, only the interactive % prompt divergence (by design, #1127 P1) remains.

#1449 — diff/sdiff -I is a regular expression (commit 2)

make_blank_or_matching_predicate matched the -I argument as a literal substring (std::string::find), so any pattern with metacharacters silently failed to ignore hunks. GNU compiles each -I RE as a basic regular expression (oracle-verified: \+, \(...\), \|, \{n\} are the special forms; bare +(){}| are literal) and searches each changed line with it. The predicate now takes compiled portable_regex patterns (the repo's shared engine, Syntax::Basic — the same choice diff already makes for --show-function-line and tac makes for -r):

  • A hunk is ignored iff every changed line is ignored, where a line is ignored iff it is blank under -B or matches at least one -I RE. This is GNU's per-line invisibility model; it also fixes two latent faces of the old all-blank-OR-all-match shape: a blank-only hunk is no longer dropped under -I alone, and a mixed blank+matching hunk is now dropped under -B -I (both oracle-verified).
  • Repeated -I/--ignore-matching-lines options accumulate (GNU semantics; previously only one value survived), in both diff and sdiff, collected via ctx.string_occurrences (the house idiom used for -x/-X).
  • An invalid RE is rejected at startup with the existing house diagnostic diff: invalid regular expression '<pat>' and exit 2 (same message/exit the --show-function-line path already uses; GNU exits 2 as well). In sdiff the compile happens after operand resolution, matching GNU sdiff's observable error order.
  • The latent literal twin filter_matching_lines (no callers) is converted to the same compiled patterns.

Corpus case corpus/sdiff/12-ignore-matching-lines.case is expected to flip from EXIT_DIFF to PASS; its baseline entry is updated accordingly.

#1447 — tac -r empty-matching separator (commit 3)

tac -r -s 'x*' errored out ("separator regex matches empty string") at the first zero-length match; GNU coreutils 9.4 accepts it. The regex splitter is rewritten to GNU's match model: separator matches are discovered right-to-left — at each step the match with the largest start in the not-yet-claimed prefix, longest at that start (this is what glibc's backward re_search in tac.c returns) — and records are the segments between consecutive match ends (default) or match starts (-b). Empty matches are ordinary separators under this model and cannot loop: each step strictly shrinks the unclaimed prefix. The model was verified byte-for-byte against the local GNU 9.4 oracle on 30+ pattern/input shapes (x*, .*, .+, .., b*, a*, [a-c]*, .*x, x.*, with and without -b), including every shape where the old forward find_all walk and GNU disagree. The obsolete error string is removed with the error path; no user-visible strings are added or changed.

Regression tests are added in the repo's unit-test style for all three issues, named with the issue numbers.

Refs #1441
Refs #1449
Refs #1447

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