Repository navigation
fix(diff): refresh adoption of upstream #3268 — Myers alignment, FileComparison, listing budgets - #153
Merged
Conversation
`rtk diff <f1> <f2>` decided identity from `str::lines()`, which strips a trailing `\r` and treats the final newline as optional. A CRLF-vs-LF pair printed "[ok] Files are identical" and exited 0, so a verification gate built on `diff` silently passed. Identity is now decided on the bytes, and when the bytes differ while the text matches, the render names the cause instead of listing visually identical strings. `compute_diff` compared line N to line N, so one inserted line desynchronized the whole tail: 200 lines with one insertion rendered 403 lines of output, and the `never_worse` guard threw that away and dumped both files. It now trims the common prefix and suffix and aligns the middle with Myers' greedy algorithm, bounded by a banded trace of 1,000,000 cells rather than by the edit distance. A lopsided pair keeps a window a few diagonals wide however large `d` grows, so one line against five thousand aligns instead of being refused. Every reported change carries a line number in each file. The classic renderer needs both: `NaM` anchors an append in file1 and ranges it in file2, `NdM` does the reverse, and after one insertion neither frame can be derived from the other. A dissimilar in-place rewrite stays one `Replaced` rather than becoming a `Removed` plus an `Added`, so the classic path groups it as a single change hunk without inferring the pairing from equal line numbers. All three listing paths are bounded by count and by bytes, and the aligned path spends its count budget before the script exists: `myers_ops` knows the edit distance when it reaches the end, so one line against 40,000 refuses without cloning a script it would throw away. Past the budget, equal lengths pair by position and say so, and unequal ones report a measured floor plus line bounds in each file. Rebased onto develop, which merged rtk-ai#3048 in the meantime. An empty change list is no longer the "identical" signal: `FileComparison` distinguishes byte identity from an invisible difference and from a refused listing, so an over-cap comparison cannot route through the identical branch and exit 0.
…test Fork-authored amendment on top of acbe88c (cherry-picked from upstream rtk-ai#3268, Ilia Alshanetsky). Kept separate so the contributor's commit stays intact and attributable. The fork's gate runs clippy 1.97 with -D warnings; `start1 >= cursor + 1` in the test-only `replay_classic` helper trips `int_plus_one`. `start1 > cursor` is the same predicate on usize. Not sent upstream: whether their CI pins a clippy that flags it is their call. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This was referenced Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #152. Adoption refresh of upstream rtk-ai#3268 (Ilia Alshanetsky), replacing the early snapshot the fork carried (
ce07aff,54cb3a1, fork testc7d29b0) with the PR's current headecef036.Commits
ecef036diff_cmd.rsfolded into the cherry-pick (no code of the fork's own added).|
7753ec7| kylehgc | Amendment: one-line clippyint_plus_onefix in the PR's test-onlyreplay_classichelper (start1 >= cursor + 1→start1 > cursor). The fork's gate runs clippy 1.97 with-D warnings; kept separate so the contributor's commit stays intact. |Repro, real binaries (before = installed
developbuild, after = this branch)CRLF-only difference and a single insertion render identically on both sides (
differs, text matches (line endings: 0 CRLF vs 2 CRLF), exit 1;0a1 / > NEW, exit 1). The behavioural change is the over-budget case — two 6000-line files with no line in common:What changed vs. the fork's snapshot
compute_diff: LCS table (LCS_CELL_CAP,lcs_ops) → Myers alignment (myers_ops,MAX_TRACE_CELLS) with a bounded positional fallback (POSITIONAL_CHANGE_CAP/POSITIONAL_BYTE_CAP) and an explicitUnalignedreason instead of silently listing everything.run():FileComparison { Identical, InvisibleDifference(cause), Lines(diff) }replaces therender_file_diff(.., content1, content2, &diff)wrapper PR Conflicted Sync: upstream/develop 2026-09-01 (39 commits) #149 had to hand-glue over upstream's fix: render a real diff instead of dumping both files for modified lines rtk-ai/rtk#3048.classic_fallback,tracking_baseline,select_file_diff_outputnow come from the PR itself, integrated with fix: render a real diff instead of dumping both files for modified lines rtk-ai/rtk#3048 by its author.src/core/guard.rs: newINVISIBLE_DIFF_TOKEN_ALLOWANCE(16 tokens) so the invisible-difference message can exceed the raw dump by a bounded amount;never_worseunchanged.describe_invisible_differencenow names CRLF line numbers and adds a frame legend.Resolution (22 conflict blocks, all in
diff_cmd.rs)Every block resolved to the PR's side, with two exceptions, both to keep the fork's region parser (
condense_unified_diff, fork PR #128 / upstream rtk-ai#3788) intact:use anyhow::Result;becameuse anyhow::{Context, Result};—condense_stdinuses.context().render_file_diff/changes_ofhelpers kept, plus the fork's test-local strict/passthroughcondense_unified_diffwrapper appended after them.git diff develop -- src/cmds/git/diff_cmd.rsshows no change to any region-parser symbol. Two fork tests dropped as stale (test_compute_diff_over_cell_cap_emits_wholesale_replacement,test_compute_diff_wholesale_replacement_still_pairs_by_similarity— both assert the removed LCS cap). Two PR tests absent by design (test_condense_unified_diff_large_no_false_overflow_indicator,_no_false_overflow): they are upstream's old condense tests, already replaced by the region parser's own.Safety gate
External code was read in full before any cargo invocation: only
src/cmds/git/diff_cmd.rsandsrc/core/guard.rstouched; noCargo.toml,build.rs, or dependency changes. No process spawning, network, env access, orunsafe; the only filesystem access is the pre-existingfs::read_to_stringof the two compared files; new imports are intra-crate only. Test bodies allocate up to ~1.1 MB strings and run bounded randomized loops (capped byMAX_TRACE_CELLS/POSITIONAL_BYTE_CAP), CPU-heavy but finite.Quality gate
x64 host toolchain:
cargo fmt --allclean ·cargo clippy --all-targets0 warnings (after the amendment; the bare cherry-pick trippedint_plus_one) ·cargo test --all3122 unit tests passed, 0 failed, 8 ignored; all integration suites green. Independent reviewer pass over fidelity to both the PR and the fork's region parser:guard.rsbyte-identical to the PR; every line differing frompr-3268indiff_cmd.rsis region-parser content already ondevelop, theContextimport, or the test-helper wrapper; region parser body byte-identical todevelop; no external callers of the changed private symbols (main.rscalls only the unchangedrun/run_stdin). Only cosmetic note: one blank line before#[cfg(test)]follows the PR's shape now.Upstream status
rtk-ai#3268 is still open with
CHANGES_REQUESTED(KuSh, 2026-09-01). This is an Adoption: self-healing upstream, no upstream PR obligation. If the next review round changes the shape again, this refresh repeats.🤖 Generated with Claude Code