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