15
return name ? name : branch;
16
}
17
18
-static struct commit *get_ref(const char *ref)
19
-{
20
- unsigned char sha1[20];
21
- struct object *object;
22
-
23
- if (get_sha1(ref, sha1))
24
- die("Could not resolve ref '%s'", ref);
25
- object = deref_tag(parse_object(sha1), ref, strlen(ref));
26
- if (!object)
27
- return NULL;
28
- if (object->type == OBJ_TREE)
29
- return make_virtual_commit((struct tree*)object,
30
- better_branch_name(ref));
31
- if (object->type != OBJ_COMMIT)
32
- return NULL;
33
- if (parse_commit((struct commit *)object))
34
- die("Could not parse commit '%s'", sha1_to_hex(object->sha1));
35
- return (struct commit *)object;
36
-}
37
-
18
int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
19
{
40
- static const char *bases[20];
41
- static unsigned bases_count = 0;
42
- int i, clean;
20
+ const char *bases[21];
21
+ unsigned bases_count = 0;
22
+ int i, failed;
23
const char *branch1, *branch2;
44
- struct commit *result, *h1, *h2;
45
- struct commit_list *ca = NULL;
46
- struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
47
- int index_fd;
24
+ unsigned char h1[20], h2[20];
25
int subtree_merge = 0;
26
27
if (argv[0]) {
37
die("Usage: %s <base>... -- <head> <remote> ...\n", argv[0]);
38
39
for (i = 1; i < argc; ++i) {
63
- if (!strcmp(argv[i], "--"))
40
+ if (!strcmp(argv[i], "--")) {
41
+ bases[bases_count] = NULL;
42
break;
65
- if (bases_count < sizeof(bases)/sizeof(*bases))
43
+ }
44
+ if (bases_count < ARRAY_SIZE(bases)-1)
45
bases[bases_count++] = argv[i];
46
+ else
47
+ warning("Cannot handle more than %zu bases. "
48
+ "Ignoring %s.", ARRAY_SIZE(bases)-1, argv[i]);
49
}
50
if (argc - i != 3) /* "--" "<head>" "<remote>" */
51
die("Not handling anything other than two heads merge.");
53
branch1 = argv[++i];
54
branch2 = argv[++i];
55
74
- h1 = get_ref(branch1);
75
- h2 = get_ref(branch2);
56
+ if (get_sha1(branch1, h1))
57
+ die("Could not resolve ref '%s'", branch1);
58
+ if (get_sha1(branch2, h2))
59
+ die("Could not resolve ref '%s'", branch2);
60
61
branch1 = better_branch_name(branch1);
62
branch2 = better_branch_name(branch2);
64
if (merge_recursive_verbosity >= 3)
65
printf("Merging %s with %s\n", branch1, branch2);
66
83
- index_fd = hold_locked_index(lock, 1);
84
-
85
- for (i = 0; i < bases_count; i++) {
86
- struct commit *ancestor = get_ref(bases[i]);
87
- ca = commit_list_insert(ancestor, &ca);
88
- }
89
- clean = merge_recursive(h1, h2, branch1, branch2, ca, &result);
90
-
91
- if (active_cache_changed &&
92
- (write_cache(index_fd, active_cache, active_nr) ||
93
- commit_locked_index(lock)))
94
- die ("unable to write %s", get_index_file());
95
-
96
- return clean ? 0: 1;
67
+ failed = merge_recursive_generic(bases, h1, branch1, h2, branch2);
68
+ if (failed < 0)
69
+ return 128; /* die() error code */
70
+ return failed;
71
}