From patchwork Thu Jul 11 23:11:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13731178 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3DAE16D320 for ; Thu, 11 Jul 2024 23:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739502; cv=none; b=uwEpg6MjicUAoyDhBCO6WWcJVMmXcqKCEgBeTnnMLi6AfCiySZQYRRNvLtwmefRo69j4a0FFpZyvLMv+bo+aC/XDep3afiAP0O0ZrTSI0ML1WHfMF7pzlWgljDEVtXZXAz9+BmbGbzlPH7DE7GX2dM2kP2Fhz88o4PxcfMbskgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739502; c=relaxed/simple; bh=u8yaTDujhV2/Nu4OVUSQjQlDfgzdR329gA/H50m5rl8=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=YKrdbtMHcdXytE1wrvlqfF++zlGwNrpLjrtfBvoabcflmgziDHLVWKy0VPRgtwRm3XPer2/MkqG/ueSvEWXVPaG0eMpNH8miYMv831u8mXVCjObyys6o/uoCQiUcVPXt5WyxvsxddgAQ/2zxCkdCS4wwT2ILKqqzmm58lSUVVYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XVfFTtwM; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XVfFTtwM" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-367940c57ddso840722f8f.3 for ; Thu, 11 Jul 2024 16:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720739499; x=1721344299; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=CocVMwk0JIazwXWV9OwSdYVdQb6i/4AS+rSFmyyw4fI=; b=XVfFTtwMopt7vCa34kb6NOmFUVT0EZLj8+EyhVUzWaPTdJzGXDcScm8wxnsj6MTHTR 6GiVyds7tizuxePlM0N5FghbskBMBCtWoPIZJRNnz4M4jS3mz6BBtR2dDvo454HBGonM mwrZMufekFVK3W7mumAjGCLYagJYE+Agml9tjX1JLb4QaXTpX4RAAre9JTplfiXJQDu1 wyUoOrSTBhrLk3/9zV7JFgDzHjmYvz3rgvyx0Qco0ehnV4kYAt9PXhAwc+hCOFizJZaQ LSNEo66BVNqY9AvqS5zd5ozYzcFPzsvTsi+rKEKgmq60Y1LFJbpTBAqdAiiwOwY08RaM PXeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720739499; x=1721344299; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CocVMwk0JIazwXWV9OwSdYVdQb6i/4AS+rSFmyyw4fI=; b=IOdm8SdN0IN+mGH2uyY0sAjQ0RQM5tSziuh/cJ1k84c8kHHZIKe8//6gNELEFH34eb ydcneX28TJp1UhW2ONOecu5y3Srky4rCHrbUYaQmCmiyWRH7YABTPK+FCro03vqAUcVw vGEZGxoXZawIaEIXtdSd9rANiBypGiueeqaknqhN/JUz9/bFm+yQU9rQS+3VzSYIdF90 IbpkoY9diVoTmGUICLtOohpVeEX7ti7S+4e4MzYn2M4wm46ia5Prf1DhtWeikD3ifyi3 YTse/0ocU0H8BPZU1aQRsM7CunPHO9BW07zQmUQzQ06NX/9hwpV4IVEzOUvFvvawKl+8 djdA== X-Gm-Message-State: AOJu0YyRiRkqIUAJvjjF+FKCra3jDTaiGwswrX3LxLMXhy4FDI9hDRff R5ZOS1DSl1fBOUHuufb2fmVQ7RTFSYYIuhM1aRw5uex8c893Y/UqraFDGQ== X-Google-Smtp-Source: AGHT+IF2p/D5f5FGdYudJ9valiEKFEMndT7oHDT72iSp4LrzZjQ7Q0h44BTTSRCWB+J/2u8VvEAxyg== X-Received: by 2002:adf:e181:0:b0:368:517:5d07 with SMTP id ffacd0b85a97d-36805175e15mr44880f8f.28.1720739498747; Thu, 11 Jul 2024 16:11:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde848cfsm8790207f8f.37.2024.07.11.16.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 16:11:38 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 11 Jul 2024 23:11:30 +0000 Subject: [PATCH v2 1/7] run-command: refactor getting the Unix shell path into its own function Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Phillip Wood , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin This encapsulates the platform-specific logic better. Signed-off-by: Johannes Schindelin --- run-command.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/run-command.c b/run-command.c index d9f80fabe6e..59e433bf91c 100644 --- a/run-command.c +++ b/run-command.c @@ -274,17 +274,22 @@ int sane_execvp(const char *file, char * const argv[]) return -1; } +static const char *git_shell_path(void) +{ +#ifndef GIT_WINDOWS_NATIVE + return SHELL_PATH; +#else + return "sh"; +#endif +} + static const char **prepare_shell_cmd(struct strvec *out, const char **argv) { if (!argv[0]) BUG("shell command is empty"); if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { -#ifndef GIT_WINDOWS_NATIVE - strvec_push(out, SHELL_PATH); -#else - strvec_push(out, "sh"); -#endif + strvec_push(out, git_shell_path()); strvec_push(out, "-c"); /* From patchwork Thu Jul 11 23:11:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13731179 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A2141A0737 for ; Thu, 11 Jul 2024 23:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739504; cv=none; b=uN3T2+C12Qq9CimOuVhNumTH+9UtL5NwUvrQWOoKDWI2+lUHUxllKkgGgeD7kXrnzEmP+xdVQyfwOCrST4/Gp27Oid7opRp0DJTKMxUE1IEmdZSOz22Ed6aa+2ieNPKYRQk6HIaYajuA10MtjbhIs4RXd6bJeFvniuRcMOs5rtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739504; c=relaxed/simple; bh=MIwsxKQCc6L1ypFrSWOoIhAUtc7BOba8IDgNM12CZxk=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=uPuCdXG/qKpem5qlX3a5UIhXRm0D871hoGRUFkYj2JEt4M9Hwgnapf0LAbrjfLfh/TOPjqONiDKc/doDK0aCUoV4qqNq7WfsySba4V3Sp3t2rPELui6hSQ+FkJQ36VQRMhO9gAbG33CbHIPjfFEZuCRHxdf+hVKrUCgfCU3BJ2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ouy2BSYt; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ouy2BSYt" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2eaafda3b5cso12940101fa.3 for ; Thu, 11 Jul 2024 16:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720739499; x=1721344299; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=MpbfQ6cIUNHUjgSnKnj7SnzmfwlwJBl0mHg3GxACDxI=; b=Ouy2BSYtyaCeszQBg6hzV8FOH+Pr2R39Lb3FUXQWJdyZiyUHCC31a7pZmuQdaSh8uW YmXye2cRusb6mP3DAlT12I4PoImlJ6bNeJfVf/xCW4+MfmJJ6uE8pQncDMZZT0dTuH37 IlC5KmFkUeNHOobyMpxP3dH03x7XESeqzpDno3fLWRmRGmlPMhtW1pOESIRUAgVyqPw4 pwZzSkXgP9QRETOoEKTNDXRZjAXUc0PnGGy69qRHQRnXpJpsjnkzxjJDwMMOAk+F1Pxk x49HbSVQuP6ifckPQD7g46C+Np25dAL7p6IEhueQ5sUdVRD7fFUy8YBHyg1cIDcy2O5F Pbzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720739499; x=1721344299; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MpbfQ6cIUNHUjgSnKnj7SnzmfwlwJBl0mHg3GxACDxI=; b=Cm3MHQ5Mivkl8oybeinYOYJz/GiIOywYxNPHAiJIHItCKMAq7tC2QdcIlUYzN7SFap eITC1ghZ6eRqtnYvj5t/aiRSoElZk3klmiMlyzcjPE/Xig7US53niA0waU+Ru7KydTqL YQKLfBuFL6on5dfr6jVt689XRM4cMy2H+LX0wAf/r6qoztpTkzG48id45j65vvSGDbRY HmcEAaaVMjOzZMxqeoRpLQEbsz4k8HUj4Z1H4Sn6AuDiBjFHwYJRgwkx3um+cvsTu4Ag qaysa/OAFT7bcUABPBhaGgkVqfPeyKSfgNSua2kG1IuJs4BFXIpRY412Pn4l0ZbxASYI GWPw== X-Gm-Message-State: AOJu0YwRMPg56aHTNSJNHA9N0EIDf8xH4IIdS7cIs9ltBdgRX/YHdIb4 NDoezMvVYGW23+ma5oUS7Cxa07yt5lbC3G1/goFj4vbrHXh07Mf4aBj38Q== X-Google-Smtp-Source: AGHT+IEr64iGWMRkOznB3n5fj0jowARfmYLuSmlpfZ4Ro0fke/mABjLzrJJgcegVLuOUkaJLPxxsJw== X-Received: by 2002:a2e:8e92:0:b0:2ec:68d9:f3d2 with SMTP id 38308e7fff4ca-2eeb30dbdf9mr59700911fa.20.1720739499448; Thu, 11 Jul 2024 16:11:39 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f25babbsm3381565e9.20.2024.07.11.16.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 16:11:39 -0700 (PDT) Message-Id: <91ebccbc39f21fa73af8bc8c81af721f1ca201bd.1720739496.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 11 Jul 2024 23:11:31 +0000 Subject: [PATCH v2 2/7] strvec: declare the `strvec_push_nodup()` function globally Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Phillip Wood , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin This function differs from `strvec_push()` in that it takes ownership of the allocated string that is passed as second argument. This is useful when appending elements to the string array that have been freshly allocated and serve no further other purpose after that. Without declaring this function globally, call sites would allocate the memory, only to have `strvec_push()` duplicate the string, and then the first copy would need to be released. Having this function globally avoids that kind of unnecessary work. Signed-off-by: Johannes Schindelin --- strvec.c | 2 +- strvec.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/strvec.c b/strvec.c index d4073ec9fa2..f712070f574 100644 --- a/strvec.c +++ b/strvec.c @@ -10,7 +10,7 @@ void strvec_init(struct strvec *array) memcpy(array, &blank, sizeof(*array)); } -static void strvec_push_nodup(struct strvec *array, const char *value) +void strvec_push_nodup(struct strvec *array, char *value) { if (array->v == empty_strvec) array->v = NULL; diff --git a/strvec.h b/strvec.h index 6c7e8b7d503..4b73c1f092e 100644 --- a/strvec.h +++ b/strvec.h @@ -46,6 +46,9 @@ void strvec_init(struct strvec *); /* Push a copy of a string onto the end of the array. */ const char *strvec_push(struct strvec *, const char *); +/* Push an allocated string onto the end of the array, taking ownership. */ +void strvec_push_nodup(struct strvec *array, char *value); + /** * Format a string and push it onto the end of the array. This is a * convenience wrapper combining `strbuf_addf` and `strvec_push`. From patchwork Thu Jul 11 23:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13731180 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 105F61A08B6 for ; Thu, 11 Jul 2024 23:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739504; cv=none; b=ZaMMqVSkegM6K5k8oE3nQ9CTVKfYXkIawxQqr73PUi6Owsi79MLA8nbnJMrjskz1BHkxyys8KJVzEi3FDCBkWks2m6OG4wYhVqAFlrHn2PonJritBjKmgKOrQvxiWosFZ/PMqcadjlcIV8izZrhfz0NWBR93yKZnXFL7TCDiGMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739504; c=relaxed/simple; bh=R97B9Uf9PS7uc3AFFl7mnsI6myd/ued3PxgFtgachbM=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=MkIZBOppYduJrGcq4qmHbuaVW1LMxBFk0CpAcUoSWBibOHVBTEcfPAdvPwS8VyJgUK8N3J4ecCQZOp+55dvuIFzxBQbzpQ6agubS8N4QBqDnHJ8LLC16XVCRfH9+FYync+Pz2Ot5AW/lk0aulpD5CRVK9q26BjrkTFXfxxiRyiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SV/rinvI; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SV/rinvI" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-367993463b8so800181f8f.2 for ; Thu, 11 Jul 2024 16:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720739501; x=1721344301; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=HkwX2PpzjRQ24nxrS0sZ+WTECEKRNLzB7B2VnM4hk34=; b=SV/rinvIQDgwGCcgHbocob5WhjrDMwMgBNPPSRtJn66ppVkV55EKuiDT+OZ5Lg70+V vNz2td9R+YE4vggDRKv0N5VntUSnfMPbNe6VxxiAmRRLdLx562vqtFTaATvEqRQaf/Z+ etQIivo7YjY6uTi5rG0MVmB0tB1lTCnrdXgXU2MVXu5marGf5LOjgwAsfvx6K8NNdjLj 7jr/yRzYQHvo4v/hfUha1DdtwBSyn3RyF5rwjXn+0VvqLNgohn6pDXLtOQvI5tcjGfOx vfvML5AVi5QVGcmLJ0SxOWE2sKcw3oY0qjddQJG37fIyOt4tszL4WIbaEfeeosSLhkmI opFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720739501; x=1721344301; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HkwX2PpzjRQ24nxrS0sZ+WTECEKRNLzB7B2VnM4hk34=; b=ehe9WQkApOU+W8KvZ2Z+J3UHJGmtF3wGkGv3Mhx8mlUtGiSedmWdktqxKFXUeVkK0g 8wG4z9LFQ/ygFZSviq3NCYczCCtzn44AocrO/IKfDG4nZbdQcjfc9W7+UYTx4yMKZIWf B5+bDwVnWrdBwOmLV/Dcfn+ybzsMrvR++uVxTSzOvUG/7B0eeS+X9ql4NrweoxSClLjS gFJuOH1PVJpXN4oMO7PCfTRGa+eeUNBC66cJh9JpaVqqpYFdW9dCEb0MlVGauqem5tgP yq5NRqMMmDOkhY6Vnc7+7frphehyoIDTQAU0farp/Iaj6crgPcYc98zosYdZ3PdRdGe4 TNdg== X-Gm-Message-State: AOJu0YwpZDI0BgzYp9ooet3Py9yS1tsk2JNTMcgRaYuhEGPunC/todmI aBl+e6k6AODIM6MS5avo5PHeZe7WdkccsOFXzdBoQu9IzycZfHDVSwFTvw== X-Google-Smtp-Source: AGHT+IERKa5/px7NONHdJWLe/aP1K2tinnLCA/8/D3fuRNvB/Js7/sZsb8It5fEy8J1He2+31aoVWw== X-Received: by 2002:adf:f649:0:b0:367:434f:caa2 with SMTP id ffacd0b85a97d-367ce5ded5bmr6884236f8f.0.1720739501130; Thu, 11 Jul 2024 16:11:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36802d3f680sm334645f8f.33.2024.07.11.16.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 16:11:39 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 11 Jul 2024 23:11:32 +0000 Subject: [PATCH v2 3/7] win32: override `fspathcmp()` with a directory separator-aware version Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Phillip Wood , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin On Windows, the backslash is the directory separator, even if the forward slash can be used, too, at least since Windows NT. This means that the paths `a/b` and `a\b` are equivalent, and `fspathcmp()` needs to be made aware of that fact. Signed-off-by: Johannes Schindelin --- compat/win32/path-utils.c | 25 +++++++++++++++++++++++++ compat/win32/path-utils.h | 2 ++ dir.c | 2 +- dir.h | 2 +- git-compat-util.h | 5 +++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/compat/win32/path-utils.c b/compat/win32/path-utils.c index ebf2f12eb66..af7ef957bbf 100644 --- a/compat/win32/path-utils.c +++ b/compat/win32/path-utils.c @@ -50,3 +50,28 @@ int win32_offset_1st_component(const char *path) return pos + is_dir_sep(*pos) - path; } + +int win32_fspathcmp(const char *a, const char *b) +{ + int diff; + + for (;;) { + if (!*a) + return !*b ? 0 : -1; + if (!*b) + return +1; + + if (is_dir_sep(*a)) { + if (!is_dir_sep(*b)) + return -1; + a++; + b++; + continue; + } else if (is_dir_sep(*b)) + return +1; + + diff = (unsigned char)tolower(*(a++)) - (unsigned char)tolower(*(b++)); + if (diff) + return diff; + } +} diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h index 65fa3b9263a..e3c2a79df74 100644 --- a/compat/win32/path-utils.h +++ b/compat/win32/path-utils.h @@ -29,5 +29,7 @@ static inline int win32_has_dir_sep(const char *path) #define has_dir_sep(path) win32_has_dir_sep(path) int win32_offset_1st_component(const char *path); #define offset_1st_component win32_offset_1st_component +int win32_fspathcmp(const char *a, const char *b); +#define fspathcmp win32_fspathcmp #endif diff --git a/dir.c b/dir.c index b7a6625ebda..37d8e266b2c 100644 --- a/dir.c +++ b/dir.c @@ -95,7 +95,7 @@ int count_slashes(const char *s) return cnt; } -int fspathcmp(const char *a, const char *b) +int git_fspathcmp(const char *a, const char *b) { return ignore_case ? strcasecmp(a, b) : strcmp(a, b); } diff --git a/dir.h b/dir.h index 69a76d8bdd3..947e3d77442 100644 --- a/dir.h +++ b/dir.h @@ -541,7 +541,7 @@ int remove_dir_recursively(struct strbuf *path, int flag); */ int remove_path(const char *path); -int fspathcmp(const char *a, const char *b); +int git_fspathcmp(const char *a, const char *b); int fspatheq(const char *a, const char *b); int fspathncmp(const char *a, const char *b, size_t count); unsigned int fspathhash(const char *str); diff --git a/git-compat-util.h b/git-compat-util.h index ca7678a379d..ac564a68987 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -506,6 +506,11 @@ static inline int git_offset_1st_component(const char *path) #define offset_1st_component git_offset_1st_component #endif + +#ifndef fspathcmp +#define fspathcmp git_fspathcmp +#endif + #ifndef is_valid_path #define is_valid_path(path) 1 #endif From patchwork Thu Jul 11 23:11:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13731181 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 367C01A08DA for ; Thu, 11 Jul 2024 23:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739505; cv=none; b=PNF2kdlwbwwlw0QLk94pqc/muIIK7cV8c1eDNaSFr+p7pvzO8Hf5I+jfrh3p6zdh2Tr9m43oofOuAv7/xJ+oKE4yyEMEE5TVnlV51jN7/GtSCQAj54frMtX6AMZg0rRoRzAMvdoS5Kz2Ero6J1pkvvWwaX3MdCiw9xMmlOJ6Kr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739505; c=relaxed/simple; bh=X4hE+H8Z1mDrZwOiKzXK0l++3FlajlA8Z1GvV7ZqIAg=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=hj0oCCLgHbrAT0XeLjU0yRrUxQUdbeC0Y6WEtmb56/mBhDuQ4UXlgxOsD2eGjGe8Nr0+9/RIR9aatmIaqJhnWLPB9n/IcOnzv7BQTqtFrdC2Co6cwsTgoptX5PjC4WX/T7zH8N27GgtGqzbdWoCXSCU6Oa5a+KbyL6MmcTQ/J00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C5I4q8lJ; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C5I4q8lJ" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3679df4cb4cso925398f8f.0 for ; Thu, 11 Jul 2024 16:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720739502; x=1721344302; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=mCqo5imxUdi2MwtXOaJpLZGB4nbapaxdZRNCFgMicOY=; b=C5I4q8lJXbo+tQDGkPpIO1fnf1+6f6kpRget/cAOqI8U0fTLauRJ+dHOdjOGWKk7gS LchdG5c0MBvx3lWKWYGhRuWZUN7SKZX6VPYa2OVbQXdJYQlaoe9eo1nKiR848J5ZtyCM L7AwLvyYHfVZrUGjFxv3d2QdMm2PhTPDW6fISV4v6DhGfAkBNH0XYOOh32Z+pWLOFAyo hXVUHCPeyhTtomcMVjf8tm2OZJUvvH1U6aZwLpvhxm1lEXtkfaV0RVy9rLmHlFR1orrR RKs9Yxovxn4wdCpOgNWaqpdPDUMI+QoSj0ond5BzuN/jeWLKEs6wJVNVIArO5+quvHqW vUCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720739502; x=1721344302; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mCqo5imxUdi2MwtXOaJpLZGB4nbapaxdZRNCFgMicOY=; b=tRdOfESF9jW2l+nmUpDML9zpJPfklxOGOHPkUW2a8WFP+WfIY7yLd8BfwhtFSm62CL mFchUOghEmETnxy7+GH7CJOF8tljzyAHGHfeC8ApGLNkgCaGJLS4Lw5dKk8YGr7VHtNh LUi6453dhogR6I8veBkADKXI7MsitzLv//AnvWKleorRzK8/q4TNITBjhEnR7X9ZcL9N /IBGYAtLIS+JzS/5zE4jVoBzucdCikvS/pZYD6i3f7UM3TAZvPEABt1xof6MY0L+vmHi BvkQG1P0Q9v/IbS4QjYaByqwMLBVMF4DIJf5x1dW4CR5phuX7Lbw7IEkBmcDGQ+PPCWU oseg== X-Gm-Message-State: AOJu0YwVsoTgzvAZkVzsI/NPUGAKzMisjHmB3BL9zVlJfZ2a40X/HwVI ozYKmUz9pQ7XJV57TwnMGRd5RrChO/o2aQtaTOUQmHhsCX3bJDgpZCwmbQ== X-Google-Smtp-Source: AGHT+IFvBbH0iL0o6RPBq9lrTWh7wo3jJPthtLpBj8ne1hyQqeM28UdsGJ+8C7ed0qbRbedjtpJthw== X-Received: by 2002:adf:e9c8:0:b0:35f:314a:229c with SMTP id ffacd0b85a97d-36804fd655bmr63760f8f.28.1720739502194; Thu, 11 Jul 2024 16:11:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cdfab80asm8773628f8f.109.2024.07.11.16.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 16:11:41 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 11 Jul 2024 23:11:33 +0000 Subject: [PATCH v2 4/7] mingw(is_msys2_sh): handle forward slashes in the `sh.exe` path, too Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Phillip Wood , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin Whether the full path to the MSYS2 Bash is specified using backslashes or forward slashes, in either case the command-line arguments need to be quoted in the MSYS2-specific manner instead of using regular Win32 command-line quoting rules. In preparation for `prepare_shell_cmd()` to use the full path to `sh.exe` (with forward slashes for consistency), let's teach the `is_msys2_sh()` function about this; Otherwise 5580.4 'clone with backslashed path' would fail once `prepare_shell_cmd()` uses the full path instead of merely `sh`. This patch relies on the just-introduced fix where `fspathcmp()` handles backslashes and forward slashes as equivalent on Windows. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index 6097b8f9e60..29d3f09768c 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1546,7 +1546,7 @@ static int is_msys2_sh(const char *cmd) return ret; } - if (ends_with(cmd, "\\sh.exe")) { + if (ends_with(cmd, "\\sh.exe") || ends_with(cmd, "/sh.exe")) { static char *sh; if (!sh) From patchwork Thu Jul 11 23:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13731182 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 688E61A0B13 for ; Thu, 11 Jul 2024 23:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739507; cv=none; b=d7U5MIGoKvoDDNXIGVfT+m8eBOIkonHiauuaVbvamSU3fRSrcrxtfXxMzJzvgrGuWpLLk4a3AspiqHe+xGvX9tlRm68NMQPIwFLJfmRyVhpT4mypOBwy3yJlSFVlybl4ajQnFy2NClgEAObl4CfSlrh5Tr3faD4y6ejAvDhtmiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739507; c=relaxed/simple; bh=Zn6Q79lF4XV6seukFGYGo0mSUEYlc/kiG1ZjPcbLdcs=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ub+JG0/i6tY5MAMRp1MhWGiGyaBeKD2f1fQQAKsm4WKhSSsyNXEbeWQV/dEOLUQVTELGsMrYnMAMkaLLUg6e59MTOKGO8QtwZwLhdGIexeJuwVZw5WpMBiSn+FdWBS7rd6BRz35/UDTo0eXDLbccbftNvwkXJsd86kl3seFRvNw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S9oyJSqE; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S9oyJSqE" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4266fd39527so10407535e9.1 for ; Thu, 11 Jul 2024 16:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720739503; x=1721344303; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=pKJhnuUlrb2EY3P+9i3X5QJfDX5c5R6ixjlHNz1mdSA=; b=S9oyJSqEUJ+S7vOXmrf1PqVx70wNhxNSs6btnFLG738tDytoZK1hNOeJzhuP7O4Dj1 B+5A7rMz4tvscGsHw9UCioiWXumd6IrtKvk0eEXFnIO0CZ8FbPPD4qGz9gdYyAb1Tk1I 1jyGlRG4QySNqSMkoXyE4RCKNxnGHc5ICA3l1Aymb9qc0zGLVS0pnnYXPf4AekspDlgP MCPuwpFuf3QmLYShzrWlwhmLTtTN6HZjTEIWWedMfBS8kM0UIjHmwBE5BA1ZwaqL0Nc6 xQCErZeeQynIdlKUHIAh6RWiGc+v09vtuRnrJWkwe6DbZgHzBaVT7Blp6AR31MMsm2rt fUhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720739503; x=1721344303; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pKJhnuUlrb2EY3P+9i3X5QJfDX5c5R6ixjlHNz1mdSA=; b=uOE1nINRDw4334C8gRU8wVwe7t2l6kzqI6NI7p5IYF3aiS1aRi/3pVI3SMtS1jwmsP FOkkGn5aRjXVAxhXLCtzxNB/eiRRVJlP0eUGDgHPbtbJEcOh+Vd3P/yiKwI3CecHmOje f1Uet19pBG/gEOGpDtEJdDpezSQiaTczJniV3FYZQb1m74+IRK0t6wYizfZrQbR0rGty AZ100kSLddfmXwOVSc/011w1uEYhK/RgaIdqLlMPZ8lfHAoU86ZWbsIF7TZCtW0AFAeP w8c1lM0DwyPJDiOgLij9xpEoSmlM+WelOlUWu9tcIpEWdSROPb+8AmslRDqpOgLi9IGG Tbzw== X-Gm-Message-State: AOJu0YzaowNcsBI8sw/USubMijzzxBY4Xn6+Ic+WFJncN9tTxdz57Uda 6aWNgjhmW3dAAq8sJ/YD9h63mpgN5VE6IvAd343t8cZC6iT0P47ANO8aHw== X-Google-Smtp-Source: AGHT+IGGazqBoPgq+d6UE+X5v0tcguU8e1Lwgr4Vk5T1nmHqghm38Bj5DXiwFCwry/3zuBVxmMgJuw== X-Received: by 2002:a7b:cbd5:0:b0:426:5585:931f with SMTP id 5b1f17b1804b1-426707cac04mr69027925e9.10.1720739503322; Thu, 11 Jul 2024 16:11:43 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cdfa0689sm8804385f8f.85.2024.07.11.16.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 16:11:42 -0700 (PDT) Message-Id: <707daf246bd74f05428fc95c5b84b4836b06c648.1720739496.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 11 Jul 2024 23:11:34 +0000 Subject: [PATCH v2 5/7] run-command(win32): resolve the path to the Unix shell early Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Phillip Wood , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin In 776297548e (Do not use SHELL_PATH from build system in prepare_shell_cmd on Windows, 2012-04-17), the hard-coded path to the Unix shell was replaced by passing `sh` instead when executing Unix shell scripts in Git. This was done because the hard-coded path to the Unix shell is incorrect on Windows because it not only is a Unix-style absolute path instead of a Windows one, but Git uses the runtime prefix feature on Windows, i.e. the correct path cannot be hard-coded. Naturally, the `sh` argument will be resolved to the full path of said executable eventually. To help fixing the bug where `git var GIT_SHELL_PATH` currently does not reflect that logic, but shows that incorrect hard-coded Unix-style absolute path, let's resolve the full path to the `sh` executable early in the `git_shell_path()` function so that we can use it in `git var`, too, and be sure that the output is equivalent to what `run_command()` does when it is asked to execute a command-line using a Unix shell. Signed-off-by: Johannes Schindelin --- run-command.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/run-command.c b/run-command.c index 59e433bf91c..60a79db8f0e 100644 --- a/run-command.c +++ b/run-command.c @@ -274,12 +274,14 @@ int sane_execvp(const char *file, char * const argv[]) return -1; } -static const char *git_shell_path(void) +static char *git_shell_path(void) { #ifndef GIT_WINDOWS_NATIVE - return SHELL_PATH; + return xstrdup(SHELL_PATH); #else - return "sh"; + char *p = locate_in_PATH("sh"); + convert_slashes(p); + return p; #endif } @@ -289,7 +291,7 @@ static const char **prepare_shell_cmd(struct strvec *out, const char **argv) BUG("shell command is empty"); if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { - strvec_push(out, git_shell_path()); + strvec_push_nodup(out, git_shell_path()); strvec_push(out, "-c"); /* From patchwork Thu Jul 11 23:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13731183 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6814E1A254C for ; Thu, 11 Jul 2024 23:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739508; cv=none; b=Wt0brzb8d6UQMf07c6Avy4bQF826vcQPKEDJ4/vObgoQdPsHkYRCbcZtw/FNbsMwtArdI2n/1U37/yGhK9JkqHPD2A2ith9JLIiehlo4d5WaCbC9p4alhkxo40oC0qN3PzITziHskC8ZCMBkwmzHbLdhJ7H6I3P8Ao/ZbZcXHVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739508; c=relaxed/simple; bh=wGI/u536ygogFWY5DiujXv3jyD5Cg7FCZEx8VWytJyU=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=G2xH9ovUKsRCQ33pMvY9Jh2kW+lh81EMcwkK7dR9HJfrhZSyiRRjP+jL+H18LV5nsmdLl7p46KtN4fu8AGerPn8BxoVPcQ/oSYADmyoxcsa0QY08l6Pgem4yRqp/ZzqUObYm4yI7xSvCF78P0TPAW3HySoIN0rL4snONY0mp20k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JLflORXs; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JLflORXs" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-367a081d1cdso734659f8f.1 for ; Thu, 11 Jul 2024 16:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720739504; x=1721344304; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=pKBFxlpxtqw+lcKlQZcVepA2RqMBX87eNLI9J5v2lpI=; b=JLflORXsopr1Wh76maomSK44dPGw5wMNw2mC3jVHNIrWSroQlxjjyx6ezFkHp7wVO/ s/4M0z85UkMi+poj7lADZWyAp3pOuF+k6ykzYPktCrYFjjXVrAki6OT4jXrSRITmxV/j uFqJofbvKq7LTmklUEwh7dKOpSSTUPfPrVehC0wp7vUKLXs2EhvjKDMQOCNXRNkpmT1g QvJ/JU8iLYC6v6V+pn9qgznflnuk6L3Uv6OSqDwVRhcoEM859iHHUg8THYVpnJnF+kxL n2U1kjZx9i3SQL6ibLK4Mc2Xro+7da/DhkCY3l7QrS6hvP9+D6zc4okUL8wkYeefqPdC PZJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720739504; x=1721344304; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pKBFxlpxtqw+lcKlQZcVepA2RqMBX87eNLI9J5v2lpI=; b=vjOfSiooMqdLPX6Ts8O0HRB7eO9Cq10I34RtvTPYeaY5mQD6Q1W940IgYdhabF4Q4r sgPvSD8hAxKKnyTgak+pffUU9eErPLcWQbG5zd93P51RvdhD1IZjcNPHPAO44zzJNaW7 rLtnfurzAdW6a/ksxK94JGxC5C47Gtcrnf2dpOshzhbqYJKZ6/8uz18cCIfbFEYOAw+J n1WTT1DhXWB5/upV/VtrQMeLVjJumOxeciFYOxmT19GIv95dCAqZL0RNGoOP6tUhxH2h fiZsGHYwDKsyZm/xjrXpVF9SmV4h6cz2fR4IS3a3PxnMiNlXMWjTxMunepBwvZJGidbv AotA== X-Gm-Message-State: AOJu0YzezB2mnFj8W85lx+f1rL8GjLDAwsKMzOg1k924DMU0Kt50aiEK 7nNXcRpVX+fZY7/FT+aHWKtAeY01IIWYf9XkBoOwnacLpyhLw1WWDsWErg== X-Google-Smtp-Source: AGHT+IF8HjJOiMpLpVjk40EL5Qv7GTbD0jh+b1g0EHT0JBLmyqp1UU2cZaItrMokrH8VOvWy76x6gg== X-Received: by 2002:a5d:4ac5:0:b0:367:9792:8bd4 with SMTP id ffacd0b85a97d-367ceac4988mr6213796f8f.43.1720739504400; Thu, 11 Jul 2024 16:11:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde7ed52sm8958450f8f.6.2024.07.11.16.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 16:11:43 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 11 Jul 2024 23:11:35 +0000 Subject: [PATCH v2 6/7] run-command: declare the `git_shell_path()` function globally Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Phillip Wood , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The intention is to use it in `git var GIT_SHELL_PATH`, therefore we need this function to stop being file-local only. Signed-off-by: Johannes Schindelin --- run-command.c | 2 +- run-command.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/run-command.c b/run-command.c index 60a79db8f0e..45ba5449323 100644 --- a/run-command.c +++ b/run-command.c @@ -274,7 +274,7 @@ int sane_execvp(const char *file, char * const argv[]) return -1; } -static char *git_shell_path(void) +char *git_shell_path(void) { #ifndef GIT_WINDOWS_NATIVE return xstrdup(SHELL_PATH); diff --git a/run-command.h b/run-command.h index 55f6631a2aa..03e7222d8b5 100644 --- a/run-command.h +++ b/run-command.h @@ -195,6 +195,11 @@ int is_executable(const char *name); */ int exists_in_PATH(const char *command); +/** + * Return the path that is used to execute Unix shell command-lines. + */ +char *git_shell_path(void); + /** * Start a sub-process. Takes a pointer to a `struct child_process` * that specifies the details and returns pipe FDs (if requested). From patchwork Thu Jul 11 23:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13731184 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C0D21A2566 for ; Thu, 11 Jul 2024 23:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739510; cv=none; b=P6gmXSbikO9zp7C6y2DItWwcuRfJBsyHDeFK9+tMRiwKhdgoK45yYJ295eWMwxM9HoF6+WTSheqJp4+a5oYQaR7EnTpU9FxkNCsGZOG4zuXLqRfQ1tsGqKAUVAs/Fu2JJRpIa2G6EwXK1Use2zb1cvxR/SsHXJ8rHiBVqCSrN2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720739510; c=relaxed/simple; bh=vPT+TOEiMe/bjQeQ0jCb6acz4GYnr54LsJHfh1fhtc4=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=DeDIQkC3k84dD0BNH35LcLhNwwX3bp+a3UN8kwBjB3Pfk6M68PK3MEau42cueHpYN8NtXeT/EPerLcWiQK3Gt26X0SHUrguYGvUqqnrWWqCx822SZ3s+7p4JmqYuz+mI2aqhAeANhWBkN0REIkp7/ofxwFIuhqnoUKBggAN0ID4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=htCMcIgy; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="htCMcIgy" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2eeb2d60efbso16685301fa.1 for ; Thu, 11 Jul 2024 16:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720739506; x=1721344306; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=dkJwz/YY+MwgxQ1TrFALyw+kqQQqMj4QPMpSB0JQrS4=; b=htCMcIgyzMcCaaoPp751YJy0c+R/eAxRf8anx59drTVLLj9Mn4A+b9Re1mTEeZbvsA /SVD0KfH+KqxUZilSrN+8m5nv0GVC5+laG/lvG84aq15nFzKnGroMEzSSAdoV3UAoExs WqL9AkN5vQvB5ir8tQV932qKxPLY61722eoG+iNCb0bNTob5wDrHKqzvkqhhU8msKybx atmFlwL6nVOg0bs5iKgpyEEedGj6FFRFfTBsPCuqM0N/smxODrWK7MjOQ5wlmymPyYTq ScXBt2veyV+hpBIqlVV0i+CE/4IynMjk9aRv76OILQJ+2VeflN0HMHytrH673gThzGa2 zIbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720739506; x=1721344306; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dkJwz/YY+MwgxQ1TrFALyw+kqQQqMj4QPMpSB0JQrS4=; b=oxIQVbb7EXnxE02H1w0AUSbtQyD82H1tixA23o1CZExipXHbarirsMFCyheSK5ZxWw qkKz1pRWNc8C+uCgeOUKsTSpTpwGhCwjkxYtC95Se6wr6i23c2bJwI3dM7gTbiSWFwnW f+jjLRGvSY8DNxk/rSwJYAgeTywfpY3hjX3fe0iV3EPm04Z9mAY+zrcBLnncZAXrz4V2 tLWoQHbFAs+tadm09lu8wSegG/MV9WE3qVyHkKvNup8oEe4IkAfC9oQorM1fNRvv7Xcp /oJxmJA6bnjb5TB7q8+36MfIZwE2TMfLfNALA06XD18OB7QhFQ+rYsfbrAabht8Ytoy6 Mz5w== X-Gm-Message-State: AOJu0YzpVo04GRaRQDARWyGS1TMtyS33qM2wvoS9rhnIZEP9yOUyfKrn hw67VXKSTSljNoOGvomIbpdYCdVT6VKa7cXY6+IQCLt6q4qZDwUk+5ZSsA== X-Google-Smtp-Source: AGHT+IHhsDr7b4tFQfsLaawas4lUPGVQNzlpZkvgkc/R1clmfoMdSH5yzNPuZCeD7oIoqLRQ78rUAQ== X-Received: by 2002:a2e:9bd5:0:b0:2ec:56ce:d50e with SMTP id 38308e7fff4ca-2eeb30bc5f4mr63264371fa.3.1720739505524; Thu, 11 Jul 2024 16:11:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde84798sm8790470f8f.38.2024.07.11.16.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 16:11:44 -0700 (PDT) Message-Id: <8bfd23cfa00c351ffdcc25bd29f3b84089544a56.1720739496.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 11 Jul 2024 23:11:36 +0000 Subject: [PATCH v2 7/7] var(win32): do report the GIT_SHELL_PATH that is actually used Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Phillip Wood , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin On Windows, Unix-like paths like `/bin/sh` make very little sense. In the best case, they simply don't work, in the worst case they are misinterpreted as absolute paths that are relative to the drive associated with the current directory. To that end, Git does not actually use the path `/bin/sh` that is recorded e.g. when `run_command()` is called with a Unix shell command-line. Instead, as of 776297548e (Do not use SHELL_PATH from build system in prepare_shell_cmd on Windows, 2012-04-17), it re-interprets `/bin/sh` as "look up `sh` on the `PATH` and use the result instead". This is the logic users expect to be followed when running `git var GIT_SHELL_PATH`. However, when 1e65721227 (var: add support for listing the shell, 2023-06-27) introduced support for `git var GIT_SHELL_PATH`, Windows was not special-cased as above, which is why it outputs `/bin/sh` even though that disagrees with what Git actually uses. Let's fix this by using the exact same logic as `prepare_shell_cmd()`, adjusting the Windows-specific `git var GIT_SHELL_PATH` test case to verify that it actually finds a working executable. Reported-by: Phillip Wood Signed-off-by: Johannes Schindelin --- builtin/var.c | 3 ++- t/t0007-git-var.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/var.c b/builtin/var.c index 5dc384810c0..e30ff45be1c 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -12,6 +12,7 @@ #include "refs.h" #include "path.h" #include "strbuf.h" +#include "run-command.h" static const char var_usage[] = "git var (-l | )"; @@ -51,7 +52,7 @@ static char *default_branch(int ident_flag UNUSED) static char *shell_path(int ident_flag UNUSED) { - return xstrdup(SHELL_PATH); + return git_shell_path(); } static char *git_attr_val_system(int ident_flag UNUSED) diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh index ff4fd9348cc..9fc58823873 100755 --- a/t/t0007-git-var.sh +++ b/t/t0007-git-var.sh @@ -157,7 +157,7 @@ test_expect_success POSIXPERM 'GIT_SHELL_PATH points to a valid executable' ' test_expect_success MINGW 'GIT_SHELL_PATH points to a suitable shell' ' shellpath=$(git var GIT_SHELL_PATH) && case "$shellpath" in - *sh) ;; + [A-Z]:/*/sh.exe) test -f "$shellpath";; *) return 1;; esac '