Skip to content

Commit 8124d81

Browse files
mjcheethamdscho
authored andcommitted
scalar: add run_git_argv
Add ability to run Git commands for Scalar by passing a struct strvec rather than having to use varargs. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent 8710905 commit 8124d81

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

‎scalar.c‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,38 @@ static void setup_enlistment_directory(int argc, const char **argv,
8989

9090
static int git_retries = 3;
9191

92+
static int run_git_argv(const struct strvec *argv)
93+
{
94+
int res = 0, attempts;
95+
96+
for (attempts = 0, res = 1;
97+
res && attempts < git_retries;
98+
attempts++) {
99+
struct child_process cmd = CHILD_PROCESS_INIT;
100+
101+
cmd.git_cmd = 1;
102+
strvec_pushv(&cmd.args, argv->v);
103+
res = run_command(&cmd);
104+
}
105+
106+
return res;
107+
}
108+
92109
LAST_ARG_MUST_BE_NULL
93110
static int run_git(const char *arg, ...)
94111
{
95112
va_list args;
96113
const char *p;
97114
struct strvec argv = STRVEC_INIT;
98-
int res = 0, attempts;
115+
int res;
99116

100117
va_start(args, arg);
101118
strvec_push(&argv, arg);
102119
while ((p = va_arg(args, const char *)))
103120
strvec_push(&argv, p);
104121
va_end(args);
105122

106-
for (attempts = 0, res = 1;
107-
res && attempts < git_retries;
108-
attempts++) {
109-
struct child_process cmd = CHILD_PROCESS_INIT;
110-
111-
cmd.git_cmd = 1;
112-
strvec_pushv(&cmd.args, argv.v);
113-
res = run_command(&cmd);
114-
}
123+
res = run_git_argv(&argv);
115124

116125
strvec_clear(&argv);
117126
return res;

0 commit comments

Comments
 (0)