Re: [PATCH 12/12] mingw: allow `git.exe` to be used instead of the "Git wrapper"

Junio C Hamano <[email protected]> Thu, 06 Aug 2026 10:26:49 -0700
Newsgroups org.kernel.vger.git
Message-ID <[email protected]>
"Johannes Schindelin via GitGitGadget" <[email protected]>
writes:

> @@ -3186,6 +3225,32 @@ static void setup_windows_environment(void)
>  			setenv("HOME", tmp, 1);
>  	}
>  
> +	if (!getenv("PLINK_PROTOCOL"))
> +		setenv("PLINK_PROTOCOL", "ssh", 0);
> +
> +#ifdef ENSURE_MSYSTEM_IS_SET
> +	if (!(tmp = getenv("MSYSTEM")) || !tmp[0]) {

Checking tmp[0] is a sign that we do not consider MSYSTEM set to an
empty string a sane state and ENSURE_MSYSTEM_IS_SET is about
correcting it, right?

> +		const char *home = getenv("HOME"), *path = getenv("PATH");
> +		char buf[32768];
> +		size_t off = 0;
> +
> +		setenv("MSYSTEM", ENSURE_MSYSTEM_IS_SET, 1);

In config.mak.uname, ENSURE_MSYSTEM_IS_SET is defined to "$(MSYSTEM)".

+	COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY \
+		-DENSURE_MSYSTEM_IS_SET="\"$(MSYSTEM)\"" -DMINGW_PREFIX="\"$(patsubst /%,%,$(MINGW_PREFIX))\"" \

Can $(MSYSTEM) be an empty string or undefined at the build time,
making ENSURE_MSYSTEM_IS_SET set to "" (two double-quotes)?  Which
would mean we are exporting MSYSTEM defined to be an empty string as
well with this setenv.

It seems ifeq($(uname_S),MINGW) side protects against this situation
by placing the cflags definition
	
+		COMPAT_CFLAGS += -DDETECT_MSYS_TTY \
+			-DENSURE_MSYSTEM_IS_SET="\"$(MSYSTEM)\"" \

inside "ifneq (,$(MSYSTEM))..endif".  That way, ENSURE_MSYSTEM_IS_SET
is not defined to "" (two double-quotes), so #ifdef ENSURE_MSYSTEM_IS_SET
would not kick in.