Skip to content

fix(git): filter git show <rev>:<path> blobs instead of passthrough - #3121

Closed
MannXo wants to merge 1 commit into
rtk-ai:developfrom
MannXo:fix/git-show-blob-read-filter
Closed

MannXo wants to merge 1 commit into
rtk-ai:developfrom
MannXo:fix/git-show-blob-read-filter

Conversation

@MannXo

@MannXo MannXo commented Jul 21, 2026

Copy link
Copy Markdown

Summary

  • git show <rev>:<path> prints a file at a revision (a file read), but it was routed to passthrough and emitted uncompressed at 0% savings, while the <rev> -- <path> diff form already compacts.
  • Route the blob form through the same filtering rtk read applies: minimal comment/blank-line stripping with language detected from the path extension, capped at the same 500-line default the diff form uses, guarded by never_worse so small files pass through unchanged.
  • git show --stat and --format variants keep their previous behavior.

Fixes #3116

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test (2444 lib tests pass, zero clippy warnings)
  • New unit tests in src/cmds/git/git.rs: blob-path extraction, comment stripping, 500-line cap with truncation marker, unknown-extension faithfulness, never_worse on tiny input, and a ≥60% savings check
  • Manual testing against a real repo:
    • rtk git show HEAD:Cargo.toml — small file, byte-identical to raw (faithful)
    • rtk git show HEAD:src/cmds/git/git.rs — 3325-line file capped to 500 lines with a [2692 more lines] marker

The `<rev>:<path>` form of `git show` prints a file at a revision, i.e.
a file read, but it was routed to passthrough and emitted uncompressed
(0% savings), while the `<rev> -- <path>` diff form already compacts.

Route the blob form through the same filtering `rtk read` applies:
minimal comment/blank-line stripping with language detected from the
path extension, capped at the same 500-line default the diff form uses,
guarded by `never_worse` so small files pass through unchanged. The
`--stat` and `--format` variants keep their previous behavior.

Fixes rtk-ai#3116
@CLAassistant

CLAassistant commented Jul 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@KuSh

KuSh commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for digging into this. The blob form is filtered on develop now: #3265 (merged 2026-09-11) routes git show <rev>:<path> into a size-capped preview window instead of raw passthrough, so the 0% savings case you reported is gone. Measured on current develop, a 259 KB blob comes back as 8 KB. The merged version keeps raw bytes rather than stripping comments, deliberately, so that non-UTF-8 and binary blobs survive the window, and it also handles the --stat and --format combinations you left on the old path. Closing as covered, but please comment here or reopen if you hit a blob shape the new path still misses.

@KuSh KuSh closed this Sep 12, 2026
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.

rtk git show <rev>:<path> is a file read but routes to passthrough (0% savings) instead of the read filter

3 participants