Skip to content

line-log: scope stat, check, and -G to -L line ranges - #2152

Open
mmontalbo wants to merge 7 commits into
gitgitgadget:masterfrom
mmontalbo:mm/line-log-stat-formats-followup
Open

line-log: scope stat, check, and -G to -L line ranges#2152
mmontalbo wants to merge 7 commits into
gitgitgadget:masterfrom
mmontalbo:mm/line-log-stat-formats-followup

Conversation

@mmontalbo

@mmontalbo mmontalbo commented Jun 15, 2026

Copy link
Copy Markdown

Teach -L to work with the --stat family of options and --check. Also,
teach -G to search within the line ranges specified by -L. This series
continues the previous work[1][2] extending -L to work with more diff
options, and, for example, enables:

Reviewing the history of a single function with the --stat family,
counted over just that function's lines rather than the whole file:

$ git log --oneline -L:strbuf_grow:strbuf.c --stat
c13d0f7bd4 strbuf: use st_add3() in strbuf_grow()
 strbuf.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
...
b449f4cfc9 Rework strbuf API and semantics.
 strbuf.c | 6 ++++++
 1 file changed, 6 insertions(+)

Finding where a pattern changed inside one function with -G, ignoring
matches elsewhere in the file:

$ git log --oneline -L:run_builtin:git.c -G RUN_SETUP
e5b17bda8b git: ensure correct git directory setup with -h
27bd38d4e5 git.c: treat RUN_SETUP_GENTLY and RUN_SETUP as mutually exclusive
...
47d0b4ff57 Clean up internal command handling

The first 3 commits are preparatory cleanup for the main feature
changes and could potentially be separated. The last 4 commits
implement the new features.

Patches:

  1. Rename line_range_callback to line_range_filter to more accurately
    reflect its role as a general filter for other diff features. Also,
    replace verbose comments with descriptive field and variable names.
  2. Simplify line-range filtering logic, which fixes a bug as a result.
  3. Make -L diff hunk header format consistent with default mode's
    header format for all cases by exposing xdiff's header generating
    function.
  4. Enable support for --stat family of options.
  5. Enable support for --check.
  6. Teach -G to search within -L line ranges.

Changes since v2:

  • Rewrite all prose in series from scratch to remove significant
    verbosity and extraneous detail that makes the series hard to reason
    about. Replace block comments with descriptive field and variable
    names.
  • Pare down and simplify some test implementations.
  • No other logical behavior changes.

