1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-05 10:36:11 +02:00
git/t/helper/test-fake-ssh.c
René Scharfe 4120294cbf use child_process member "args" instead of string array variable
Use run_command() with a struct child_process variable and populate its
"args" member directly instead of building a string array and passing it
to run_command_v_opt().  This avoids the use of magic index numbers and
makes simplifies the possible addition of more arguments in the future.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2022-10-30 14:04:39 -04:00

32 lines
818 B
C

#include "git-compat-util.h"
#include "run-command.h"
#include "strbuf.h"
int cmd_main(int argc, const char **argv)
{
const char *trash_directory = getenv("TRASH_DIRECTORY");
struct strbuf buf = STRBUF_INIT;
FILE *f;
int i;
struct child_process cmd = CHILD_PROCESS_INIT;
/* First, print all parameters into $TRASH_DIRECTORY/ssh-output */
if (!trash_directory)
die("Need a TRASH_DIRECTORY!");
strbuf_addf(&buf, "%s/ssh-output", trash_directory);
f = fopen(buf.buf, "w");
if (!f)
die("Could not write to %s", buf.buf);
for (i = 0; i < argc; i++)
fprintf(f, "%s%s", i > 0 ? " " : "", i > 0 ? argv[i] : "ssh:");
fprintf(f, "\n");
fclose(f);
/* Now, evaluate the *last* parameter */
if (argc < 2)
return 0;
cmd.use_shell = 1;
strvec_push(&cmd.args, argv[argc - 1]);
return run_command(&cmd);
}