]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/merge-recursive.c
log,diff-tree: add --combined-all-paths option
[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
d64bb065 10static char *better_branch_name(const char *branch)
7ba3c078 11{
b7f20f72 12 static char githead_env[8 + GIT_MAX_HEXSZ + 1];
7ba3c078
SP
13 char *name;
14
b7f20f72 15 if (strlen(branch) != the_hash_algo->hexsz)
d64bb065 16 return xstrdup(branch);
5096d490 17 xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
7ba3c078 18 name = getenv(githead_env);
d64bb065 19 return xstrdup(name ? name : branch);
7ba3c078
SP
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 28 struct merge_options o;
d64bb065 29 char *better1, *better2;
8a2fce18 30 struct commit *result;
6d297f81 31
8a2fce18 32 init_merge_options(&o);
59556548 33 if (argv[0] && ends_with(argv[0], "-subtree"))
85e51b78 34 o.subtree_shift = "";
68faf689 35
6d297f81 36 if (argc < 4)
e78d01bf 37 usagef(builtin_merge_recursive_usage, argv[0]);
6d297f81 38
6d297f81 39 for (i = 1; i < argc; ++i) {
8cc5b290
AP
40 const char *arg = argv[i];
41
59556548 42 if (starts_with(arg, "--")) {
8cc5b290
AP
43 if (!arg[2])
44 break;
635a7bb1 45 if (parse_merge_opt(&o, arg + 2))
ccf78131 46 die(_("unknown option %s"), arg);
8cc5b290
AP
47 continue;
48 }
8a2fce18 49 if (bases_count < ARRAY_SIZE(bases)-1) {
4e8161a8 50 struct object_id *oid = xmalloc(sizeof(struct object_id));
51 if (get_oid(argv[i], oid))
ccf78131 52 die(_("could not parse object '%s'"), argv[i]);
4e8161a8 53 bases[bases_count++] = oid;
73118f89 54 }
73118f89 55 else
ccf78131
VA
56 warning(Q_("cannot handle more than %d base. "
57 "Ignoring %s.",
58 "cannot handle more than %d bases. "
59 "Ignoring %s.",
60 (int)ARRAY_SIZE(bases)-1),
b74d779b 61 (int)ARRAY_SIZE(bases)-1, argv[i]);
6d297f81
JS
62 }
63 if (argc - i != 3) /* "--" "<head>" "<remote>" */
ccf78131 64 die(_("not handling anything other than two heads merge."));
6d297f81 65
8a2fce18
MV
66 o.branch1 = argv[++i];
67 o.branch2 = argv[++i];
6d297f81 68
4e8161a8 69 if (get_oid(o.branch1, &h1))
ccf78131 70 die(_("could not resolve ref '%s'"), o.branch1);
4e8161a8 71 if (get_oid(o.branch2, &h2))
ccf78131 72 die(_("could not resolve ref '%s'"), o.branch2);
6d297f81 73
d64bb065
JK
74 o.branch1 = better1 = better_branch_name(o.branch1);
75 o.branch2 = better2 = better_branch_name(o.branch2);
3f6ee2d1 76
8a2fce18 77 if (o.verbosity >= 3)
765773c8 78 printf(_("Merging %s with %s\n"), o.branch1, o.branch2);
e0ec1819 79
4e8161a8 80 failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
d64bb065
JK
81
82 free(better1);
83 free(better2);
84
73118f89
SB
85 if (failed < 0)
86 return 128; /* die() error code */
87 return failed;
6d297f81 88}