run-command API users: use strvec_push(), not argv construction

Change a pattern of hardcoding an "argv" array size, populating it and
assigning to the "argv" member of "struct child_process" to instead
use "strvec_push()" to add data to the "args" member.

As noted in the preceding commit this moves us further towards being
able to remove the "argv" member in a subsequent commit

These callers could have used strvec_pushl(), but moving to
strvec_push() makes the diff easier to read, and keeps the arguments
aligned as before.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2021-11-25 23:52:21 +01:00
committed by Junio C Hamano
parent 2b7098936c
commit 7f14609e29
6 changed files with 31 additions and 53 deletions

View File

@@ -326,22 +326,18 @@ static int run_access_hook(struct daemon_service *service, const char *dir,
{
struct child_process child = CHILD_PROCESS_INIT;
struct strbuf buf = STRBUF_INIT;
const char *argv[8];
const char **arg = argv;
char *eol;
int seen_errors = 0;
*arg++ = access_hook;
*arg++ = service->name;
*arg++ = path;
*arg++ = hi->hostname.buf;
*arg++ = get_canon_hostname(hi);
*arg++ = get_ip_address(hi);
*arg++ = hi->tcp_port.buf;
*arg = NULL;
strvec_push(&child.args, access_hook);
strvec_push(&child.args, service->name);
strvec_push(&child.args, path);
strvec_push(&child.args, hi->hostname.buf);
strvec_push(&child.args, get_canon_hostname(hi));
strvec_push(&child.args, get_ip_address(hi));
strvec_push(&child.args, hi->tcp_port.buf);
child.use_shell = 1;
child.argv = argv;
child.no_stdin = 1;
child.no_stderr = 1;
child.out = -1;