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

[PATCH 3/4] in_merge_bases(): use paint_down_to_common()

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 30, 2012, 23:13 UTC
Message-ID
<1346368388-23576-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1346368388-23576-1-git-send-email-gitster@pobox.com>
With paint_down_to_common(), we can tell if "commit" is reachable
from "reference" by simply looking at its object flag, instead of
iterating over the merge bases.
---
 commit.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/commit.c b/commit.c
index 0058fa5..d39a9e9 100644
--- a/commit.c
+++ b/commit.c
@@ -786,20 +786,17 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
  */
 int in_merge_bases(struct commit *commit, struct commit *reference)
 {
-	struct commit_list *bases, *b;
+	struct commit_list *bases;
 	int ret = 0;
 
-	bases = merge_bases_many(commit, 1, &reference);
+	if (parse_commit(commit) || parse_commit(reference))
+		return ret;
+
+	bases = paint_down_to_common(commit, 1, &reference);
+	if (commit->object.flags & PARENT2)
+		ret = 1;
 	clear_commit_marks(commit, all_flags);
 	clear_commit_marks(reference, all_flags);
-
-	for (b = bases; b; b = b->next) {
-		if (!hashcmp(commit->object.sha1, b->item->object.sha1)) {
-			ret = 1;
-			break;
-		}
-	}
-
 	free_commit_list(bases);
 	return ret;
 }
-- 
1.7.12.293.g6aeebca
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 9 in “"merge-base" updates”
  1. 0/4 "merge-base" updatesJunio C Hamano, Aug 30, 2012
  2. 1/4 merge_bases_many(): split out the logic to paint historyJunio C Hamano, Aug 30, 2012
  3. 2/4 merge-base: "--is-ancestor A B"Junio C Hamano, Aug 30, 2012
  4. Martin von ZweigbergkAug 31, 2012
  5. Junio C HamanoAug 31, 2012
  6. Martin von ZweigbergkAug 31, 2012
  7. Junio C HamanoAug 31, 2012
  8. 3/4 in_merge_bases(): use paint_down_to_common()Junio C Hamano, Aug 30, 2012
  9. 4/4 get_merge_bases_many(): walk from many tips in parallelJunio C Hamano, Aug 30, 2012

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.