[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/

Cc: "D. Ben Knoble" ben.knoble@gmail.com

@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch 8 times, most recently from 7977925 to 2ea00b6 Compare June 16, 2026 21:41
@mmontalbo mmontalbo changed the title line-log: support stat and check diff formats with -L line-log: range-scope stat, check, and -G under -L Jun 16, 2026
@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch 17 times, most recently from 2bc09ca to f69ccfb Compare June 18, 2026 16:29
@mmontalbo

Copy link
Copy Markdown
Author

/preview

@gitgitgadget

gitgitgadget Bot commented Jun 18, 2026

Copy link
Copy Markdown

Preview email sent as pull.2152.git.1781800932.gitgitgadget@gmail.com

@mmontalbo

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Jun 18, 2026

Copy link
Copy Markdown

Submitted as pull.2152.git.1781806593.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2152/mmontalbo/mm/line-log-stat-formats-followup-v1

To fetch this version to local tag pr-2152/mmontalbo/mm/line-log-stat-formats-followup-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2152/mmontalbo/mm/line-log-stat-formats-followup-v1

@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch from df83e62 to 43bc512 Compare July 26, 2026 17:48
@gitgitgadget

gitgitgadget Bot commented Jul 27, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
cf. <xmqq8q8bpl03.fsf@gitster.g>
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Jul 29, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 3, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 5, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 8, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 11, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 13, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 15, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 17, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 18, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 21, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 24, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 26, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 29, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 29, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@gitgitgadget

gitgitgadget Bot commented Aug 31, 2026

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch mm/line-log-limited-ops on the Git mailing list:

The 'git log -L<range>:<path>' command has been taught to limit
various 'diff' operations, such as '--stat', '--check', and '-G', to
the specified range and path.

Needs review.
source: <pull.2152.v2.git.1782581342.gitgitgadget@gmail.com>

@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch from 43bc512 to ee53c92 Compare September 2, 2026 21:07
@gitgitgadget

gitgitgadget Bot commented Sep 2, 2026

Copy link
Copy Markdown

There is an issue in commit 72a86b9:
diff: support --check with -L line ranges

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch from ee53c92 to 4db558b Compare September 2, 2026 21:41
diff's line-range filtering logic uses the line_range_callback
struct to represent filtering state. However, this name does not
clearly reflect the role it plays. This is especially relevant as
we extend diff's line-range filtering to work with more options,
including --stat and -G.

In the same way, line_range_callback's fields are terse and do not
clearly name their role, while at the same time, the comment explaining
line_range_callback is overly verbose and out of place compared
to its surroundings.

Rename line_range_callback to line_range_filter, and replace the verbose
comment with a concise one, instead preferring descriptive field and
variable names that are self-explanatory over comments.

No logical behavior change. Some fields are grouped under a new struct
in the newly renamed line_range_filter. Everything else is just a
rename.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch from 4db558b to 102a294 Compare September 2, 2026 22:02
Currently, the diff line-range filter stores preimage removal lines in a
buffer until a postimage line arrives whose line number can confirm if
the preimage line is part of a relevant line range or not. However,
storing preimage lines in a separate buffer is unnecessary. Worse than
this, the logic has a bug causing a preimage line that is not part of
the line range target to be included when it immediately follows a
postimage line that is part of the target range.

Preimage lines will always precede their postimage counterpart both in
content line number and emission order from xdiff's line callback
function. That means preimage lines can just be stored in the same
buffer as postimage lines and flushed as appropriate depending on
whether or not the postimage lines lie within the target line range.

Remove logic related to storing preimage lines in a separate "removal"
buffer and prepending them to the accumulating_hunk's line buffer.
Instead, store those lines in the accumulating_hunk's line_buffer
immediately and flush everything as appropriate based on postimage
line numbers that arrive. This resolves the aforementioned bug by
construction.

Also, simplify line_range_filter's state management by calculating the
old and new line counts that should be emitted in the diff hunk header
when flushing rather than storing counters in line_range_filter.

Add a test to t/t4211-line-log.sh that verifies the aforementioned
preimage line emission bug is fixed.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Currently, diff's line-range filter implements its own method for
emitting diff hunk headers. This mostly matches what xdiff itself
outputs, but there is a discrepancy when it comes to postimage or
preimage sides with 0 line changes. For a side that has no lines
(count 0) the begin is the line before the change, and it omits
a line count of 1 from the header.

Rather than fixing this case in line-range's implementation, expose
the function xdiff uses for emitting its headers and use it instead to
keep the emitted header format consistent both with and without -L.

Update test scenarios and fixtures to reflect the now consistent header
format.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Extract logic for initializing the line-range filter and running a diff
for a specific line range. This logic is needed for any diff that
targets a line range independent of the current patch display path.

This extracted logic is used in the subsequent commits that enable
additional line range targeted diff modes.

No logical behavior change.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch from 102a294 to 994bac9 Compare September 2, 2026 22:54
Reuse the line_range_filter in builtin_diffstat() so -L supports
the stat formats and add tests verifying the new behavior.

Ungate the newly enabled options and drop "yet" from the generic
-L rejection message ("does not yet support the requested diff
format"). Some rejected formats do not fit -L at all, so "yet"
wrongly implies they are all just awaiting support.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Reuse the line_range_filter in builtin_checkdiff() so -L supports
the --check option.

Document and ungate the newly enabled option, add tests verifying
the new behavior.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Teach -G to only search the line ranges specified by -L.
Teaching -S is left as future work, so it still matches the entire
file even if -L is specified.

Update documentation and add tests accordingly.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
@mmontalbo
mmontalbo force-pushed the mm/line-log-stat-formats-followup branch from 994bac9 to 5f606e6 Compare September 2, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant