]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/merge-recursive.c
merge-recursive: convert merge_recursive_generic() to object_id
[thirdparty/git.git] / builtin / merge-recursive.c
CommitLineData
c2e86add 1#include "builtin.h"
6d297f81 2#include "commit.h"
6d297f81 3#include "tag.h"
e1b3a2ca 4#include "merge-recursive.h"
58a1ece4 5#include "xdiff-interface.h"
6d297f81 6
e78d01bf
TF
7static const char builtin_merge_recursive_usage[] =
8 "git %s <base>... -- <head> <remote> ...";
9
7ba3c078
SP
10static const char *better_branch_name(const char *branch)
11{
4e8161a8 12 static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
7ba3c078
SP
13 char *name;
14
4e8161a8 15 if (strlen(branch) != GIT_SHA1_HEXSZ)
7ba3c078 16 return branch;
5096d490 17 xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
7ba3c078
SP
18 name = getenv(githead_env);
19 return name ? name : branch;
20}
21
e1b3a2ca 22int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
6d297f81 23{
4e8161a8 24 const struct object_id *bases[21];
73118f89
SB
25 unsigned bases_count = 0;
26 int i, failed;
4e8161a8 27 struct object_id h1, h2;
8a2fce18
MV
28 struct merge_options o;
29 struct commit *result;
6d297f81 30
8a2fce18 31 init_merge_options(&o);
59556548 32 if (argv[0] && ends_with(argv[0], "-subtree"))
85e51b78 33 o.subtree_shift = "";
68faf689 34
6d297f81 35 if (argc < 4)
e78d01bf 36 usagef(builtin_merge_recursive_usage, argv[0]);
6d297f81 37
6d297f81 38 for (i = 1; i < argc; ++i) {
8cc5b290
AP
39 const char *arg = argv[i];
40
59556548 41 if (starts_with(arg, "--")) {
8cc5b290
AP
42 if (!arg[2])
43 break;
635a7bb1 44 if (parse_merge_opt(&o, arg + 2))
8cc5b290
AP
45 die("Unknown option %s", arg);
46 continue;
47 }
8a2fce18 48 if (bases_count < ARRAY_SIZE(bases)-1) {
4e8161a8 49 struct object_id *oid = xmalloc(sizeof(struct object_id));
50 if (get_oid(argv[i], oid))
8a2fce18 51 die("Could not parse object '%s'", argv[i]);
4e8161a8 52 bases[bases_count++] = oid;
73118f89 53 }
73118f89 54 else
b74d779b
JS
55 warning("Cannot handle more than %d bases. "
56 "Ignoring %s.",
57 (int)ARRAY_SIZE(bases)-1, argv[i]);
6d297f81
JS
58 }
59 if (argc - i != 3) /* "--" "<head>" "<remote>" */
60 die("Not handling anything other than two heads merge.");
61
8a2fce18
MV
62 o.branch1 = argv[++i];
63 o.branch2 = argv[++i];
6d297f81 64
4e8161a8 65 if (get_oid(o.branch1, &h1))
8a2fce18 66 die("Could not resolve ref '%s'", o.branch1);
4e8161a8 67 if (get_oid(o.branch2, &h2))
8a2fce18 68 die("Could not resolve ref '%s'", o.branch2);
6d297f81 69
8a2fce18
MV
70 o.branch1 = better_branch_name(o.branch1);
71 o.branch2 = better_branch_name(o.branch2);
3f6ee2d1 72
8a2fce18
MV
73 if (o.verbosity >= 3)
74 printf("Merging %s with %s\n", o.branch1, o.branch2);
e0ec1819 75
4e8161a8 76 failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
73118f89
SB
77 if (failed < 0)
78 return 128; /* die() error code */
79 return failed;
6d297f81 80}