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

[PATCH 1/7] commit: simplify fastpath of merge-base computation

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 19, 2016, 04:23 UTC
Message-ID
<20161019042345.29766-2-gitster@pobox.com>
In-Reply-To
<20161019042345.29766-1-gitster@pobox.com>

The get_merge_bases_many*() family of functions first call merge_bases_many() to find all possible merge bases between a single commit "one" and a set of other commits "twos[]". Because this typically involves traversing the commit graph, which uses the object flags on the commits involved, the function needs to clear the flags before it returns.

Except for one special case. If "one" is exactly one of the "twos", "one" is the merge base and merge_bases_many() returns a list of merge bases with a single element, "one", on it, without smudging the object flags of the commits at all.

We used to use a loop over "twos[]" array to see if this fast-path would have kicked in in merge_bases_many(), in which case we can return without cleaning the bits at all. We can do the same by inspecting the result in a more direct way, which is conceptually cleaner.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 commit.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/commit.c b/commit.c
index aada266f9a..6266c0380c 100644
--- a/commit.c
+++ b/commit.c
@@ -955,10 +955,17 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
 	int cnt, i;
 
 	result = merge_bases_many(one, n, twos);
-	for (i = 0; i < n; i++) {
-		if (one == twos[i])
-			return result;
-	}
+
+	/*
+	 * The fast-path of 'one' being the merge-base; there is no
+	 * need to clean the object flags in this case.
+	 */
+	if (result && !result->next &&
+	    result->item == one &&
+	    !(one->object.flags & RESULT))
+		return result;
+
+	/* If we didn't get any, or there is only one, we are done */
 	if (!result || !result->next) {
 		if (cleanup) {
 			clear_commit_marks(one, all_flags);
-- 
2.10.1-631-gb2c64dcf30
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 13 in “[RFD] should all merge bases be equal?”
  1. Junio C HamanoOct 17, 2016
  2. 0/7 Rejecting useless merge basesJunio C Hamano, Oct 19, 2016
  3. 1/7 commit: simplify fastpath of merge-base computationJunio C Hamano, Oct 19, 2016
  4. 3/7 merge-base: stop moving commits around in remove_redundant()Junio C Hamano, Oct 19, 2016
  5. 2/7 sha1_name: remove ONELINE_SEEN bitJunio C Hamano, Oct 19, 2016
  6. 4/7 merge-base: expose get_merge_bases_many_0() a bit moreJunio C Hamano, Oct 19, 2016
  7. 5/7 merge-base: mark bases that are on first-parent chainJunio C Hamano, Oct 19, 2016
  8. Junio C HamanoOct 19, 2016
  9. 6/7 merge-base: limit the output to bases that are on first-parent chainJunio C Hamano, Oct 19, 2016
  10. 7/7 merge: allow to use only the fp-only merge basesJunio C Hamano, Oct 19, 2016
  11. Junio C HamanoOct 19, 2016
  12. Michael HaggertyFeb 9, 2017
  13. Junio C HamanoFeb 9, 2017

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.