From: Junio C Hamano <gitster@pobox.com>
To: Miklos Vajna <vmiklos@frugalware.org>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] Introduce get_merge_bases_many()
Date: Sat, 21 Jun 2008 02:45:50 -0700 [thread overview]
Message-ID: <7vlk0zazox.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 1214007784-4801-1-git-send-email-vmiklos@frugalware.org
This introduces a new function get_merge_bases_many() which is a natural
extension of two commit merge base computation. It is given one commit
(one) and a set of other commits (twos), and computes the merge base of
one and a merge across other commits.
This is mostly useful to figure out the common ancestor when iterating
over heads during an octopus merge. When making an octopus between
commits A, B, C and D, we first merge tree of A and B, and then try to
merge C with it. If we were making pairwise merge, we would be recording
the tree resulting from the merge between A and B as a commit, say M, and
then the next round we will be computing the merge base between M and C.
o---C...*
/ .
o---B...M
/ .
o---o---A
But during an octopus merge, we actually do not create a commit M. In
order to figure out that the common ancestor to use for this merge,
instead of computing the merge base between C and M, we can call
merge_bases_many() with one set to C and twos containing A and B.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
commit.c | 56 ++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/commit.c b/commit.c
index e2d8624..4ee234d 100644
--- a/commit.c
+++ b/commit.c
@@ -525,26 +525,34 @@ static struct commit *interesting(struct commit_list *list)
return NULL;
}
-static struct commit_list *merge_bases(struct commit *one, struct commit *two)
+static struct commit_list *merge_bases_many(struct commit *one, int n, struct commit **twos)
{
struct commit_list *list = NULL;
struct commit_list *result = NULL;
+ int i;
- if (one == two)
- /* We do not mark this even with RESULT so we do not
- * have to clean it up.
- */
- return commit_list_insert(one, &result);
+ for (i = 0; i < n; i++) {
+ if (one == twos[i])
+ /*
+ * We do not mark this even with RESULT so we do not
+ * have to clean it up.
+ */
+ return commit_list_insert(one, &result);
+ }
if (parse_commit(one))
return NULL;
- if (parse_commit(two))
- return NULL;
+ for (i = 0; i < n; i++) {
+ if (parse_commit(twos[i]))
+ return NULL;
+ }
one->object.flags |= PARENT1;
- two->object.flags |= PARENT2;
insert_by_date(one, &list);
- insert_by_date(two, &list);
+ for (i = 0; i < n; i++) {
+ twos[i]->object.flags |= PARENT2;
+ insert_by_date(twos[i], &list);
+ }
while (interesting(list)) {
struct commit *commit;
@@ -592,21 +600,26 @@ static struct commit_list *merge_bases(struct commit *one, struct commit *two)
return result;
}
-struct commit_list *get_merge_bases(struct commit *one,
- struct commit *two, int cleanup)
+struct commit_list *get_merge_bases_many(struct commit *one,
+ int n,
+ struct commit **twos,
+ int cleanup)
{
struct commit_list *list;
struct commit **rslt;
struct commit_list *result;
int cnt, i, j;
- result = merge_bases(one, two);
- if (one == two)
- return result;
+ result = merge_bases_many(one, n, twos);
+ for (i = 0; i < n; i++) {
+ if (one == twos[i])
+ return result;
+ }
if (!result || !result->next) {
if (cleanup) {
clear_commit_marks(one, all_flags);
- clear_commit_marks(two, all_flags);
+ for (i = 0; i < n; i++)
+ clear_commit_marks(twos[i], all_flags);
}
return result;
}
@@ -624,12 +637,13 @@ struct commit_list *get_merge_bases(struct commit *one,
free_commit_list(result);
clear_commit_marks(one, all_flags);
- clear_commit_marks(two, 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(rslt[i], rslt[j]);
+ 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) {
@@ -651,6 +665,12 @@ struct commit_list *get_merge_bases(struct commit *one,
return result;
}
+struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
+ int cleanup)
+{
+ return get_merge_bases_many(one, 1, &two, cleanup);
+}
+
int in_merge_bases(struct commit *commit, struct commit **reference, int num)
{
struct commit_list *bases, *b;
--
1.5.6.6.gd3e97
next prev parent reply other threads:[~2008-06-21 9:47 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-19 23:22 [PATCH 00/11] Build in merge Miklos Vajna
2008-06-19 23:22 ` [PATCH 01/11] Move split_cmdline() to alias.c Miklos Vajna
2008-06-19 23:22 ` [PATCH 02/11] Move commit_list_count() to commit.c Miklos Vajna
2008-06-19 23:22 ` [PATCH 03/11] Move parse-options's skip_prefix() to git-compat-util.h Miklos Vajna
2008-06-19 23:22 ` [PATCH 04/11] Add new test to ensure git-merge handles pull.twohead and pull.octopus Miklos Vajna
2008-06-19 23:22 ` [PATCH 05/11] parseopt: add a new PARSE_OPT_ARGV0_IS_AN_OPTION option Miklos Vajna
2008-06-19 23:22 ` [PATCH 06/11] Move read_cache_unmerged() to read-cache.c Miklos Vajna
2008-06-19 23:22 ` [PATCH 07/11] git-fmt-merge-msg: make it usable from other builtins Miklos Vajna
2008-06-19 23:22 ` [PATCH 08/11] Introduce get_octopus_merge_bases() in commit.c Miklos Vajna
2008-06-19 23:22 ` [PATCH 09/11] Introduce filter_independent() " Miklos Vajna
2008-06-19 23:22 ` [PATCH 10/11] Build in merge Miklos Vajna
2008-06-19 23:22 ` [PATCH 11/11] Add new test to ensure git-merge handles more than 25 refs Miklos Vajna
2008-06-20 3:03 ` [PATCH 09/11] Introduce filter_independent() in commit.c Junio C Hamano
2008-06-20 11:53 ` Johannes Schindelin
2008-06-20 12:06 ` Miklos Vajna
2008-06-20 12:37 ` Johannes Schindelin
2008-06-20 13:25 ` Miklos Vajna
2008-06-21 0:23 ` [PATCH] " Miklos Vajna
2008-06-21 9:45 ` Junio C Hamano
2008-06-21 17:00 ` [PATCH 00/13] Build in merge Miklos Vajna
2008-06-21 17:00 ` [PATCH 09/13] Add new test to ensure git-merge handles more than 25 refs Miklos Vajna
2008-06-21 17:00 ` [PATCH 10/13] Introduce get_merge_bases_many() Miklos Vajna
2008-06-21 17:00 ` [PATCH 11/13] Introduce reduce_heads() Miklos Vajna
2008-06-21 17:00 ` [PATCH 12/13] Build in merge Miklos Vajna
2008-06-21 17:00 ` [PATCH 13/13] Add new test case to ensure git-merge filters for independent parents Miklos Vajna
2008-06-21 17:15 ` [PATCH 13/13] Add new test case to ensure git-merge reduces octopus parents when possible Miklos Vajna
2008-06-25 16:22 ` [PATCH 12/13] Build in merge Olivier Marin
2008-06-27 1:06 ` Miklos Vajna
2008-06-27 11:03 ` Olivier Marin
2008-06-27 12:54 ` Miklos Vajna
2008-06-27 13:04 ` Olivier Marin
2008-06-27 13:17 ` Miklos Vajna
2008-06-27 11:56 ` Johannes Schindelin
2008-06-27 13:01 ` Miklos Vajna
2008-06-21 9:45 ` Junio C Hamano [this message]
2008-06-21 9:45 ` [PATCH 2/2] Introduce reduce_heads() Junio C Hamano
2008-06-20 3:04 ` [PATCH 00/11] Build in merge Junio C Hamano
2008-06-21 0:32 ` Miklos Vajna
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=7vlk0zazox.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=vmiklos@frugalware.org \
/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).