Skip to content

Commit 615c4e0

Browse files
committed
mingw: take argv[0] from command line parameters
Instead of basing argv[0] on the executable path, use argv[0] as provided on the command line. Setting argv[0] to git-<builtin> is currently the only way to prevent git from falling back to calling a helper executable. This change will allow the git-wrapper executable, that Git for Windows uses, to signal to git to handle the command as a builtin. Related to git-for-windows#1496 Signed-off-by: Kim Gybels <[email protected]>
1 parent b2956b3 commit 615c4e0

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

compat/mingw.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,8 +3381,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
33813381
adjust_symlink_flags();
33823382

33833383
/* determine size of argv conversion buffer */
3384-
maxlen = wcslen(_wpgmptr);
3385-
for (k = 1; k < argc; k++)
3384+
maxlen = 0;
3385+
for (k = 0; k < argc; k++)
33863386
maxlen = max(maxlen, wcslen(w_argv[k]));
33873387

33883388
/* allocate buffer (wchar_t encodes to max 3 UTF-8 bytes) */
@@ -3396,8 +3396,7 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
33963396
*/
33973397
ALLOC_ARRAY(my_utf8_argv, argc + 1);
33983398
ALLOC_ARRAY(save, argc + 1);
3399-
save[0] = my_utf8_argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
3400-
for (k = 1; k < argc; k++)
3399+
for (k = 0; k < argc; k++)
34013400
save[k] = my_utf8_argv[k] = wcstoutfdup_startup(buffer, w_argv[k], maxlen);
34023401
save[k] = my_utf8_argv[k] = NULL;
34033402

@@ -3454,8 +3453,8 @@ void mingw_startup(void)
34543453
die_startup();
34553454

34563455
/* determine size of argv and environ conversion buffer */
3457-
maxlen = wcslen(_wpgmptr);
3458-
for (i = 1; i < argc; i++)
3456+
maxlen = 0;
3457+
for (i = 0; i < argc; i++)
34593458
maxlen = max(maxlen, wcslen(wargv[i]));
34603459
for (i = 0; wenv[i]; i++)
34613460
maxlen = max(maxlen, wcslen(wenv[i]));
@@ -3474,8 +3473,7 @@ void mingw_startup(void)
34743473
buffer = malloc_startup(maxlen);
34753474

34763475
/* convert command line arguments and environment to UTF-8 */
3477-
__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
3478-
for (i = 1; i < argc; i++)
3476+
for (i = 0; i < argc; i++)
34793477
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
34803478
for (i = 0; wenv[i]; i++)
34813479
environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);

0 commit comments

Comments
 (0)