[PATCH 09/10] Introduce get_octopus_merge_bases() in commit.c
From: Miklos Vajna <hidden>
Date: 2016-06-15 22:44:41
Subsystem:
the rest · Maintainer:
Linus Torvalds
This is like get_merge_bases() but it works for multiple heads, like show-branch --merge-base. Signed-off-by: Miklos Vajna <redacted> --- commit.c | 32 ++++++++++++++++++++++++++++++++ commit.h | 1 + 2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/commit.c b/commit.c
index 6ba5acb..c09b305 100644
--- a/commit.c
+++ b/commit.c@@ -625,6 +625,38 @@ static struct commit_list *merge_bases(struct commit *one, struct commit *two) return result; } +struct commit_list *get_octopus_merge_bases(struct commit_list *in, int cleanup) +{ + struct commit_list *i, *j, *k, *ret = NULL; + + for (i = in; i; i = i->next) { + if (!ret) + commit_list_append(i->item, &ret); + else { + struct commit_list *new = NULL, *end = NULL; + + for (j = ret; j; j = j->next) { + struct commit_list *bases; + bases = get_merge_bases(i->item, j->item, cleanup); + /* + * Now we just append bases to new, but + * calling commit_list_append() for each + * item would be expensive, so do it by + * hand. + */ + if (!new) + new = bases; + else + end->next = bases; + for (k = bases; k; k = k->next) + end = k; + } + ret = new; + } + } + return ret; +} + struct commit_list *get_merge_bases(struct commit *one, struct commit *two, int cleanup) {
diff --git a/commit.h b/commit.h
index 5d9ac43..201782d 100644
--- a/commit.h
+++ b/commit.h@@ -122,6 +122,7 @@ int read_graft_file(const char *graft_file); struct commit_graft *lookup_commit_graft(const unsigned char *sha1); extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup); +extern struct commit_list *get_octopus_merge_bases(struct commit_list *in, int cleanup); extern int register_shallow(const unsigned char *sha1); extern int unregister_shallow(const unsigned char *sha1);
--
1.5.6.rc0.dirty