Expand description
Per-file hunk scanner for the /diff overlay.
Extends super’s numstat-based snapshot with full unified-diff
content needed to render the GitHub-style diff viewer. Runs up to
three subprocess calls per scan:
git diff <target> --name-status- file list with M/A/D/R classification.git diff <target> --no-ext-diff- full unified-diff body. The flag defeats user-configured difftastic / delta so the parser sees standard unified-diff format.git ls-files --others --exclude-standard- untracked files (only whentarget == "HEAD", capped atMAX_UNTRACKED_FILESentries, each read up toMAX_UNTRACKED_FILE_SIZEbytes).
Single-shot - never polled. The /diff overlay calls scan on
open and renders the resulting Vec<FileHunks> for the duration
of the view; refreshing mid-review would invalidate pending
comments anchored to specific lines.
Always returns a ScanOutcome - files may be empty on a
genuinely clean tree OR when one of the subprocess calls hit
Failed / Oversize. The scanner_ok flag distinguishes the two
so a downstream renderer can show “scan failed” rather than
miscategorising the empty result as “no changes.”
Structs§
- Commit
Meta - One commit in the review stepper’s ordered list.
shais the full hash (used to scope the per-commit diff),short_shathe abbreviated form for display,subjectthe commit’s first line.bodyis the message beyond the subject, filled lazily byscan_commit_bodywhen the stepper first lands on the commit (empty until then, and for a subject-only commit). - Diff
Line - One rendered diff line. Carries its kind, raw text (no leading marker), and per-side line numbers so the renderer can show a gutter without recomputing positions.
- File
Hunks - One file’s worth of hunks, ordered as
git diffemitted them. - Hunk
- A single
@@-delimited hunk inside one file’s diff.linespreserves the original unified-diff ordering with each line tagged as context, added, or removed - the renderer iterates them directly to draw the+ / - /markers and per-side line numbers without re-classifying anything. - Scan
Outcome - Outcome of a single scan invocation.
filescarries whatever was parsed;scanner_okisfalsewhen at least one of the underlying subprocess calls hitFailedorOversize- the file list may be partial or empty, and a downstream renderer should distinguish that case from a genuine clean tree so the user knows whether to retry vs. accept “no changes.”
Enums§
- Diff
Line Kind - Per-line classification inside a hunk.
- File
Status - How git classified one file’s change.
Constants§
- MAX_
UNTRACKED_ FILES - Skip the untracked-file scan entirely when the working tree
has more than this many untracked entries. A fresh-repo state
with hundreds of untracked files would otherwise dump everything
into the overlay. The Inspector GIT section is unaffected; only
the
/diffoverlay’s untracked surface is suppressed (noUrows render in the rail when the cap is exceeded).
Functions§
- scan
- Top-level scanner entry.
targetis a plain ref / SHA /"HEAD"(not a../...range - the helperdiff_ref_specpicks the shape for us)."HEAD"runs a two-dot working-tree diff (uncommitted only); any other ref runsgit diff <target>...HEAD, the three-dot form that surfaces what THIS branch contributed vs the merge-base withtarget. Three-dot matches the Inspector GIT panel’s branch-ahead scanner (which composesformat!("{default}...HEAD")via the same helper), so the panel and overlay agree on what’s diffable even after a squash-merge where two-dotgit diff main HEADwould be empty. - scan_
commit - Scan a single commit’s own diff (
<sha>^..<sha>, or against the empty tree for a parentless root commit) into per-file hunks. Never surfaces untracked files - a commit’s diff is closed over its own changes. - scan_
commit_ body - Fetch a commit’s message body - everything after the subject line,
with the trailing newline trimmed. Empty for a subject-only commit.
Kept out of
scan_commitsbecause a multi-line body would break its line-per-commitgit logparse; the stepper fetches it lazily per commit alongside the hunks. - scan_
commit_ body_ within scan_commit_bodywith its command budget spelled; see the module’sscan_within.- scan_
commit_ within scan_commitwith its command budget spelled; see the module’sscan_within.- scan_
commits - List the commits in
<target>..HEAD, oldest first, for the diff overlay’s commit stepper. Empty when the range has no commits (dirty-tree-only review,/diff HEAD, ortargetunresolvable). - scan_
commits_ within scan_commitswith its command budget spelled; see the module’sscan_within.- scan_
within scanwith its command budget spelled: the shell gives each child this reader spawns the 10 sCOMMAND_TIMEOUT, and a test gives them one of its own. The budget is a bound on the machine, not on the read: it is spent starting each child, so a loaded machine can hold a child’s first output past the shell’s 10 s and blank a file’s hunk section.