]>
Commit | Line | Data |
---|---|---|
03eae9af | 1 | #define USE_THE_REPOSITORY_VARIABLE |
c2e86add | 2 | #include "builtin.h" |
6c6ddf92 | 3 | #include "advice.h" |
f394e093 | 4 | #include "gettext.h" |
d1cbe1e6 | 5 | #include "hash.h" |
77c02949 | 6 | #include "merge-ort-wrappers.h" |
dabab1d6 | 7 | #include "object-name.h" |
6d297f81 | 8 | |
e78d01bf TF |
9 | static const char builtin_merge_recursive_usage[] = |
10 | "git %s <base>... -- <head> <remote> ..."; | |
11 | ||
d64bb065 | 12 | static char *better_branch_name(const char *branch) |
7ba3c078 | 13 | { |
b7f20f72 | 14 | static char githead_env[8 + GIT_MAX_HEXSZ + 1]; |
7ba3c078 SP |
15 | char *name; |
16 | ||
b7f20f72 | 17 | if (strlen(branch) != the_hash_algo->hexsz) |
d64bb065 | 18 | return xstrdup(branch); |
5096d490 | 19 | xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch); |
7ba3c078 | 20 | name = getenv(githead_env); |
d64bb065 | 21 | return xstrdup(name ? name : branch); |
7ba3c078 SP |
22 | } |
23 | ||
9b1cb507 JC |
24 | int cmd_merge_recursive(int argc, |
25 | const char **argv, | |
26 | const char *prefix UNUSED, | |
27 | struct repository *repo UNUSED) | |
6d297f81 | 28 | { |
3199b22e | 29 | struct object_id bases[21]; |
73118f89 SB |
30 | unsigned bases_count = 0; |
31 | int i, failed; | |
4e8161a8 | 32 | struct object_id h1, h2; |
8a2fce18 | 33 | struct merge_options o; |
d64bb065 | 34 | char *better1, *better2; |
8a2fce18 | 35 | struct commit *result; |
6d297f81 | 36 | |
9c93ba4d | 37 | init_basic_merge_options(&o, the_repository); |
59556548 | 38 | if (argv[0] && ends_with(argv[0], "-subtree")) |
85e51b78 | 39 | o.subtree_shift = ""; |
68faf689 | 40 | |
f66d1423 JH |
41 | if (argc == 2 && !strcmp(argv[1], "-h")) { |
42 | struct strbuf msg = STRBUF_INIT; | |
43 | strbuf_addf(&msg, builtin_merge_recursive_usage, argv[0]); | |
44 | show_usage_if_asked(argc, argv, msg.buf); | |
45 | } | |
46 | ||
6d297f81 | 47 | if (argc < 4) |
e78d01bf | 48 | usagef(builtin_merge_recursive_usage, argv[0]); |
6d297f81 | 49 | |
6d297f81 | 50 | for (i = 1; i < argc; ++i) { |
8cc5b290 AP |
51 | const char *arg = argv[i]; |
52 | ||
59556548 | 53 | if (starts_with(arg, "--")) { |
8cc5b290 AP |
54 | if (!arg[2]) |
55 | break; | |
635a7bb1 | 56 | if (parse_merge_opt(&o, arg + 2)) |
ccf78131 | 57 | die(_("unknown option %s"), arg); |
8cc5b290 AP |
58 | continue; |
59 | } | |
8a2fce18 | 60 | if (bases_count < ARRAY_SIZE(bases)-1) { |
3199b22e | 61 | if (repo_get_oid(the_repository, argv[i], &bases[bases_count++])) |
ccf78131 | 62 | die(_("could not parse object '%s'"), argv[i]); |
73118f89 | 63 | } |
73118f89 | 64 | else |
ccf78131 VA |
65 | warning(Q_("cannot handle more than %d base. " |
66 | "Ignoring %s.", | |
67 | "cannot handle more than %d bases. " | |
68 | "Ignoring %s.", | |
6f693252 | 69 | ARRAY_SIZE(bases)-1), |
b74d779b | 70 | (int)ARRAY_SIZE(bases)-1, argv[i]); |
6d297f81 JS |
71 | } |
72 | if (argc - i != 3) /* "--" "<head>" "<remote>" */ | |
ccf78131 | 73 | die(_("not handling anything other than two heads merge.")); |
6d297f81 | 74 | |
9822175d EN |
75 | if (repo_read_index_unmerged(the_repository)) |
76 | die_resolve_conflict("merge"); | |
77 | ||
8a2fce18 MV |
78 | o.branch1 = argv[++i]; |
79 | o.branch2 = argv[++i]; | |
6d297f81 | 80 | |
d850b7a5 | 81 | if (repo_get_oid(the_repository, o.branch1, &h1)) |
ccf78131 | 82 | die(_("could not resolve ref '%s'"), o.branch1); |
d850b7a5 | 83 | if (repo_get_oid(the_repository, o.branch2, &h2)) |
ccf78131 | 84 | die(_("could not resolve ref '%s'"), o.branch2); |
6d297f81 | 85 | |
d64bb065 JK |
86 | o.branch1 = better1 = better_branch_name(o.branch1); |
87 | o.branch2 = better2 = better_branch_name(o.branch2); | |
3f6ee2d1 | 88 | |
8a2fce18 | 89 | if (o.verbosity >= 3) |
765773c8 | 90 | printf(_("Merging %s with %s\n"), o.branch1, o.branch2); |
e0ec1819 | 91 | |
77c02949 | 92 | failed = merge_ort_generic(&o, &h1, &h2, bases_count, bases, &result); |
d64bb065 JK |
93 | |
94 | free(better1); | |
95 | free(better2); | |
96 | ||
73118f89 SB |
97 | if (failed < 0) |
98 | return 128; /* die() error code */ | |
99 | return failed; | |
6d297f81 | 100 | } |