4 #include "merge-recursive.h"
5 #include "xdiff-interface.h"
7 static const char builtin_merge_recursive_usage
[] =
8 "git %s <base>... -- <head> <remote> ...";
10 static const char *better_branch_name(const char *branch
)
12 static char githead_env
[8 + GIT_MAX_HEXSZ
+ 1];
15 if (strlen(branch
) != the_hash_algo
->hexsz
)
17 xsnprintf(githead_env
, sizeof(githead_env
), "GITHEAD_%s", branch
);
18 name
= getenv(githead_env
);
19 return name
? name
: branch
;
22 int cmd_merge_recursive(int argc
, const char **argv
, const char *prefix
)
24 const struct object_id
*bases
[21];
25 unsigned bases_count
= 0;
27 struct object_id h1
, h2
;
28 struct merge_options o
;
29 struct commit
*result
;
31 init_merge_options(&o
);
32 if (argv
[0] && ends_with(argv
[0], "-subtree"))
36 usagef(builtin_merge_recursive_usage
, argv
[0]);
38 for (i
= 1; i
< argc
; ++i
) {
39 const char *arg
= argv
[i
];
41 if (starts_with(arg
, "--")) {
44 if (parse_merge_opt(&o
, arg
+ 2))
45 die(_("unknown option %s"), arg
);
48 if (bases_count
< ARRAY_SIZE(bases
)-1) {
49 struct object_id
*oid
= xmalloc(sizeof(struct object_id
));
50 if (get_oid(argv
[i
], oid
))
51 die(_("could not parse object '%s'"), argv
[i
]);
52 bases
[bases_count
++] = oid
;
55 warning(Q_("cannot handle more than %d base. "
57 "cannot handle more than %d bases. "
59 (int)ARRAY_SIZE(bases
)-1),
60 (int)ARRAY_SIZE(bases
)-1, argv
[i
]);
62 if (argc
- i
!= 3) /* "--" "<head>" "<remote>" */
63 die(_("not handling anything other than two heads merge."));
65 o
.branch1
= argv
[++i
];
66 o
.branch2
= argv
[++i
];
68 if (get_oid(o
.branch1
, &h1
))
69 die(_("could not resolve ref '%s'"), o
.branch1
);
70 if (get_oid(o
.branch2
, &h2
))
71 die(_("could not resolve ref '%s'"), o
.branch2
);
73 o
.branch1
= better_branch_name(o
.branch1
);
74 o
.branch2
= better_branch_name(o
.branch2
);
77 printf(_("Merging %s with %s\n"), o
.branch1
, o
.branch2
);
79 failed
= merge_recursive_generic(&o
, &h1
, &h2
, bases_count
, bases
, &result
);
81 return 128; /* die() error code */