mirror of
https://github.com/git/git
synced 2024-10-02 14:45:21 +00:00
merge: use argv_array when spawning merge strategy
This is shorter, and avoids a rather complicated set of allocation and free steps. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
3bdd55228b
commit
5c1753b198
42
merge.c
42
merge.c
|
@ -18,39 +18,23 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
|
||||||
const char **xopts, struct commit_list *common,
|
const char **xopts, struct commit_list *common,
|
||||||
const char *head_arg, struct commit_list *remotes)
|
const char *head_arg, struct commit_list *remotes)
|
||||||
{
|
{
|
||||||
const char **args;
|
struct argv_array args = ARGV_ARRAY_INIT;
|
||||||
int i = 0, x = 0, ret;
|
int i, ret;
|
||||||
struct commit_list *j;
|
struct commit_list *j;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
|
||||||
|
|
||||||
args = xmalloc((4 + xopts_nr + commit_list_count(common) +
|
argv_array_pushf(&args, "merge-%s", strategy);
|
||||||
commit_list_count(remotes)) * sizeof(char *));
|
for (i = 0; i < xopts_nr; i++)
|
||||||
strbuf_addf(&buf, "merge-%s", strategy);
|
argv_array_pushf(&args, "--%s", xopts[i]);
|
||||||
args[i++] = buf.buf;
|
|
||||||
for (x = 0; x < xopts_nr; x++) {
|
|
||||||
char *s = xmalloc(strlen(xopts[x])+2+1);
|
|
||||||
strcpy(s, "--");
|
|
||||||
strcpy(s+2, xopts[x]);
|
|
||||||
args[i++] = s;
|
|
||||||
}
|
|
||||||
for (j = common; j; j = j->next)
|
for (j = common; j; j = j->next)
|
||||||
args[i++] = xstrdup(merge_argument(j->item));
|
argv_array_push(&args, merge_argument(j->item));
|
||||||
args[i++] = "--";
|
argv_array_push(&args, "--");
|
||||||
args[i++] = head_arg;
|
argv_array_push(&args, head_arg);
|
||||||
for (j = remotes; j; j = j->next)
|
for (j = remotes; j; j = j->next)
|
||||||
args[i++] = xstrdup(merge_argument(j->item));
|
argv_array_push(&args, merge_argument(j->item));
|
||||||
args[i] = NULL;
|
|
||||||
ret = run_command_v_opt(args, RUN_GIT_CMD);
|
ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
|
||||||
strbuf_release(&buf);
|
argv_array_clear(&args);
|
||||||
i = 1;
|
|
||||||
for (x = 0; x < xopts_nr; x++)
|
|
||||||
free((void *)args[i++]);
|
|
||||||
for (j = common; j; j = j->next)
|
|
||||||
free((void *)args[i++]);
|
|
||||||
i += 2;
|
|
||||||
for (j = remotes; j; j = j->next)
|
|
||||||
free((void *)args[i++]);
|
|
||||||
free(args);
|
|
||||||
discard_cache();
|
discard_cache();
|
||||||
if (read_cache() < 0)
|
if (read_cache() < 0)
|
||||||
die(_("failed to read the cache"));
|
die(_("failed to read the cache"));
|
||||||
|
|
Loading…
Reference in a new issue