From 0077138cd9d4f94636184553afd8b33b98d320a1 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 8 Jun 2009 22:34:29 +0200 Subject: [PATCH] Simplify some instances of run_command() by using run_command_v_opt(). Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- builtin-receive-pack.c | 10 +++------- ll-merge.c | 11 ++--------- merge-index.c | 42 +++++++++++++----------------------------- 3 files changed, 18 insertions(+), 45 deletions(-) diff --git a/builtin-receive-pack.c b/builtin-receive-pack.c index 0b08da9b5..33d345dc3 100644 --- a/builtin-receive-pack.c +++ b/builtin-receive-pack.c @@ -192,7 +192,6 @@ static int run_receive_hook(const char *hook_name) static int run_update_hook(struct command *cmd) { static const char update_hook[] = "hooks/update"; - struct child_process proc; const char *argv[5]; if (access(update_hook, X_OK) < 0) @@ -204,12 +203,9 @@ static int run_update_hook(struct command *cmd) argv[3] = sha1_to_hex(cmd->new_sha1); argv[4] = NULL; - memset(&proc, 0, sizeof(proc)); - proc.argv = argv; - proc.no_stdin = 1; - proc.stdout_to_stderr = 1; - - return hook_status(run_command(&proc), update_hook); + return hook_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | + RUN_COMMAND_STDOUT_TO_STDERR), + update_hook); } static int is_ref_checked_out(const char *ref) diff --git a/ll-merge.c b/ll-merge.c index 81c02ad05..31d6f0a2e 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -175,8 +175,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn, { "B", temp[2] }, { NULL } }; - struct child_process child; - const char *args[20]; + const char *args[] = { "sh", "-c", NULL, NULL }; int status, fd, i; struct stat st; @@ -191,14 +190,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn, strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict); - memset(&child, 0, sizeof(child)); - child.argv = args; - args[0] = "sh"; - args[1] = "-c"; args[2] = cmd.buf; - args[3] = NULL; - - status = run_command(&child); + status = run_command_v_opt(args, 0); if (status < -ERR_RUN_COMMAND_FORK) ; /* failure in run-command */ else diff --git a/merge-index.c b/merge-index.c index aa9cf23a3..19ddd03e0 100644 --- a/merge-index.c +++ b/merge-index.c @@ -3,45 +3,20 @@ #include "exec_cmd.h" static const char *pgm; -static const char *arguments[9]; static int one_shot, quiet; static int err; -static void run_program(void) -{ - struct child_process child; - memset(&child, 0, sizeof(child)); - child.argv = arguments; - if (run_command(&child)) { - if (one_shot) { - err++; - } else { - if (!quiet) - die("merge program failed"); - exit(1); - } - } -} - static int merge_entry(int pos, const char *path) { int found; + const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL }; + char hexbuf[4][60]; + char ownbuf[4][60]; if (pos >= active_nr) die("git merge-index: %s not in the cache", path); - arguments[0] = pgm; - arguments[1] = ""; - arguments[2] = ""; - arguments[3] = ""; - arguments[4] = path; - arguments[5] = ""; - arguments[6] = ""; - arguments[7] = ""; - arguments[8] = NULL; found = 0; do { - static char hexbuf[4][60]; - static char ownbuf[4][60]; struct cache_entry *ce = active_cache[pos]; int stage = ce_stage(ce); @@ -55,7 +30,16 @@ static int merge_entry(int pos, const char *path) } while (++pos < active_nr); if (!found) die("git merge-index: %s not in the cache", path); - run_program(); + + if (run_command_v_opt(arguments, 0)) { + if (one_shot) + err++; + else { + if (!quiet) + die("merge program failed"); + exit(1); + } + } return found; } -- 2.26.2