Repository navigation
Commit da407dc
fix(git): correct the machine-output flag set and stop diluting gain stats
Fork-authored amendment on top of 46d16ea (cherry-picked from upstream rtk-ai#2573).
Kept separate so the contributor's commit stays intact and attributable.
Three defects found by code review on PR #68, each reproduced against native
git before and after.
1. `--word-porcelain` is not a git flag.
`git diff --word-porcelain` exits 129 (unknown option). The real
machine-readable spelling is `--word-diff=porcelain`, and because the guard
uses `matches!` on exact equality it never matched. So the adopted list had
one dead arm and one real gap. Replaced the former with the latter.
`--word-diff=plain` and `--word-diff=color` are human-facing and stay
compacted; only the porcelain variant passes through.
before: rtk git diff --word-diff=porcelain -> compacted
after : native 6706 bytes | rtk 6706 bytes
2. `-z` was unhandled for `git log`.
Issue #48 names `-z` explicitly, but log_args_request_machine_output only
matched --format/--pretty variants. `git log -z --name-only` carries no
custom format, so it fell to the compact path — which injects its own
--pretty=format:<MARKER>, -10 and --no-merges and then filters. That is
precisely the corruption this guard exists to prevent.
before: native 2267 bytes | rtk 564 bytes (decorated)
after : native 2267 bytes | rtk 2267 bytes
3. `--no-color` was treated as machine output.
It only suppresses ANSI and says nothing about the format, so listing it
bought a full passthrough and silently disabled compaction for a commonly
passed flag — a cost with no faithfulness gain. Removed.
before: native 6456 bytes | rtk 6456 bytes (passthrough)
after : native 6456 bytes | rtk 6365 bytes (compacted)
Also switches the three new log/status tracking calls from
`timer.track(.., &stdout, &stdout)` to `timer.track_passthrough(..)`. Equal
non-zero token counts record 0%-savings rows that dilute `rtk gain`;
tracking.rs documents track_passthrough for exactly this, and run_passthrough
in this same file already uses it. The pre-existing calls in run_diff and
run_show are left alone — they predate this change.
Tests: the contributor's diff-flag test asserted `--word-porcelain` is machine
output, encoding the belief that it is a git flag. Updated to assert the intent
instead — the real flag matches, the non-flag does not, and the human-facing
word-diff modes stay compacted.
Adds tests/git_machine_output_test.rs. The existing unit tests only cover the
flag predicates, so swapping `print!` back to `println!("{}", stdout.trim())`
would still pass all of them while dropping the trailing newline. The new test
runs the built binary (CARGO_BIN_EXE_rtk, no install needed) against real git
and compares bytes, with a counterweight case asserting bare `git status` and
`git diff --no-color` stay compacted so the guard can't be widened until
byte-equality passes trivially.
Not addressed, deliberately: the ~90 lines duplicating run_passthrough, and the
pre-existing loss of stdout on non-zero exit in run_diff (verified present
before this change on --numstat/--name-only/--raw alike). Both are separate
concerns from this adoption.
Quality gate: fmt clean, clippy 0 warnings, cargo test --all 2585 passed,
0 failed (LASTEXITCODE=0).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 46d16ea commit da407dc
2 files changed
Lines changed: 156 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| |||
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
102 | | - | |
103 | 106 | | |
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
107 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
| |||
498 | 503 | | |
499 | 504 | | |
500 | 505 | | |
501 | | - | |
| 506 | + | |
502 | 507 | | |
503 | 508 | | |
504 | | - | |
505 | | - | |
506 | 509 | | |
507 | 510 | | |
508 | 511 | | |
| |||
930 | 933 | | |
931 | 934 | | |
932 | 935 | | |
933 | | - | |
| 936 | + | |
934 | 937 | | |
935 | 938 | | |
936 | | - | |
937 | | - | |
938 | 939 | | |
939 | 940 | | |
940 | 941 | | |
| |||
944 | 945 | | |
945 | 946 | | |
946 | 947 | | |
947 | | - | |
| 948 | + | |
948 | 949 | | |
949 | 950 | | |
950 | | - | |
951 | | - | |
952 | 951 | | |
953 | 952 | | |
954 | 953 | | |
| |||
2297 | 2296 | | |
2298 | 2297 | | |
2299 | 2298 | | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
2300 | 2312 | | |
2301 | 2313 | | |
2302 | 2314 | | |
2303 | 2315 | | |
2304 | 2316 | | |
2305 | 2317 | | |
2306 | 2318 | | |
2307 | | - | |
| 2319 | + | |
2308 | 2320 | | |
2309 | 2321 | | |
2310 | 2322 | | |
2311 | 2323 | | |
2312 | 2324 | | |
2313 | 2325 | | |
2314 | 2326 | | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
2315 | 2355 | | |
2316 | 2356 | | |
2317 | 2357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
0 commit comments