Simplify some instances of run_command() by using run_command_v_opt().
Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jun 8, 2009 at 22:34 UTC
0077138cd9d4f94636184553afd8b33b98d320a1
3 files changed
+18
-45
builtin-receive-pack.c
+3
-7
@@ -192,7 +192,6 @@ static int run_receive_hook(const char *hook_name)
192
static int run_update_hook(struct command *cmd)
193
{
194
static const char update_hook[] = "hooks/update";
195
- struct child_process proc;
195
const char *argv[5];
196
197
if (access(update_hook, X_OK) < 0)
@@ -204,12 +203,9 @@ static int run_update_hook(struct command *cmd)
203
argv[3] = sha1_to_hex(cmd->new_sha1);
204
argv[4] = NULL;
205
207
- memset(&proc, 0, sizeof(proc));
208
- proc.argv = argv;
209
- proc.no_stdin = 1;
210
- proc.stdout_to_stderr = 1;
211
-
212
- return hook_status(run_command(&proc), update_hook);
206
+ return hook_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
207
+ RUN_COMMAND_STDOUT_TO_STDERR),
208
+ update_hook);
209
}
210
211
static int is_ref_checked_out(const char *ref)
ll-merge.c
+2
-9
@@ -175,8 +175,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
175
{ "B", temp[2] },
176
{ NULL }
177
};
178
- struct child_process child;
179
- const char *args[20];
178
+ const char *args[] = { "sh", "-c", NULL, NULL };
179
int status, fd, i;
180
struct stat st;
181
@@ -191,14 +190,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
190
191
strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
192
194
- memset(&child, 0, sizeof(child));
195
- child.argv = args;
196
- args[0] = "sh";
197
- args[1] = "-c";
193
args[2] = cmd.buf;
199
- args[3] = NULL;
200
-
201
- status = run_command(&child);
194
+ status = run_command_v_opt(args, 0);
195
if (status < -ERR_RUN_COMMAND_FORK)
196
; /* failure in run-command */
197
else
merge-index.c
+13
-29
@@ -3,45 +3,20 @@
3
#include "exec_cmd.h"
4
5
static const char *pgm;
6
-static const char *arguments[9];
6
static int one_shot, quiet;
7
static int err;
8
10
-static void run_program(void)
11
-{
12
- struct child_process child;
13
- memset(&child, 0, sizeof(child));
14
- child.argv = arguments;
15
- if (run_command(&child)) {
16
- if (one_shot) {
17
- err++;
18
- } else {
19
- if (!quiet)
20
- die("merge program failed");
21
- exit(1);
22
- }
23
- }
24
-}
25
-
9
static int merge_entry(int pos, const char *path)
10
{
11
int found;
12
+ const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
13
+ char hexbuf[4][60];
14
+ char ownbuf[4][60];
15
16
if (pos >= active_nr)
17
die("git merge-index: %s not in the cache", path);
32
- arguments[0] = pgm;
33
- arguments[1] = "";
34
- arguments[2] = "";
35
- arguments[3] = "";
36
- arguments[4] = path;
37
- arguments[5] = "";
38
- arguments[6] = "";
39
- arguments[7] = "";
40
- arguments[8] = NULL;
18
found = 0;
19
do {
43
- static char hexbuf[4][60];
44
- static char ownbuf[4][60];
20
struct cache_entry *ce = active_cache[pos];
21
int stage = ce_stage(ce);
22
@@ -55,7 +30,16 @@ static int merge_entry(int pos, const char *path)
30
} while (++pos < active_nr);
31
if (!found)
32
die("git merge-index: %s not in the cache", path);
58
- run_program();
33
+
34
+ if (run_command_v_opt(arguments, 0)) {
35
+ if (one_shot)
36
+ err++;
37
+ else {
38
+ if (!quiet)
39
+ die("merge program failed");
40
+ exit(1);
41
+ }
42
+ }
43
return found;
44
}
45