]>
Commit | Line | Data |
---|---|---|
6d297f81 | 1 | #include "cache.h" |
6d297f81 | 2 | #include "commit.h" |
6d297f81 | 3 | #include "tag.h" |
e1b3a2ca | 4 | #include "merge-recursive.h" |
6d297f81 | 5 | |
7ba3c078 SP |
6 | static const char *better_branch_name(const char *branch) |
7 | { | |
8 | static char githead_env[8 + 40 + 1]; | |
9 | char *name; | |
10 | ||
11 | if (strlen(branch) != 40) | |
12 | return branch; | |
13 | sprintf(githead_env, "GITHEAD_%s", branch); | |
14 | name = getenv(githead_env); | |
15 | return name ? name : branch; | |
16 | } | |
17 | ||
e1b3a2ca | 18 | int cmd_merge_recursive(int argc, const char **argv, const char *prefix) |
6d297f81 | 19 | { |
8a2fce18 | 20 | const unsigned char *bases[21]; |
73118f89 SB |
21 | unsigned bases_count = 0; |
22 | int i, failed; | |
73118f89 | 23 | unsigned char h1[20], h2[20]; |
8a2fce18 MV |
24 | struct merge_options o; |
25 | struct commit *result; | |
6d297f81 | 26 | |
8a2fce18 | 27 | init_merge_options(&o); |
68faf689 JH |
28 | if (argv[0]) { |
29 | int namelen = strlen(argv[0]); | |
30 | if (8 < namelen && | |
31 | !strcmp(argv[0] + namelen - 8, "-subtree")) | |
8a2fce18 | 32 | o.subtree_merge = 1; |
68faf689 JH |
33 | } |
34 | ||
6d297f81 | 35 | if (argc < 4) |
d7530708 | 36 | die("Usage: %s <base>... -- <head> <remote> ...", argv[0]); |
6d297f81 | 37 | |
6d297f81 | 38 | for (i = 1; i < argc; ++i) { |
8a2fce18 | 39 | if (!strcmp(argv[i], "--")) |
6d297f81 | 40 | break; |
8a2fce18 MV |
41 | if (bases_count < ARRAY_SIZE(bases)-1) { |
42 | unsigned char *sha = xmalloc(20); | |
43 | if (get_sha1(argv[i], sha)) | |
44 | die("Could not parse object '%s'", argv[i]); | |
45 | bases[bases_count++] = sha; | |
73118f89 | 46 | } |
73118f89 SB |
47 | else |
48 | warning("Cannot handle more than %zu bases. " | |
49 | "Ignoring %s.", ARRAY_SIZE(bases)-1, argv[i]); | |
6d297f81 JS |
50 | } |
51 | if (argc - i != 3) /* "--" "<head>" "<remote>" */ | |
52 | die("Not handling anything other than two heads merge."); | |
53 | ||
8a2fce18 MV |
54 | o.branch1 = argv[++i]; |
55 | o.branch2 = argv[++i]; | |
6d297f81 | 56 | |
8a2fce18 MV |
57 | if (get_sha1(o.branch1, h1)) |
58 | die("Could not resolve ref '%s'", o.branch1); | |
59 | if (get_sha1(o.branch2, h2)) | |
60 | die("Could not resolve ref '%s'", o.branch2); | |
6d297f81 | 61 | |
8a2fce18 MV |
62 | o.branch1 = better_branch_name(o.branch1); |
63 | o.branch2 = better_branch_name(o.branch2); | |
3f6ee2d1 | 64 | |
8a2fce18 MV |
65 | if (o.verbosity >= 3) |
66 | printf("Merging %s with %s\n", o.branch1, o.branch2); | |
e0ec1819 | 67 | |
8a2fce18 | 68 | failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result); |
73118f89 SB |
69 | if (failed < 0) |
70 | return 128; /* die() error code */ | |
71 | return failed; | |
6d297f81 | 72 | } |