All of lore.kernel.org
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Tim Jaacks <tim.jaacks@garz-fricke.com>,
	Chris Torek <chris.torek@gmail.com>
Subject: [PATCH 6/6] revision: add parents after child for ^!
Date: Thu, 15 Sep 2022 16:55:12 +0200	[thread overview]
Message-ID: <84018532-169f-dc9b-f894-3d19bb7b4245@web.de> (raw)
In-Reply-To: <ba6eea28-fb3a-b376-2529-351727c02f1a@web.de>

gitrevisions(7) says: "A suffix '^' followed by an exclamation mark is
the same as giving commit '<rev>' and then all its parents prefixed with
'^' to exclude them (and their ancestors)."

handle_revision_arg_1() however adds the negated parents first.  This
leads to unexpected results with git diff and merge commits, as that
command expects the documented order.

Split up the handling of ^! by moving the actual addition of the parents
after the addition of the child.

Reported-by: Tim Jaacks <tim.jaacks@garz-fricke.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 revision.c               | 13 ++++++-------
 t/t4038-diff-combined.sh | 10 ++++++++++
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/revision.c b/revision.c
index 5e756b76aa..8385127f1a 100644
--- a/revision.c
+++ b/revision.c
@@ -2107,6 +2107,7 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl
 	const char *arg = arg_;
 	int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
 	unsigned get_sha1_flags = GET_OID_RECORD_PATH;
+	struct commit *caret_bang_commit = NULL;

 	flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM;

@@ -2135,14 +2136,9 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl
 	}
 	mark = strstr(arg, "^!");
 	if (mark && !mark[2]) {
-		struct commit *commit;
-
 		*mark = 0;
-		commit = get_commit(revs, arg);
-		if (commit)
-			add_parents(revs, commit->parents, arg,
-				    flags ^ (UNINTERESTING | BOTTOM));
-		else
+		caret_bang_commit = get_commit(revs, arg);
+		if (!caret_bang_commit)
 			*mark = '^';
 	}
 	mark = strstr(arg, "^-");
@@ -2179,6 +2175,9 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl
 	add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags);
 	add_pending_object_with_path(revs, object, arg, oc.mode, oc.path);
 	free(oc.path);
+	if (caret_bang_commit)
+		add_parents(revs, caret_bang_commit->parents, arg,
+			    flags ^ (UNINTERESTING | BOTTOM));
 	return 0;
 }

diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
index 9a292bac70..2ce26e585c 100755
--- a/t/t4038-diff-combined.sh
+++ b/t/t4038-diff-combined.sh
@@ -80,11 +80,21 @@ test_expect_success 'check combined output (1)' '
 	verify_helper sidewithone
 '

+test_expect_success 'check combined output (1) with git diff <rev>^!' '
+	git diff sidewithone^! -- >sidewithone &&
+	verify_helper sidewithone
+'
+
 test_expect_success 'check combined output (2)' '
 	git show sidesansone -- >sidesansone &&
 	verify_helper sidesansone
 '

+test_expect_success 'check combined output (2) with git diff <rev>^!' '
+	git diff sidesansone^! -- >sidesansone &&
+	verify_helper sidesansone
+'
+
 test_expect_success 'diagnose truncated file' '
 	>file &&
 	git add file &&
--
2.37.3

  parent reply	other threads:[~2022-09-15 14:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 14:48 [PATCH 0/6] revision: fix order of revs for ^! René Scharfe
2022-09-15 14:51 ` [PATCH 1/6] revision: use strtol_i() for exclude_parent René Scharfe
2022-09-17  0:59   ` Chris Torek
2022-09-15 14:52 ` [PATCH 2/6] revision: factor out get_commit() René Scharfe
2022-09-15 14:52 ` [PATCH 3/6] revision: factor out add_parent() René Scharfe
2022-09-15 14:53 ` [PATCH 4/6] revision: factor out add_parents() René Scharfe
2022-09-15 14:54 ` [PATCH 5/6] revision: rename add_parents_only() to add_nth_parent() René Scharfe
2022-09-15 14:55 ` René Scharfe [this message]
2022-09-15 17:53   ` [PATCH 6/6] revision: add parents after child for ^! Junio C Hamano
2022-09-16  9:02     ` René Scharfe
2022-09-16 15:55       ` Junio C Hamano
2022-09-18  5:36         ` René Scharfe
2022-10-01 10:23 ` [PATCH v3 0/3] diff: support ^! for merges René Scharfe
2022-10-01 10:25   ` [PATCH v3 1/3] revision: use strtol_i() for exclude_parent René Scharfe
2022-10-01 10:26   ` [PATCH v3 2/3] revisions.txt: unspecify order of resolved parts of ^! René Scharfe
2022-10-01 10:28   ` [PATCH v3 3/3] diff: support ^! for merges René Scharfe

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=84018532-169f-dc9b-f894-3d19bb7b4245@web.de \
    --to=l.s.r@web.de \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tim.jaacks@garz-fricke.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.