From: Junio C Hamano <gitster@pobox.com>
To: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH] range-diff: add --matched-only to skip one-sided commits
Date: Fri, 11 Sep 2026 10:19:27 -0700 [thread overview]
Message-ID: <xmqqik4bbt9c.fsf@gitster.g> (raw)
In-Reply-To: <pull.2401.git.git.1789144877632.gitgitgadget@gmail.com> (Harald Nordgren via GitGitGadget's message of "Fri, 11 Sep 2026 16:41:17 +0000")
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> diff --git a/Documentation/git-range-diff.adoc b/Documentation/git-range-diff.adoc
> index 5cc5e2ed56..58e59e8e3b 100644
> --- a/Documentation/git-range-diff.adoc
> +++ b/Documentation/git-range-diff.adoc
> @@ -10,7 +10,8 @@ SYNOPSIS
> [synopsis]
> git range-diff [--color=[<when>]] [--no-color] [<diff-options>]
> [--no-dual-color] [--creation-factor=<factor>]
> - [--left-only | --right-only] [--diff-merges=<format>]
> + [--left-only | --right-only | --matched-only]
> + [--diff-merges=<format>]
> [--remerge-diff] [--no-notes | --notes[=<ref>]]
> ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
> [[--] <path>...]
> @@ -82,6 +83,13 @@ to revert to color all lines according to the outer diff markers
> Suppress commits that are missing from the second specified range
> (or the "right range" when using the `<rev1>...<rev2>` form).
>
> +`--matched-only`::
> + Only emit commits that have a corresponding commit in the other
> + range, suppressing any commit that exists on only one side. This is
> + the same as using `--left-only` and `--right-only` together. Useful
> + to skip added or removed commits when reviewing how the commits
> + that survived a rebase changed.
While conceptually it is the same as giving "--hide-right-only"
(which would have hidden the right-only entry) and
"--hide-left-only" at the same time, because the existing two
options are not defined in terms of "hiding" entries that have only
one side (which would have logically allowed combining) but instead
showing "only" one side (which makes it impossible to give them
together, and indeed that is the first thing
range-diff.c:show_range_diff() checks and yields an error), this
description is not accurate.
I wonder if the implementation actually can be more like
- give "--hide-left-only" and "--hide-right-only" as synonyms to
"--right-only" and "--left-only", and deprecate the original;
- allow them to be given together, which will give the new
behaviour you are introducing, i.e., skip steps without both
sides from the output;
- give a short-hand synonym, "--matched-only", to truly behave the
same as giving "--hide-{left,right}-only" together.
which would allow the above explanation to be more accurate? I
dunno.
> + if (range_diff_opts->left_only + range_diff_opts->right_only +
> + range_diff_opts->matched_only > 1)
> + res = error(_("options '%s', '%s', or '%s' cannot be used together"),
> + "--left-only", "--right-only", "--matched-only");
Don't we have die_for_incompatible_opt3() to do this?
The basic idea sounds good. The unmatched entries do serve as a
strong hint that a greater --creation-factor may help. For example,
> + git range-diff -s --abbrev=7 combined-old...combined-new >actual &&
> + cat >expect <<-EOF &&
> + 1: $old_only_oid < -: ------- c-old-only
> + -: ------- > 1: $new_only_oid c-new-only
> + 2: $common_old_oid = 2: $common_new_oid c-common
> + EOF
> + test_cmp expect actual &&
the above clearly shows that the command might compare c-old-only
and c-new-only with a better creation factor settings.
But because the entries are numbered, gaps in the numbers, like this
output
> + git range-diff -s --abbrev=7 --matched-only combined-old...combined-new \
> + >actual &&
> + echo "2: $common_old_oid = 2: $common_new_oid c-common" >expect &&
> + test_cmp expect actual
may be sufficient (we can tell that 1 was omitted), except that
somehow we at least need to be aware that there were only 2 commits
on both sides (it may be hiding commits 3 thru 99 as unmatching
pairs and we lose that hint from the new output), which is not a
huge downside.
Thanks.
next prev parent reply other threads:[~2026-09-11 17:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 16:41 [PATCH] range-diff: add --matched-only to skip one-sided commits Harald Nordgren via GitGitGadget
2026-09-11 17:19 ` Junio C Hamano [this message]
2026-09-11 18:48 ` Harald Nordgren
2026-09-11 18:52 ` Junio C Hamano
2026-09-11 19:01 ` Harald Nordgren
2026-09-11 19:05 ` Junio C Hamano
2026-09-11 20:55 ` [PATCH v2] " Harald Nordgren via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqik4bbt9c.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=haraldnordgren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox