Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 64 lines (51 sloc) 1.405 kb
baffc0e Make every builtin-*.c file #include "builtin.h"
Peter Hagervall authored
1 #include "builtin.h"
6683463 Do a very simple "merge-base" that finds the most recent common
Linus Torvalds authored
2 #include "cache.h"
b5039db [PATCH] Switch implementations of merge-base, port to parsing
Daniel Barkalow authored
3 #include "commit.h"
e5d1a4d @MadCoder parse-opt: migrate git-merge-base.
MadCoder authored
4 #include "parse-options.h"
6683463 Do a very simple "merge-base" that finds the most recent common
Linus Torvalds authored
5
53eda89 @chriscool merge-base: teach "git merge-base" to drive underlying merge_bases_many(...
chriscool authored
6 static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
52cab8a @dscho refactor merge_bases() as preparation to libify merge-base
dscho authored
7 {
53eda89 @chriscool merge-base: teach "git merge-base" to drive underlying merge_bases_many(...
chriscool authored
8 struct commit_list *result;
9
10 result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1, 0);
52cab8a @dscho refactor merge_bases() as preparation to libify merge-base
dscho authored
11
12 if (!result)
13 return 1;
14
9585e40 Try to find the optimum merge base while resolving.
Junio C Hamano authored
15 while (result) {
52cab8a @dscho refactor merge_bases() as preparation to libify merge-base
dscho authored
16 printf("%s\n", sha1_to_hex(result->item->object.sha1));
9585e40 Try to find the optimum merge base while resolving.
Junio C Hamano authored
17 if (!show_all)
18 return 0;
52cab8a @dscho refactor merge_bases() as preparation to libify merge-base
dscho authored
19 result = result->next;
9585e40 Try to find the optimum merge base while resolving.
Junio C Hamano authored
20 }
52cab8a @dscho refactor merge_bases() as preparation to libify merge-base
dscho authored
21
9585e40 Try to find the optimum merge base while resolving.
Junio C Hamano authored
22 return 0;
6683463 Do a very simple "merge-base" that finds the most recent common
Linus Torvalds authored
23 }
24
e5d1a4d @MadCoder parse-opt: migrate git-merge-base.
MadCoder authored
25 static const char * const merge_base_usage[] = {
995bdc7 @mjg git-merge-base/git-show-branch: Cleanup documentation and usage
mjg authored
26 "git merge-base [-a|--all] <commit> <commit>...",
e5d1a4d @MadCoder parse-opt: migrate git-merge-base.
MadCoder authored
27 NULL
28 };
9585e40 Try to find the optimum merge base while resolving.
Junio C Hamano authored
29
df57acc @chriscool merge-base: die with an error message if not passed a commit ref
chriscool authored
30 static struct commit *get_commit_reference(const char *arg)
31 {
32 unsigned char revkey[20];
33 struct commit *r;
34
35 if (get_sha1(arg, revkey))
36 die("Not a valid object name %s", arg);
37 r = lookup_commit_reference(revkey);
38 if (!r)
39 die("Not a valid commit name %s", arg);
40
41 return r;
42 }
43
71dfbf2 Make merge-base a built-in.
Junio C Hamano authored
44 int cmd_merge_base(int argc, const char **argv, const char *prefix)
6683463 Do a very simple "merge-base" that finds the most recent common
Linus Torvalds authored
45 {
53eda89 @chriscool merge-base: teach "git merge-base" to drive underlying merge_bases_many(...
chriscool authored
46 struct commit **rev;
47 int rev_nr = 0;
71dfbf2 Make merge-base a built-in.
Junio C Hamano authored
48 int show_all = 0;
6683463 Do a very simple "merge-base" that finds the most recent common
Linus Torvalds authored
49
e5d1a4d @MadCoder parse-opt: migrate git-merge-base.
MadCoder authored
50 struct option options[] = {
51 OPT_BOOLEAN('a', "all", &show_all, "outputs all common ancestors"),
52 OPT_END()
53 };
53eda89 @chriscool merge-base: teach "git merge-base" to drive underlying merge_bases_many(...
chriscool authored
54
e5d1a4d @MadCoder parse-opt: migrate git-merge-base.
MadCoder authored
55 git_config(git_default_config, NULL);
3778292 @bebarino parse-opts: prepare for OPT_FILENAME
bebarino authored
56 argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0);
e5d1a4d @MadCoder parse-opt: migrate git-merge-base.
MadCoder authored
57 if (argc < 2)
58 usage_with_options(merge_base_usage, options);
59 rev = xmalloc(argc * sizeof(*rev));
60 while (argc-- > 0)
61 rev[rev_nr++] = get_commit_reference(*argv++);
53eda89 @chriscool merge-base: teach "git merge-base" to drive underlying merge_bases_many(...
chriscool authored
62 return show_merge_base(rev, rev_nr, show_all);
6683463 Do a very simple "merge-base" that finds the most recent common
Linus Torvalds authored
63 }
Something went wrong with that request. Please try again.