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 <gitster@pobox.com>
Junio C Hamano committed
Aug 26, 2020 at 15:25 UTC
afbdba391eaf3c473eff8f12437ff510935b520f
4 files changed
+7
-19
convert.c
+1
-4
@@ -638,7 +638,6 @@ static int filter_buffer_or_fd(int in, int out, void *data)
638
struct child_process child_process = CHILD_PROCESS_INIT;
639
struct filter_params *params = (struct filter_params *)data;
640
int write_err, status;
641
- const char *argv[] = { NULL, NULL };
641
642
/* apply % substitution to cmd */
643
struct strbuf cmd = STRBUF_INIT;
@@ -656,9 +655,7 @@ static int filter_buffer_or_fd(int in, int out, void *data)
655
strbuf_expand(&cmd, params->cmd, strbuf_expand_dict_cb, &dict);
656
strbuf_release(&path);
657
659
- argv[0] = cmd.buf;
660
-
661
- child_process.argv = argv;
658
+ strvec_push(&child_process.args, cmd.buf);
659
child_process.use_shell = 1;
660
child_process.in = -1;
661
child_process.out = out;
credential.c
+1
-3
@@ -274,11 +274,9 @@ static int run_credential_helper(struct credential *c,
274
int want_output)
275
{
276
struct child_process helper = CHILD_PROCESS_INIT;
277
- const char *argv[] = { NULL, NULL };
277
FILE *fp;
278
280
- argv[0] = cmd;
281
- helper.argv = argv;
279
+ strvec_push(&helper.args, cmd);
280
helper.use_shell = 1;
281
helper.in = -1;
282
if (want_output)
submodule.c
+4
-9
@@ -1726,14 +1726,6 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
1726
int submodule_uses_gitfile(const char *path)
1727
{
1728
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
- };
1729
struct strbuf buf = STRBUF_INIT;
1730
const char *git_dir;
1731
@@ -1746,7 +1738,10 @@ int submodule_uses_gitfile(const char *path)
1738
strbuf_release(&buf);
1739
1740
/* 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
+
1745
prepare_submodule_repo_env(&cp.env_array);
1746
cp.git_cmd = 1;
1747
cp.no_stdin = 1;
trailer.c
+1
-3
@@ -221,15 +221,13 @@ static char *apply_command(const char *command, const char *arg)
221
struct strbuf cmd = STRBUF_INIT;
222
struct strbuf buf = STRBUF_INIT;
223
struct child_process cp = CHILD_PROCESS_INIT;
224
- const char *argv[] = {NULL, NULL};
224
char *result;
225
226
strbuf_addstr(&cmd, command);
227
if (arg)
228
strbuf_replace(&cmd, TRAILER_ARG_STRING, arg);
229
231
- argv[0] = cmd.buf;
232
- cp.argv = argv;
230
+ strvec_push(&cp.args, cmd.buf);
231
cp.env = local_repo_env;
232
cp.no_stdin = 1;
233
cp.use_shell = 1;