Skip to main content

Module hunks

Module hunks 

Source
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:

  1. git diff <target> --name-status - file list with M/A/D/R classification.
  2. 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.
  3. git ls-files --others --exclude-standard - untracked files (only when target == "HEAD", capped at MAX_UNTRACKED_FILES entries, each read up to MAX_UNTRACKED_FILE_SIZE bytes).

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§

CommitMeta
One commit in the review stepper’s ordered list. sha is the full hash (used to scope the per-commit diff), short_sha the abbreviated form for display, subject the commit’s first line. body is the message beyond the subject, filled lazily by scan_commit_body when the stepper first lands on the commit (empty until then, and for a subject-only commit).
DiffLine
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.
FileHunks
One file’s worth of hunks, ordered as git diff emitted them.
Hunk
A single @@-delimited hunk inside one file’s diff. lines preserves 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.
ScanOutcome
Outcome of a single scan invocation. files carries whatever was parsed; scanner_ok is false when at least one of the underlying subprocess calls hit Failed or Oversize - 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§

DiffLineKind
Per-line classification inside a hunk.
FileStatus
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 /diff overlay’s untracked surface is suppressed (no U rows render in the rail when the cap is exceeded).

Functions§

scan
Top-level scanner entry. target is a plain ref / SHA / "HEAD" (not a ../... range - the helper diff_ref_spec picks the shape for us). "HEAD" runs a two-dot working-tree diff (uncommitted only); any other ref runs git diff <target>...HEAD, the three-dot form that surfaces what THIS branch contributed vs the merge-base with target. Three-dot matches the Inspector GIT panel’s branch-ahead scanner (which composes format!("{default}...HEAD") via the same helper), so the panel and overlay agree on what’s diffable even after a squash-merge where two-dot git diff main HEAD would 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_commits because a multi-line body would break its line-per-commit git log parse; the stepper fetches it lazily per commit alongside the hunks.
scan_commit_body_within
scan_commit_body with its command budget spelled; see the module’s scan_within.
scan_commit_within
scan_commit with its command budget spelled; see the module’s scan_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, or target unresolvable).
scan_commits_within
scan_commits with its command budget spelled; see the module’s scan_within.
scan_within
scan with its command budget spelled: the shell gives each child this reader spawns the 10 s COMMAND_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.