Skip to content

Commit 0077138

Browse files
j6tgitster
authored andcommitted
Simplify some instances of run_command() by using run_command_v_opt().
Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e169b97 commit 0077138

File tree

3 files changed

+18
-45
lines changed

3 files changed

+18
-45
lines changed

builtin-receive-pack.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ static int run_receive_hook(const char *hook_name)
192192
static int run_update_hook(struct command *cmd)
193193
{
194194
static const char update_hook[] = "hooks/update";
195-
struct child_process proc;
196195
const char *argv[5];
197196

198197
if (access(update_hook, X_OK) < 0)
@@ -204,12 +203,9 @@ static int run_update_hook(struct command *cmd)
204203
argv[3] = sha1_to_hex(cmd->new_sha1);
205204
argv[4] = NULL;
206205

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);
213209
}
214210

215211
static int is_ref_checked_out(const char *ref)

ll-merge.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
175175
{ "B", temp[2] },
176176
{ NULL }
177177
};
178-
struct child_process child;
179-
const char *args[20];
178+
const char *args[] = { "sh", "-c", NULL, NULL };
180179
int status, fd, i;
181180
struct stat st;
182181

@@ -191,14 +190,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
191190

192191
strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
193192

194-
memset(&child, 0, sizeof(child));
195-
child.argv = args;
196-
args[0] = "sh";
197-
args[1] = "-c";
198193
args[2] = cmd.buf;
199-
args[3] = NULL;
200-
201-
status = run_command(&child);
194+
status = run_command_v_opt(args, 0);
202195
if (status < -ERR_RUN_COMMAND_FORK)
203196
; /* failure in run-command */
204197
else

merge-index.c

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,20 @@
33
#include "exec_cmd.h"
44

55
static const char *pgm;
6-
static const char *arguments[9];
76
static int one_shot, quiet;
87
static int err;
98

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-
269
static int merge_entry(int pos, const char *path)
2710
{
2811
int found;
12+
const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
13+
char hexbuf[4][60];
14+
char ownbuf[4][60];
2915

3016
if (pos >= active_nr)
3117
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;
4118
found = 0;
4219
do {
43-
static char hexbuf[4][60];
44-
static char ownbuf[4][60];
4520
struct cache_entry *ce = active_cache[pos];
4621
int stage = ce_stage(ce);
4722

@@ -55,7 +30,16 @@ static int merge_entry(int pos, const char *path)
5530
} while (++pos < active_nr);
5631
if (!found)
5732
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+
}
5943
return found;
6044
}
6145

0 commit comments

Comments
 (0)