Skip to content

diff: add -T/--initial-tab - #445

Open
Harp404 wants to merge 3 commits into
uutils:mainfrom
Harp404:diff-initial-tab
Open

Harp404 wants to merge 3 commits into
uutils:mainfrom
Harp404:diff-initial-tab

Conversation

@Harp404

@Harp404 Harp404 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

diff -T / --initial-tab was rejected as an unrecognized option. GNU diff uses it to put a tab between the line marker and the line, so that tabs in the text line up the same way they do in the files:

$ diff -T a b        $ diff -T -u a b
2c2                  @@ -1,3 +1,3 @@
<	b                	a
---                  -	b
>	B                +	B

This adds the option to Params and handles it in line_prefix, which the normal, context and unified formats already use for their markers. The space that ends the marker becomes a tab (< → <\t, ! → !\t, the unified context marker → \t), and a tab is added after the unified - and +. --suppress-blank-empty still drops the marker's blank on empty lines, as in GNU. The ed, ifdef and side-by-side formats are unchanged, and GNU doesn't change them either.

I compared -T, --initial-tab, -T -u, -T -c, -T -U0, -T -C1, -T -e, -T -D X, -T -t, -T -t -u, -T -q and -T with --suppress-blank-empty against GNU diff 3.12 on two pairs of files (one with an empty line and a tab in the text). The output and exit status match.

The new initial_tab cases fail on main and pass with this change. cargo fmt --check and cargo clippy -- -D warnings are clean. cargo test fails only ifdef_diff_identical, ifdef_diff_identical_report and ifdef_diff_missing_newline, which fail on main as well; #444 fixes those.

I used Claude Code (Opus 5.5) to help investigate and draft this change; I checked the output against GNU diff myself.

Put a tab instead of a space between the line marker and the line in
the normal, context and unified formats, as GNU diff does.
Copilot AI balanced review requested due to automatic review settings November 30, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@Harp404

Harp404 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

The cargo test failures here are the 3 ifdef_diff_identical* tests that already fail on main (see #444). Everything else passes, including the new initial_tab cases. They should go green once #444 is merged, and I can rebase this then.

Comment thread tests/by-util/test_diff.rs Outdated
let stdout = result.stdout_str();
let body = if args.contains(&"-u") {
stdout.splitn(3, '\n').nth(2).unwrap()
} else if args.contains(&"-c") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both branches are the same, could be merged with a ||, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, merged them into one || in f2f8416.

Comment thread src/params.rs
params.ignore_tab_expansion = true;
continue;
}
if param == "-T" || param == "--initial-tab" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add -T / --initial-tab cases to the parse_params tests too, like -E

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added initial_tab_short and initial_tab_long cases next to the -E ones in f2f8416. I also merged main to fix the conflict with #444.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 02:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants