Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Documentation/line-range-options.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
_<start>_ and _<end>_ (or _<funcname>_) must exist in the starting revision.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Michael Montalbo via GitGitGadget" <gitgitgadget@gmail.com> writes:

> diff --git a/Documentation/line-range-options.adoc b/Documentation/line-range-options.adoc
> index 72f639b5e7..1a25f55bb1 100644
> --- a/Documentation/line-range-options.adoc
> +++ b/Documentation/line-range-options.adoc
> @@ -9,10 +9,14 @@
>  	_<start>_ and _<end>_ (or _<funcname>_) must exist in the starting revision.
>  	You can specify this option more than once. Implies `--patch`.
>  	Patch output can be suppressed using `--no-patch`.
> -	Non-patch diff formats `--raw`, `--name-only`, `--name-status`,
> -	and `--summary` are supported.  Diff stat formats
> -	(`--stat`, `--numstat`, `--shortstat`, `--dirstat`) are not
> -	currently implemented.
> +	The following non-patch diff formats are supported: `--raw`,
> +	`--name-only`, `--name-status`, `--summary`,
> +	`--stat`, `--numstat`, and `--shortstat`.
> +	The stat formats show range-scoped counts: only lines within
> +	the tracked range are counted.  `--dirstat` is not supported

If "range-scoped" is a widely known term (as opposed to a new word
invented only during the introduction of this topic), the above
reads well with a nice rhythm, but otherwise it may be easier to
read, i.e., something like

	The stat formats counts only lines within the tracked range.

without having readers learn yet another new term that is only used
here.

> diff --git a/diff.c b/diff.c
> index 6233a96bf0..026fafeb90 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4289,7 +4289,18 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
>  		xecfg.ctxlen = o->context;
>  		xecfg.interhunkctxlen = o->interhunkcontext;
>  		xecfg.flags = XDL_EMIT_NO_HUNK_HDR;
> -		if (xdi_diff_outf(&mf1, &mf2, NULL,
> +
> +		if (p->line_ranges) {
> +			struct line_range_filter lr_filter;
> +
> +			line_range_filter_init(&lr_filter, p->line_ranges,
> +					       diffstat_consume, diffstat);
> +
> +			if (line_range_filter_diff(&lr_filter, &mf1, &mf2,
> +						   &xpp, &xecfg))
> +				die("unable to generate diffstat for %s",
> +				    one->path);
> +		} else if (xdi_diff_outf(&mf1, &mf2, NULL,
>  				  diffstat_consume, diffstat, &xpp, &xecfg))
>  			die("unable to generate diffstat for %s", one->path);

It is pleasing to see that this can be done with such a surprisingly
small change.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Michael Montalbo wrote on the Git mailing list (how to reply to this email):

On Thu, Jun 18, 2026 at 3:00 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> If "range-scoped" is a widely known term (as opposed to a new word
> invented only during the introduction of this topic), the above
> reads well with a nice rhythm, but otherwise it may be easier to
> read, i.e., something like
>
>         The stat formats counts only lines within the tracked range.
>
> without having readers learn yet another new term that is only used
> here.
>

It was something I invented for the topic, but I agree it is better to
avoid coining a new term, especially since it ends up being spelled
out anyway in the blurb that follows. Will replace the term.

> > diff --git a/diff.c b/diff.c
> > index 6233a96bf0..026fafeb90 100644
> > --- a/diff.c
> > +++ b/diff.c
> > @@ -4289,7 +4289,18 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
> >               xecfg.ctxlen = o->context;
> >               xecfg.interhunkctxlen = o->interhunkcontext;
> >               xecfg.flags = XDL_EMIT_NO_HUNK_HDR;
> > -             if (xdi_diff_outf(&mf1, &mf2, NULL,
> > +
> > +             if (p->line_ranges) {
> > +                     struct line_range_filter lr_filter;
> > +
> > +                     line_range_filter_init(&lr_filter, p->line_ranges,
> > +                                            diffstat_consume, diffstat);
> > +
> > +                     if (line_range_filter_diff(&lr_filter, &mf1, &mf2,
> > +                                                &xpp, &xecfg))
> > +                             die("unable to generate diffstat for %s",
> > +                                 one->path);
> > +             } else if (xdi_diff_outf(&mf1, &mf2, NULL,
> >                                 diffstat_consume, diffstat, &xpp, &xecfg))
> >                       die("unable to generate diffstat for %s", one->path);
>
> It is pleasing to see that this can be done with such a surprisingly
> small change.
>

Agreed! I didn't initially plan it out that way during the first series,
but things fell into place nicely by the end.

You can specify this option more than once. Implies `--patch`.
Patch output can be suppressed using `--no-patch`.
Non-patch diff formats `--raw`, `--name-only`, `--name-status`,
and `--summary` are supported. Diff stat formats
(`--stat`, `--numstat`, `--shortstat`, `--dirstat`) are not
currently implemented.
The following non-patch diff formats are supported: `--raw`,
`--name-only`, `--name-status`, `--summary`, `--check`,
`--stat`, `--numstat`, and `--shortstat`.
The stat formats count only lines within the tracked range.
`--dirstat` is not supported
with `-L`: it summarizes change as each directory's share of
the total churn, not as counts for the tracked lines. Use
`--numstat` for exact per-file counts within the range.
+
Patch formatting options such as `--word-diff`, `--color-moved`,
`--no-prefix`, and whitespace options (`-w`, `-b`) are supported,
as are pickaxe options (`-S`, `-G`) and `--diff-filter`.
as are pickaxe options (`-S`, `-G`) and `--diff-filter`. `-G` is
scoped to the tracked range; `-S` is still evaluated over the whole
file, so an `-S` query may select a commit for a change outside the
range.
+
include::line-range-format.adoc[]
Loading
Loading