Skip to content

Commit 2f10008

Browse files
committed
git wrapper: refactor extraction of 1st arg into its own function
This will be reused by the upcoming `--command=<command>` option. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 63aaec4 commit 2f10008

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

compat/win32/git-wrapper.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ static int strip_prefix(LPWSTR str, int *len, LPCWSTR prefix)
184184
return 0;
185185
}
186186

187+
static void extract_first_arg(LPWSTR command_line, LPWSTR exepath, LPWSTR buf)
188+
{
189+
LPWSTR *wargv;
190+
int wargc;
191+
192+
wargv = CommandLineToArgvW(command_line, &wargc);
193+
if (wargc < 1) {
194+
fwprintf(stderr, L"Invalid command-line: '%s'\n", command_line);
195+
exit(1);
196+
}
197+
if (*wargv[0] == L'\\' ||
198+
(isalpha(*wargv[0]) && wargv[0][1] == L':'))
199+
wcscpy(buf, wargv[0]);
200+
else {
201+
wcscpy(buf, exepath);
202+
PathAppend(buf, wargv[0]);
203+
}
204+
LocalFree(wargv);
205+
}
206+
187207
static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
188208
LPWSTR *prefix_args, int *prefix_args_len,
189209
int *is_git_command, LPWSTR *working_directory, int *full_path,
@@ -264,20 +284,7 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
264284
atat[env_len - 1] = save;
265285
}
266286

267-
/* parse first argument */
268-
wargv = CommandLineToArgvW(buf, &wargc);
269-
if (wargc < 1) {
270-
fwprintf(stderr, L"Invalid command-line: '%s'\n", buf);
271-
exit(1);
272-
}
273-
if (*wargv[0] == L'\\' ||
274-
(isalpha(*wargv[0]) && wargv[0][1] == L':'))
275-
wcscpy(exep, wargv[0]);
276-
else {
277-
wcscpy(exep, exepath);
278-
PathAppend(exep, wargv[0]);
279-
}
280-
LocalFree(wargv);
287+
extract_first_arg(buf, exepath, exep);
281288

282289
if (_waccess(exep, 0) != -1)
283290
break;

0 commit comments

Comments
 (0)