Skip to content

Commit 8bba470

Browse files
committed
git-wrapper: prepare to allow more options than MINIMAL_PATH
With the resource-driven command-line configuration, we introduced the option to ensure that only the PATH environment variable is edited only minimally, i.e. only /cmd/ is added (as appropriate for _Git CMD_). We are about to add another option, so let's refactor the equivalent of Git's `strip_prefix()` function; It is not *quite* the same because we have to `memmove()` the remainder to the beginning of the buffer. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 11f4738 commit 8bba470

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

compat/win32/git-wrapper.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,22 @@ static LPWSTR fixup_commandline(LPWSTR exepath, LPWSTR *exep, int *wait,
168168
return cmd;
169169
}
170170

171+
static int strip_prefix(LPWSTR str, int *len, LPCWSTR prefix)
172+
{
173+
LPWSTR start = str;
174+
do {
175+
if (str - start > *len)
176+
return 0;
177+
if (!*prefix) {
178+
*len -= str - start;
179+
memmove(start, str,
180+
sizeof(WCHAR) * (wcslen(str) + 1));
181+
return 1;
182+
}
183+
} while (*str++ == *prefix++);
184+
return 0;
185+
}
186+
171187
static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
172188
LPWSTR *prefix_args, int *prefix_args_len,
173189
int *is_git_command, LPWSTR *working_directory, int *full_path,
@@ -199,10 +215,11 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
199215
exit(1);
200216
}
201217

202-
if (!wcsncmp(L"MINIMAL_PATH=1 ", buf, 15)) {
203-
minimal_search_path = 1;
204-
memmove(buf, buf + 15,
205-
sizeof(WCHAR) * (wcslen(buf + 15) + 1));
218+
for (;;) {
219+
if (strip_prefix(buf, &len, L"MINIMAL_PATH=1 "))
220+
minimal_search_path = 1;
221+
else
222+
break;
206223
}
207224

208225
buf[len] = L'\0';

0 commit comments

Comments
 (0)