Skip to content

Commit

Permalink
Introduce get_octopus_merge_bases() in commit.c
Browse files Browse the repository at this point in the history
This is like get_merge_bases() but it works for multiple heads, like
show-branch --merge-base.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Miklos Vajna authored and Junio C Hamano committed Jul 1, 2008
1 parent 0b9a969 commit 5240c9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,33 @@ 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)
{
struct commit_list *i, *j, *k, *ret = NULL;
struct commit_list **pptr = &ret;

for (i = in; i; i = i->next) {
if (!ret)
pptr = &commit_list_insert(i->item, pptr)->next;
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, 1);
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)
{
Expand Down
1 change: 1 addition & 0 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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);

extern int register_shallow(const unsigned char *sha1);
extern int unregister_shallow(const unsigned char *sha1);
Expand Down

0 comments on commit 5240c9d

Please sign in to comment.