Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Michael Hore <Michael.Hore@asic.gov.au>
Cc: Jerry Zhang <jerry@skydio.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Bug report - git rev-list --exclude-first-parent-only [SEC=UNOFFICIAL]
Date: Fri, 03 Jul 2026 13:28:50 -0700	[thread overview]
Message-ID: <xmqqbjcnizr1.fsf@gitster.g> (raw)
In-Reply-To: <ME2PR01MB5490E3CE825C83474D1573CED1F52@ME2PR01MB5490.ausprd01.prod.outlook.com> (Michael Hore's message of "Thu, 2 Jul 2026 03:59:04 +0000")

Michael Hore <Michael.Hore@asic.gov.au> writes:

> I believe I have found a bug -
>
> My repo has a commit structure like
>
> R2
> |\
> | F
> |/
> R1
>
> i.e.
>  - there is a merge commit R2 with parents R1 and F
>  - the parent of F is R1

IOW, R2 is a useless merge that could have been a simple
fast-forward directly to F.

> I ran "git rev-list --exclude-first-parent-only F ^R2"
>
> it gave the expected result: "F"
>
> I ran "git rev-list --exclude-first-parent-only F R1 ^R2"
>
> I expected the same result, but I got an unexpected result - nothing at all

This seems to have come from 9d505b7b49 (git-rev-list: add
--exclude-first-parent-only flag, 2022-01-11).  I do not know if the
original author is still around, but it would have been nicer to ask
for input from them (cc'ed).

A fix could be something along this line, but I've never used this
feature even once (I instead use Michael Haggerty's exellent "git
when-merged" thing), so I may very well be breaking _other_ use
cases this feature was originally intended for without knowing.

The patched part is inside a huge "while (parent)" loop.  The idea
is to break out before the loop goes on to smudge later parents when
we are in the "smudge only first parent as uninteresting, without
contaminating the history leading to other parents" mode.

 revision.c                   | 10 ++++++++--
 t/t6012-rev-list-simplify.sh | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git c/revision.c w/revision.c
index e91d7e1f11..1f50d42a7a 100644
--- c/revision.c
+++ w/revision.c
@@ -1151,12 +1151,18 @@ static int process_parents(struct rev_info *revs, struct commit *commit,
 			if (p)
 				p->object.flags |= UNINTERESTING |
 						   CHILD_VISITED;
-			if (repo_parse_commit_gently(revs->repo, p, 1) < 0)
+			if (repo_parse_commit_gently(revs->repo, p, 1) < 0) {
+				if (revs->exclude_first_parent_only)
+					break;
 				continue;
+			}
 			if (p->parents)
 				mark_parents_uninteresting(revs, p);
-			if (p->object.flags & SEEN)
+			if (p->object.flags & SEEN) {
+				if (revs->exclude_first_parent_only)
+					break;
 				continue;
+			}
 			p->object.flags |= (SEEN | NOT_USER_GIVEN);
 			if (queue)
 				prio_queue_put(queue, p);
diff --git c/t/t6012-rev-list-simplify.sh w/t/t6012-rev-list-simplify.sh
index 4cecb6224c..2284bbba12 100755
--- c/t/t6012-rev-list-simplify.sh
+++ w/t/t6012-rev-list-simplify.sh
@@ -285,4 +285,22 @@ test_expect_success 'log --graph --simplify-merges --show-pulls' '
 	test_cmp expect actual
 '
 
+test_expect_success 'exclude-first-parent-only with parent already seen' '
+	git checkout --orphan test-seen &&
+	git rm -rf . &&
+	test_commit r1 &&
+	git checkout -b branch-f &&
+	test_commit f &&
+	git checkout test-seen &&
+	git merge --no-ff --no-edit -m r2 branch-f &&
+	git tag r2 &&
+
+	git rev-list --exclude-first-parent-only f ^r2 >actual &&
+	git rev-parse f >expect &&
+	test_cmp expect actual &&
+
+	git rev-list --exclude-first-parent-only f r1 ^r2 >actual2 &&
+	test_cmp expect actual2
+'
+
 test_done


      reply	other threads:[~2026-07-03 20:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  3:59 Bug report - git rev-list --exclude-first-parent-only [SEC=UNOFFICIAL] Michael Hore
2026-07-03 20:28 ` Junio C Hamano [this message]

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=xmqqbjcnizr1.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Michael.Hore@asic.gov.au \
    --cc=git@vger.kernel.org \
    --cc=jerry@skydio.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