git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Thomas Rast <trast@student.ethz.ch>, Jeff King <peff@peff.net>
Subject: [PATCH 5/5] (BROKEN) get_merge_bases_many(): walk from many tips in parallel
Date: Mon, 27 Aug 2012 16:12:03 -0700	[thread overview]
Message-ID: <1346109123-12357-6-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1346109123-12357-1-git-send-email-gitster@pobox.com>

After merge_bases_many() paints the graph in two colors to find
common ancestors, get_merge_bases_many() reduces the result by
excluding commits that can be reached from other commits in the
result.  We used to do N * (N-1) traversals for this, but we can
check if one commit is reachable from any of the other (N-1) commits
by a single traversal, and repeat it N times to find the answer.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 commit.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/commit.c b/commit.c
index f5211bd..ccf2c5a 100644
--- a/commit.c
+++ b/commit.c
@@ -715,7 +715,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
 					 int cleanup)
 {
 	struct commit_list *list;
-	struct commit **rslt;
+	struct commit **rslt, **others;
 	struct commit_list *result;
 	int cnt, i, j;
 
@@ -744,33 +744,37 @@ struct commit_list *get_merge_bases_many(struct commit *one,
 	for (list = result, i = 0; list; list = list->next)
 		rslt[i++] = list->item;
 	free_commit_list(result);
+	result = NULL;
 
 	clear_commit_marks(one, all_flags);
 	for (i = 0; i < n; i++)
 		clear_commit_marks(twos[i], all_flags);
-	for (i = 0; i < cnt - 1; i++) {
-		for (j = i+1; j < cnt; j++) {
-			if (!rslt[i] || !rslt[j])
-				continue;
-			result = merge_bases_many(rslt[i], 1, &rslt[j]);
-			clear_commit_marks(rslt[i], all_flags);
-			clear_commit_marks(rslt[j], all_flags);
-			for (list = result; list; list = list->next) {
-				if (rslt[i] == list->item)
-					rslt[i] = NULL;
-				if (rslt[j] == list->item)
-					rslt[j] = NULL;
-			}
-		}
-	}
 
-	/* Surviving ones in rslt[] are the independent results */
-	result = NULL;
+	others = xcalloc(cnt - 1, sizeof(*others));
 	for (i = 0; i < cnt; i++) {
-		if (rslt[i])
+		/*
+		 * Is rslt[i] an ancestor of any of the others?
+		 * then it is not interesting to us.
+		 */
+		for (j = 0; j < i; j++)
+			others[j] = rslt[j];
+		for (j = 1 + 1; j < cnt; j++)
+			others[j - 1] = rslt[j];
+		list = merge_bases_many(rslt[i], cnt - 1, others);
+		clear_commit_marks(rslt[i], all_flags);
+		for (j = 0; j < cnt - 1; j++)
+			clear_commit_marks(others[j], all_flags);
+		while (list) {
+			if (rslt[i] == list->item)
+				break;
+			list = list->next;
+		}
+		if (!list)
 			commit_list_insert_by_date(rslt[i], &result);
+		free_commit_list(list);
 	}
 	free(rslt);
+	free(others);
 	return result;
 }
 
-- 
1.7.12.116.g31e0100

  parent reply	other threads:[~2012-08-27 23:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-27 23:11 [PATCH 0/5] optimize fast-forward checks Junio C Hamano
2012-08-27 23:11 ` [PATCH 1/5] in_merge_bases(): support only one "other" commit Junio C Hamano
2012-08-27 23:12 ` [PATCH 2/5] receive-pack: use in_merge_bases() for fast-forward check Junio C Hamano
2012-08-27 23:12 ` [PATCH 3/5] http-push: " Junio C Hamano
2012-08-27 23:12 ` [PATCH 4/5] in_merge_bases(): omit unnecessary redundant common ancestor reduction Junio C Hamano
2012-08-27 23:12 ` Junio C Hamano [this message]
2012-08-28  1:25   ` [PATCH 5/5] (BROKEN) get_merge_bases_many(): walk from many tips in parallel Junio C Hamano
2012-08-28 21:35     ` Junio C Hamano
2012-08-28 23:39       ` Junio C Hamano
2012-08-29 11:08         ` Jeff King
2012-08-29 11:10           ` [PATCH 1/2] basic priority queue implementation Jeff King
2012-08-29 11:11           ` [PATCH 2/2] commit: use a priority queue in merge base functions Jeff King
2012-08-29 16:36             ` Junio C Hamano
2012-08-29 20:53               ` Jeff King
2012-08-29 20:55                 ` Jeff King
2012-08-29 21:00                   ` Jeff King
2012-08-29 21:05                     ` Jeff King
2012-08-30 12:54                       ` Jeff King
2012-08-30 13:03                         ` Jeff King
2012-08-30 13:24                           ` Jeff King
2012-08-30 16:33                           ` Junio C Hamano
2012-08-30 21:48                             ` Jeff King
2012-08-30 22:16                               ` Junio C Hamano
2012-08-30 16:23                         ` Junio C Hamano
2012-08-30 21:31                           ` Jeff King
2012-08-30 21:59                             ` Junio C Hamano
2012-08-29 21:18                     ` Junio C Hamano

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=1346109123-12357-6-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=trast@student.ethz.ch \
    /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;
as well as URLs for NNTP newsgroup(s).