Skip to content

Commit afbdba3

Browse files
committed
run_command: teach API users to use embedded 'args' more
The child_process structure has an embedded strvec for formulating the command line argument list these days, but code that predates the wide use of it prepared a separate char *argv[] array and manually set the child_process.argv pointer point at it. Teach these old-style code to lose the separate argv[] array. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47ae905 commit afbdba3

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

convert.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ static int filter_buffer_or_fd(int in, int out, void *data)
638638
struct child_process child_process = CHILD_PROCESS_INIT;
639639
struct filter_params *params = (struct filter_params *)data;
640640
int write_err, status;
641-
const char *argv[] = { NULL, NULL };
642641

643642
/* apply % substitution to cmd */
644643
struct strbuf cmd = STRBUF_INIT;
@@ -656,9 +655,7 @@ static int filter_buffer_or_fd(int in, int out, void *data)
656655
strbuf_expand(&cmd, params->cmd, strbuf_expand_dict_cb, &dict);
657656
strbuf_release(&path);
658657

659-
argv[0] = cmd.buf;
660-
661-
child_process.argv = argv;
658+
strvec_push(&child_process.args, cmd.buf);
662659
child_process.use_shell = 1;
663660
child_process.in = -1;
664661
child_process.out = out;

credential.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,9 @@ static int run_credential_helper(struct credential *c,
274274
int want_output)
275275
{
276276
struct child_process helper = CHILD_PROCESS_INIT;
277-
const char *argv[] = { NULL, NULL };
278277
FILE *fp;
279278

280-
argv[0] = cmd;
281-
helper.argv = argv;
279+
strvec_push(&helper.args, cmd);
282280
helper.use_shell = 1;
283281
helper.in = -1;
284282
if (want_output)

submodule.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,14 +1726,6 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
17261726
int submodule_uses_gitfile(const char *path)
17271727
{
17281728
struct child_process cp = CHILD_PROCESS_INIT;
1729-
const char *argv[] = {
1730-
"submodule",
1731-
"foreach",
1732-
"--quiet",
1733-
"--recursive",
1734-
"test -f .git",
1735-
NULL,
1736-
};
17371729
struct strbuf buf = STRBUF_INIT;
17381730
const char *git_dir;
17391731

@@ -1746,7 +1738,10 @@ int submodule_uses_gitfile(const char *path)
17461738
strbuf_release(&buf);
17471739

17481740
/* Now test that all nested submodules use a gitfile too */
1749-
cp.argv = argv;
1741+
strvec_pushl(&cp.args,
1742+
"submodule", "foreach", "--quiet", "--recursive",
1743+
"test -f .git", NULL);
1744+
17501745
prepare_submodule_repo_env(&cp.env_array);
17511746
cp.git_cmd = 1;
17521747
cp.no_stdin = 1;

trailer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,13 @@ static char *apply_command(const char *command, const char *arg)
221221
struct strbuf cmd = STRBUF_INIT;
222222
struct strbuf buf = STRBUF_INIT;
223223
struct child_process cp = CHILD_PROCESS_INIT;
224-
const char *argv[] = {NULL, NULL};
225224
char *result;
226225

227226
strbuf_addstr(&cmd, command);
228227
if (arg)
229228
strbuf_replace(&cmd, TRAILER_ARG_STRING, arg);
230229

231-
argv[0] = cmd.buf;
232-
cp.argv = argv;
230+
strvec_push(&cp.args, cmd.buf);
233231
cp.env = local_repo_env;
234232
cp.no_stdin = 1;
235233
cp.use_shell = 1;

0 commit comments

Comments
 (0)