git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 10/9] revision.c: treat A...B merge bases as if manually specified

From
Kevin Bracey <kevin@bracey.fi>
Date
May 6, 2013, 16:51 UTC
Message-ID
<1367859096-25909-1-git-send-email-kevin@bracey.fi>
In-Reply-To
<1367767977-14513-1-git-send-email-kevin@bracey.fi>

The documentation assures users that "A...B" is defined as 'r1 r2 --not $(git merge-base --all r1 r2)'. This isn't in fact quite true, because the calculated merge bases are not sent to add_rev_cmdline().

Previously, the effect was pretty minor - all that I can think of is that "git rev-list --ancestry-path A B ^AB_base" works, but "git rev-list --ancestry-path A...B" fails with a "no bottom commits" error.

But now that all history walking cares about bottom commits, this failure to note the merge bases as bottoms can lead to worse results for "A...B" compared to "A B ^AB_base".

So ensure that the calculated merge bases are sent to add_rev_cmdline(), flagged as 'REV_CMD_MERGE_BASE'.

Signed-off-by: Kevin Bracey <kevin@bracey.fi>
---
 revision.c                   | 9 +++++++--
 revision.h                   | 2 ++
 t/t6111-rev-list-treesame.sh | 4 ++++
 3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 99a3432..aad16a6 100644
--- a/revision.c
+++ b/revision.c
@@ -1305,12 +1305,16 @@ void init_revisions(struct rev_info *revs, const char *prefix)
 
 static void add_pending_commit_list(struct rev_info *revs,
                                     struct commit_list *commit_list,
+                                    int whence,
                                     unsigned int flags)
 {
 	while (commit_list) {
 		struct object *object = &commit_list->item->object;
+		const char *sha1 = sha1_to_hex(object->sha1);
 		object->flags |= flags;
-		add_pending_object(revs, object, sha1_to_hex(object->sha1));
+		if (whence != REV_CMD_NONE)
+			add_rev_cmdline(revs, object, sha1, whence, flags);
+		add_pending_object(revs, object, sha1);
 		commit_list = commit_list->next;
 	}
 }
@@ -1332,7 +1336,7 @@ static void prepare_show_merge(struct rev_info *revs)
 	add_pending_object(revs, &head->object, "HEAD");
 	add_pending_object(revs, &other->object, "MERGE_HEAD");
 	bases = get_merge_bases(head, other, 1);
-	add_pending_commit_list(revs, bases, UNINTERESTING);
+	add_pending_commit_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING);
 	free_commit_list(bases);
 	head->object.flags |= SYMMETRIC_LEFT;
 
@@ -1420,6 +1424,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 			if (symmetric) {
 				exclude = get_merge_bases(a, b, 1);
 				add_pending_commit_list(revs, exclude,
+							REV_CMD_MERGE_BASE,
 							flags_exclude);
 				free_commit_list(exclude);
 				a_flags = flags | SYMMETRIC_LEFT;
diff --git a/revision.h b/revision.h
index 765630a..b2ac5a3 100644
--- a/revision.h
+++ b/revision.h
@@ -32,10 +32,12 @@ struct rev_cmdline_info {
 		struct object *item;
 		const char *name;
 		enum {
+			REV_CMD_NONE,
 			REV_CMD_REF,
 			REV_CMD_PARENTS_ONLY,
 			REV_CMD_LEFT,
 			REV_CMD_RIGHT,
+			REV_CMD_MERGE_BASE,
 			REV_CMD_REV
 		} whence;
 		unsigned flags;
diff --git a/t/t6111-rev-list-treesame.sh b/t/t6111-rev-list-treesame.sh
index 689d357..ded0b1a 100755
--- a/t/t6111-rev-list-treesame.sh
+++ b/t/t6111-rev-list-treesame.sh
@@ -161,6 +161,10 @@ check_result 'F' B..F --ancestry-path --simplify-merges -- file
 check_result 'F D' B..F --first-parent
 check_result 'F' B..F --first-parent -- file
 
+# E...F should be equivalent to E F ^B, and be able to drop D as above.
+check_result 'F' E F ^B -- file
+check_result 'F' E...F -- file
+
 # Any sort of full history of C..F should show D, as it's the connection to C,
 # and it differs from it.
 check_result 'F D B' C..F
-- 
1.8.3.rc0.28.g4b02ef5
Previous: Kevin BraceyNext: Junio C Hamano
Message 18 of 20 in “History traversal refinements”
  1. 0/9 History traversal refinementsKevin Bracey, May 5, 2013
  2. 1/9 decorate.c: compact table when growingKevin Bracey, May 5, 2013
  3. 2/9 t6019: test file dropped in -s ours mergeKevin Bracey, May 5, 2013
  4. 3/9 t6111: new TREESAME test setKevin Bracey, May 5, 2013
  5. Junio C HamanoMay 6, 2013
  6. Junio C HamanoMay 6, 2013
  7. Kevin BraceyMay 7, 2013
  8. Junio C HamanoMay 7, 2013
  9. 4/9 rev-list-options.txt: correct TREESAME for PKevin Bracey, May 5, 2013
  10. 5/9 revision.c: Make --full-history consider more mergesKevin Bracey, May 5, 2013
  11. Junio C HamanoMay 6, 2013
  12. Kevin BraceyMay 7, 2013
  13. Junio C HamanoMay 7, 2013
  14. 6/9 t6012: update test for tweaked full-history traversalKevin Bracey, May 5, 2013
  15. 7/9 simplify-merges: never remove all TREESAME parentsKevin Bracey, May 5, 2013
  16. 8/9 simplify-merges: drop merge from irrelevant side branchKevin Bracey, May 5, 2013
  17. 9/9 revision.c: discount side branches when computing TREESAMEKevin Bracey, May 5, 2013
  18. 10/9 revision.c: treat A...B merge bases as if manually specifiedKevin Bracey, May 6, 2013
  19. Junio C HamanoMay 6, 2013
  20. Kevin BraceyMay 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.