4 #include "merge-recursive.h"
6 static const char *better_branch_name(const char *branch)
8 static char githead_env[8 + 40 + 1];
11 if (strlen(branch) != 40)
13 sprintf(githead_env, "GITHEAD_%s", branch);
14 name = getenv(githead_env);
15 return name ? name : branch;
18 int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
20 const unsigned char *bases[21];
21 unsigned bases_count = 0;
23 unsigned char h1[20], h2[20];
24 struct merge_options o;
25 struct commit *result;
27 init_merge_options(&o);
28 if (argv[0] && !suffixcmp(argv[0], "-subtree"))
32 usagef("%s <base>... -- <head> <remote> ...", argv[0]);
34 for (i = 1; i < argc; ++i) {
35 const char *arg = argv[i];
37 if (!prefixcmp(arg, "--")) {
40 if (parse_merge_opt(&o, arg + 2))
41 die("Unknown option %s", arg);
44 if (bases_count < ARRAY_SIZE(bases)-1) {
45 unsigned char *sha = xmalloc(20);
46 if (get_sha1(argv[i], sha))
47 die("Could not parse object '%s'", argv[i]);
48 bases[bases_count++] = sha;
51 warning("Cannot handle more than %d bases. "
53 (int)ARRAY_SIZE(bases)-1, argv[i]);
55 if (argc - i != 3) /* "--" "<head>" "<remote>" */
56 die("Not handling anything other than two heads merge.");
58 o.branch1 = argv[++i];
59 o.branch2 = argv[++i];
61 if (get_sha1(o.branch1, h1))
62 die("Could not resolve ref '%s'", o.branch1);
63 if (get_sha1(o.branch2, h2))
64 die("Could not resolve ref '%s'", o.branch2);
66 o.branch1 = better_branch_name(o.branch1);
67 o.branch2 = better_branch_name(o.branch2);
70 printf("Merging %s with %s\n", o.branch1, o.branch2);
72 failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result);
74 return 128; /* die() error code */