[PATCH 0/7] line-log: range-scope stat, check, and -G under -L
- From
Michael Montalbo via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Jun 18, 2026, 18:16 UTC
- Message-ID
- <pull.2152.git.1781806593.gitgitgadget@gmail.com>
This series extends git log -L so that more of its diff output and commit selection honor the tracked line ranges: the diff stat formats and --check are supported with range-scoped results, and the -G pickaxe is scoped to the tracked range.
It builds on top of the mm/line-log-cleanup topic [1], which integrated -L with the standard log output pipeline and taught it the non-patch formats --raw, --name-only, --name-status, and --summary.
With these patches the following also honor the tracked range:
* --stat, --numstat, --shortstat: counts cover only the lines inside the tracked range, not the whole file.
* --check: whitespace errors are reported only for added lines inside the tracked range, with the correct file line numbers.
* -G: a commit is selected only when the pattern appears on an added/removed line inside the tracked range, rather than anywhere in the file.
The --dirstat format is deliberately rejected. Its default mode reports each directory's share of the total churn as a percentage, computed from whole-file byte damage (via diffcore_count_changes(), outside the line-based pipeline that -L scopes), so bare --dirstat cannot honor the tracked range. The --dirstat=lines mode could: it aggregates the same per-file line counts as --numstat, which -L already scopes. But supporting only that sub-mode while bare --dirstat still errors is a confusing split, so the whole format is left to a follow-up; --numstat already gives the exact range-scoped per-file counts.
-S is left matching the whole file. Unlike -G, it counts needle occurrences per blob rather than grepping the diff, so scoping it to a range needs a different approach; that is left to a follow-up. Patch 7, which scopes -G, also updates the -L documentation to note the -S/-G distinction, so the whole-file behavior of -S is not mistaken for the range-scoped behavior around it.
Patches 1-3 are independent of the new formats: they fix two bugs in the existing -L patch output (a leaked deletion and an off-by-one hunk header), bring its hunk headers in line with git diff's format, and clarify the line-range filter mm/line-log-cleanup added, whose names obscured its model (cryptic lno_ cursors conflating the pre/post-image and 0/1-based axes, a flat hunk-state struct, and a one-letter state pointer (s)). The two bugs may be a hint that the model could use clarification, so patch 1 renames and groups the filter state and patch 2 documents the model, before the fixes that read against it. Patches 4-7 then build the new formats on top:
* Patch 1: rename and group the filter for clarity. Spell the cryptic names out to the file's own forms: the line-number cursors to lno_in_preimage/lno_in_postimage (as in struct emit_callback) and the range index to idx_in_postimage, while the hunk geometry stays old/new (the xdiff_emit_hunk_fn convention) and moves into a sub-struct. Name the filter pointer (filter) and rename the struct to line_range_filter and the flush helper to flush_range_hunk. No behavior change.
* Patch 2: simplify the filter by classifying removals as they arrive, dropping the pending_rm buffer and a latent flush_range_hunk() bug that leaked deletions just past the range. Make the buffered lines the hunk's single source of truth: flush_range_hunk() derives the counts from them rather than tracking them per line, dropping three more fields. Document the model with a block comment and worked example, and add begin_range_hunk() as the counterpart to flush_range_hunk(). (This simplification was submitted by itself previously [2] but did not advance, so it is re-included here.)
* Patch 3: stop hand-rolling the synthetic hunk header and emit it through xdiff's own formatter via a new xdiff_emit_hunk_header() helper. The hand-rolled code put a count-0 side's begin one too high (the convention is the line before the change); routing through xdl_emit_hunk_hdr() fixes that by construction and, as a side effect, makes -L headers match git diff exactly, including its omission of a count of 1. Regenerate the two affected fixtures.
* Patch 4: extract a line_range_filter_diff() helper that folds the filter's two preconditions into one place: inflate ctxlen to the largest range span so every change within a range lands in a single xdiff hunk, and clear XDL_EMIT_NO_HUNK_HDR so the hunk headers the filter reads are always emitted (its position tracking relies on both). It then runs an initialized filter through xdiff, flushes the final range hunk, and releases it; use it in builtin_diff(). The stat, check, and -G patches that reuse it inherit both.
* Patch 5: reuse the filter in builtin_diffstat() for the stat formats, extend the -L output-format allowlist, and reject --dirstat.
* Patch 6: reuse the filter in builtin_checkdiff() and extend the allowlist for --check. The separate blank-at-eof pass scans the whole file, so scope its report to the tracked ranges too.
* Patch 7: scope -G to the tracked range. Expose the filter as diff_emit_line_ranges() and grep only the tracked range's lines, threading the filepair's line_ranges through the pickaxe callback. -S is left whole-file, and the -L documentation is updated to note that -G is range-scoped while -S still matches the whole file.
[1] https://lore.kernel.org/git/pull.2094.v3.git.1780001267.gitgitgadget@gmail.com/ [2] https://lore.kernel.org/git/pull.2099.git.1777230630020.gitgitgadget@gmail.com/
Michael Montalbo (7):
diff: rename and group the line-range filter for clarity
diff: simplify the line-range filter by classifying removals
immediately
diff: emit -L hunk headers via xdiff's formatter
diff: extract a line-range diff helper for reuse
line-log: support diff stat formats with -L
diff: support --check with -L line ranges
diffcore-pickaxe: scope -G to the -L tracked rangeDocumentation/line-range-options.adoc | 17 +- diff.c | 491 ++++++++++++++--------- diffcore-pickaxe.c | 37 +- revision.c | 6 +- t/t4211-line-log.sh | 439 +++++++++++++++++++- t/t4211/sha1/expect.no-assertion-error | 2 +- t/t4211/sha1/expect.vanishes-early | 6 +- t/t4211/sha256/expect.no-assertion-error | 2 +- t/t4211/sha256/expect.vanishes-early | 6 +- xdiff-interface.c | 19 + xdiff-interface.h | 28 ++ 11 files changed, 826 insertions(+), 227 deletions(-)
base-commit: ea97ad8d017de0c9037451a78008a0fd60abea0c Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2152%2Fmmontalbo%2Fmm%2Fline-log-stat-formats-followup-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2152/mmontalbo/mm/line-log-stat-formats-followup-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/2152
-- gitgitgadget