@matheusbsbs / matheus-bagliano / commits / 53eda89b2f
Fork 0

merge-base: teach "git merge-base" to drive underlying merge_bases_many()

Even though the underlying function for get_merge_bases() can compute a merge base between one existing commit and another (possibly nonexistent) commit that would be created by merging many commits, the facility was not available to git-merge-base. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jul 30, 2008 at 07:04 UTC 53eda89b2fe13e974ca85367255f9a5e9ab9171f
2 files changed +17 -8
builtin-merge-base.c
+16 -8
@@ -2,9 +2,11 @@
2 #include "cache.h"
3 #include "commit.h"
4
5 -static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
5 +static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
6 {
7 - struct commit_list *result = get_merge_bases(rev1, rev2, 0);
7 + struct commit_list *result;
8 +
9 + result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1, 0);
10
11 if (!result)
12 return 1;
@@ -20,7 +22,7 @@ static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_al
22 }
23
24 static const char merge_base_usage[] =
23 -"git merge-base [--all] <commit-id> <commit-id>";
25 +"git merge-base [--all] <commit-id> <commit-id>...";
26
27 static struct commit *get_commit_reference(const char *arg)
28 {
@@ -38,7 +40,8 @@ static struct commit *get_commit_reference(const char *arg)
40
41 int cmd_merge_base(int argc, const char **argv, const char *prefix)
42 {
41 - struct commit *rev1, *rev2;
43 + struct commit **rev;
44 + int rev_nr = 0;
45 int show_all = 0;
46
47 git_config(git_default_config, NULL);
@@ -51,10 +54,15 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
54 usage(merge_base_usage);
55 argc--; argv++;
56 }
54 - if (argc != 3)
57 + if (argc < 3)
58 usage(merge_base_usage);
56 - rev1 = get_commit_reference(argv[1]);
57 - rev2 = get_commit_reference(argv[2]);
59
59 - return show_merge_base(rev1, rev2, show_all);
60 + rev = xmalloc((argc - 1) * sizeof(*rev));
61 +
62 + do {
63 + rev[rev_nr++] = get_commit_reference(argv[1]);
64 + argc--; argv++;
65 + } while (argc > 1);
66 +
67 + return show_merge_base(rev, rev_nr, show_all);
68 }
commit.h
+1
@@ -121,6 +121,7 @@ int read_graft_file(const char *graft_file);
121 struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
122
123 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
124 +extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
125 extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
126
127 extern int register_shallow(const unsigned char *sha1);