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
);
29 int namelen
= strlen(argv
[0]);
31 !strcmp(argv
[0] + namelen
- 8, "-subtree"))
36 die("Usage: %s <base>... -- <head> <remote> ...", argv
[0]);
38 for (i
= 1; i
< argc
; ++i
) {
39 if (!strcmp(argv
[i
], "--"))
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
;
48 warning("Cannot handle more than %d bases. "
50 (int)ARRAY_SIZE(bases
)-1, argv
[i
]);
52 if (argc
- i
!= 3) /* "--" "<head>" "<remote>" */
53 die("Not handling anything other than two heads merge.");
55 o
.branch1
= argv
[++i
];
56 o
.branch2
= argv
[++i
];
58 if (get_sha1(o
.branch1
, h1
))
59 die("Could not resolve ref '%s'", o
.branch1
);
60 if (get_sha1(o
.branch2
, h2
))
61 die("Could not resolve ref '%s'", o
.branch2
);
63 o
.branch1
= better_branch_name(o
.branch1
);
64 o
.branch2
= better_branch_name(o
.branch2
);
67 printf("Merging %s with %s\n", o
.branch1
, o
.branch2
);
69 failed
= merge_recursive_generic(&o
, h1
, h2
, bases_count
, bases
, &result
);
71 return 128; /* die() error code */