Skip to content

Commit 6df58ff

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 c62014d commit 6df58ff

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
@@ -188,6 +188,26 @@ static int strip_prefix(LPWSTR str, int *len, LPCWSTR prefix)
188188
return 0;
189189
}
190190

191+
static void extract_first_arg(LPWSTR command_line, LPWSTR exepath, LPWSTR buf)
192+
{
193+
LPWSTR *wargv;
194+
int wargc;
195+
196+
wargv = CommandLineToArgvW(command_line, &wargc);
197+
if (wargc < 1) {
198+
fwprintf(stderr, L"Invalid command-line: '%s'\n", command_line);
199+
exit(1);
200+
}
201+
if (*wargv[0] == L'\\' ||
202+
(isalpha(*wargv[0]) && wargv[0][1] == L':'))
203+
wcscpy(buf, wargv[0]);
204+
else {
205+
wcscpy(buf, exepath);
206+
PathAppend(buf, wargv[0]);
207+
}
208+
LocalFree(wargv);
209+
}
210+
191211
static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
192212
LPWSTR *prefix_args, int *prefix_args_len,
193213
int *is_git_command, LPWSTR *working_directory, int *full_path,
@@ -268,20 +288,7 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
268288
atat[env_len - 1] = save;
269289
}
270290

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

286293
if (_waccess(exep, 0) != -1)
287294
break;

0 commit comments

Comments
 (0)