From patchwork Sat Jul 13 21:08:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13732492 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.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 EC69A1411DE for ; Sat, 13 Jul 2024 21:08:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904911; cv=none; b=nmuZKrPPbOl64pJwGSy4THjrc8oK0o43NwFPzCrLJ9uCiBWOa3t83Qrua6fYSW4Liqvn8JFlUZUOzH4k075vo6MXKLzrE9Pt50HHaVu1/vubwbc5SeiC6t6HwYwSfjcq7uZbfP3TfVF6L6tL+JJsTFaxs6KhoGKjB81vEI2FlH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904911; c=relaxed/simple; bh=u8yaTDujhV2/Nu4OVUSQjQlDfgzdR329gA/H50m5rl8=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=VHaV0+5FZd0aJB1vt8bllLEp2VbftJDUx8YNYii0zsW9AKsrJ/awFYIYQUaospH+MwKgMcbZA8UjO5vGfNfB5Kb/eMSMJTB/FoucFHUjfd11rSx88xL03jyOK8XdHRsZbEcjaoRnKevHLFRql3WhOZ0gBN+bsxgdRZCowKt9O+c= 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=D8MNVvIK; arc=none smtp.client-ip=209.85.128.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="D8MNVvIK" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42797289c8bso22553645e9.0 for ; Sat, 13 Jul 2024 14:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720904908; x=1721509708; 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=D8MNVvIKnM+vFOAELHQZICEgwwHsM3QuNEeIaPgUjmraxGh8RXOnsKhuIe5oczEfdJ rJvwNm4DFaoLu7ZHTW0NK6nzocXX5ABSDgbuTqQMeUPsyaKOBEBTh+lWcDgRc/yYw/Nw YPak3BRcKl9uS6f8OkpUSgaSRlKIhNjO/O6tfuDs7zTDjo0ehS3dYsaJnhWLf7tb6lwU uwP9RI52x+CpfPR7l+A+mUUkpTJhItvMhokakor/+vPQrDmtBuLte+IPYHDBKjXimfy2 5UgQ8PYk0vMbDATkt5o+wHMTqwqHJ/Xc7jMTxAA4GDuWIEAGu2pPscxZN8Zsc3yf0zmZ w3hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720904908; x=1721509708; 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=HJN2so1E2mRHQam7EXUGQgs0ULB7gVG39wRtNVrYIYHwSBJv1BT72sj5OFIXhljgEB 6Dvk469XGTg5jMiwFjqMSKgjjw7e+Cf38PY+uaNlfM4PA4lMewaDZ/U0u7eZPygLLTyH mkv4QD1JrivXDnviI3QaesiD73ljuMUpfWgfA9HPEVwwM0BoTS2xarAMEmR+mPpdFUm4 KWN05EQX+FpQmiwLN7KhwmVO97rnlmnZnpDFHF864GPvdxHPUW8zXaOR01g/PziAvQPY feCfmHzYFtnWyKy37LTnt/5AqHaWcz3WTGj+tXt0KG7V1E/WFelZWYM6JbA1YCZ+LvEU vplg== X-Gm-Message-State: AOJu0YzNwmdWwD5VBO/HxhF4H91wz1ERO7RygTo9AKm0NYSHZGi9R2KH ekYCMqtqA3RS2cSr7SaRZew4tgIu4+7zo1+pjnKaHXkNQj6OpBaH+Bkzeg== X-Google-Smtp-Source: AGHT+IE83J523w8We6kN0ozoYhxpPAnjYWBJMVNBDjJ7nYmRYX/K7DSJA10cGzTCBFlJ8foHZAYUSQ== X-Received: by 2002:a05:600c:42d3:b0:426:5546:71a with SMTP id 5b1f17b1804b1-426705ce6f0mr95601275e9.2.1720904907640; Sat, 13 Jul 2024 14:08:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427a5e83273sm33295895e9.17.2024.07.13.14.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 14:08:27 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 13 Jul 2024 21:08:18 +0000 Subject: [PATCH v3 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 Sat Jul 13 21:08:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13732493 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 580551420A8 for ; Sat, 13 Jul 2024 21:08:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904912; cv=none; b=Ki0aJfdDgZ+3kLY04oORhl3xX9gyVdSl+FGidBAk1YbLZ1VoWN71kC27PEj7wK5+aZwHy027VWqkbOOYqqqgQ493R/p6yFUnpFfdv5dSBj8f0dl0jAWQxsf6ueR4Df4a+GCXZcrkGMdghVB+5k8AYf3RxjKxFmY16D08yzUJqzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904912; c=relaxed/simple; bh=MIwsxKQCc6L1ypFrSWOoIhAUtc7BOba8IDgNM12CZxk=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=JC/4iUSxgLPJbLAXWX9aB2H2aWm6cAhNfzZ3QcHdyluHhPa+oyyOgT/m7WhnAI7SuGc/pDQg9uf22lb7iDRxg595hYABbWEk4u6bHpRjk2IdeVYkYaia9rHf8zzvllAwd51s+ZhxODHdwUvncDyuIihMLMtYaD6jU7YXFdSatio= 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=hG6qCyPZ; arc=none smtp.client-ip=209.85.128.50 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="hG6qCyPZ" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-426717a2d12so18284375e9.0 for ; Sat, 13 Jul 2024 14:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720904908; x=1721509708; 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=hG6qCyPZIvzepR3rFlhxHvilvp10sJZx947/P4VXsFZBzkIuj8n9O30GHOLiN2bK3X AZLUXNr/vqMn8pF4R78nF2+nUUYA4opuBDlwEL197Zzi+pzKreoBrjd6PPWGAbGX7vSm Eqx8ixDE8tr6U03xWQUTMr3IF9teDQqgoq9NVq8ORO+z3q5r3MhSdGlejQL69CnLhzfu /zqk2GhuNMGPdsFpFkwsSE6zbBX8K7zyMG1u6CnTyzlZtn3ROGKfRg7061j9k3V3Hy4V eCoQfqxokcVuJQoSHN+UgYrI2UElBuX/9dnSzIuikOtPvaWKOf1/PyjHQPnAhakymwM1 Z6AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720904908; x=1721509708; 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=MsnLPoL19/v8QChpQi57WJD0mboHLoJvsaiC5Nye1y+8hbYXM2sqwm0/LEFDpWBjjF uyDg+I3X1btonZCzo86FkwTi3wQg3YZaK7eZosUv3ZRyVvCjmTSDnlQ6J1JDra5pyY7L 0AD8mKinwmUzybcYLCt5S+NhXQA9723AGLL7AgBDg2mVJl9VDasINMETkAQAPPb2c93u 3VTc5Jfh7WUz3upHcrFXMbRtwEnaD/tgj8rWCIDCdGnjLOymFrCWWWv8XsuNdrLCsj9/ 05Eeci+47DbZqYlYYRpn20L7ZPavWJ9WIVpnli3zcnX3MN309zuXa7GWN1esN33/VyLP xlJw== X-Gm-Message-State: AOJu0Yx/D/VLJjMt1le9J0lvGOzNYz5Kewogak4kopg9EbkhZNNySOv0 CqCqsjPhKl/aK+IcKGex5ATG6ZbB6ceDQJdpCJW4NrlsbksVSgxNgqQ2aw== X-Google-Smtp-Source: AGHT+IGESz23EecRfOvwPqkK7HxiPPr0LOxbP8hOXUd3pzec8QaWOVfgJp3Moj7ljqAGRXjdmgsxFA== X-Received: by 2002:a05:600c:4793:b0:426:67f9:a7d8 with SMTP id 5b1f17b1804b1-4279dae2aedmr58167215e9.9.1720904908378; Sat, 13 Jul 2024 14:08:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f2cc42esm67891135e9.32.2024.07.13.14.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 14:08:28 -0700 (PDT) Message-Id: <91ebccbc39f21fa73af8bc8c81af721f1ca201bd.1720904905.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 13 Jul 2024 21:08:19 +0000 Subject: [PATCH v3 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 Sat Jul 13 21:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13732494 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 C11051448DC for ; Sat, 13 Jul 2024 21:08:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904913; cv=none; b=o2/oLrxUuRZYWVKp97pj4tctl7L43CDgNfJaoi2UMu7frR4Th9Aw3LyDJ1gJ26FddG1L6NarNiyYngJLOnvSSUy0QtyUYd8ue56YefustLazkJfIS0+k/OLl/kh5iz8TmXHmFnLwurx7qPaXCoQT8MvzVOFKhsdQdjs0FYqGYEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904913; c=relaxed/simple; bh=SSXWLOtFLA49xGelkQoShQtMLAJnv1L6G9J5dfCKfzI=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Xq6YfbxM6uQoHDHPEHc3syjah330JUEEdWx3XbzlKe3mR2Zhkn9/itDSWskKVCzHwZBDSRNmHDtiiTqlQxoSLq7XmhTS3n/sLGxXBMGOlAXMKRzI1vtwlXB8pyfqRTWFbz5uJYqXro4I8lipsCqBxNByEDXmzJFhNPAYw672Q/w= 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=gibmiCHQ; arc=none smtp.client-ip=209.85.128.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="gibmiCHQ" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4266dc7591fso21200485e9.0 for ; Sat, 13 Jul 2024 14:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720904909; x=1721509709; 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=o+KoE7ACa4NLm9SmoicvJ3gvk7Uiwb/D8yBVlIBGtQs=; b=gibmiCHQYDEGikbm8du5TrgUrBDpftH8XcerjE1Eo8WYt1St113VvsspupS37XMVuw wlc5vJSlhjTmnvek2ZZ+pui5YiSoTohDP3xT9UYGErbf4pgNBL76aP3LevYolYgWpRmh 9M1Q1f60VyHoio4mOaYQCgL1bhyHQKPPWw29ftthImsaw2kSjmwXSR3VLeiyau0zj+Ad j8pId7bx3ZQoYS/AzVkaDPsHg6kr5dCKPTCk2ZAKwSxc4gOOFKbs03OdoyfEmceELBUY HbefXlpwzWWw9x5OKLndqgFVLWxs676GSbnflsCE1mKnMOwHuKn1b+q2qRK8o/DL3tym Rg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720904909; x=1721509709; 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=o+KoE7ACa4NLm9SmoicvJ3gvk7Uiwb/D8yBVlIBGtQs=; b=OuLqXF+wXb5Trs/K4fK/yqvkITlwlm/jDoKYB/QBDeThitvUVOJPFyAFJ9X+HjllBY u+9KsKupSlSYUlJ/FWQx9qUU0argbvZxB3KXL/qRifri3JWjoO12Y1OedY2aoy23pURo tZkGdnlGta94+ZUy4qTr4800LVXFIJSxwPBvSeR5OGIqXLoP0aEr/KaXRsw0HQEVhYsd a3IlIerQef2suZCPLX6zX0CGUP6UMDVGD2qi1olfaXiOPCViV+a5mlClmfMu1KLEsQGe hsLPT8EMUPUxJqcUytOv/x+LzdErM8KNRINCVs50hMcL4khGcUWFXpIn7WFPQiY/YYDk zaWw== X-Gm-Message-State: AOJu0YzYXG22n7ix7eBidjnqgaszHpavWK+5LNwMPOiD2VEGU4I0zeUB P75UXsX2FSiAc/8i7v+6PCRxp4Ct5vRv9j3wijLtj8AF2rPkByqtRWEH+g== X-Google-Smtp-Source: AGHT+IEJFUx9lJUwymL7MEJ9t3sYnSHIXYRth3LpAjRdzx9awaZTbteTGMCIrh44hsF+xwDKCb7CnA== X-Received: by 2002:a5d:5f88:0:b0:367:8847:5bf4 with SMTP id ffacd0b85a97d-367cea46d6emr13362733f8f.10.1720904909401; Sat, 13 Jul 2024 14:08:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f2cc21esm67492595e9.31.2024.07.13.14.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 14:08:28 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 13 Jul 2024 21:08:20 +0000 Subject: [PATCH v3 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. Note that we have to override both `fspathcmp()` and `fspathncmp()`, and the former cannot be a mere pre-processor constant that transforms calls to `fspathcmp(a, b)` into `fspathncmp(a, b, (size_t)-1)` because the function `report_collided_checkout()` in `unpack-trees.c` wants to assign `list.cmp = fspathcmp`. Also note that `fspatheq()` does _not_ need to be overridden because it calls `fspathcmp()` internally. Signed-off-by: Johannes Schindelin --- compat/win32/path-utils.c | 37 +++++++++++++++++++++++++++++++++++++ compat/win32/path-utils.h | 4 ++++ dir.c | 4 ++-- dir.h | 4 ++-- git-compat-util.h | 8 ++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/compat/win32/path-utils.c b/compat/win32/path-utils.c index ebf2f12eb66..b658ca3f811 100644 --- a/compat/win32/path-utils.c +++ b/compat/win32/path-utils.c @@ -1,4 +1,5 @@ #include "../../git-compat-util.h" +#include "../../environment.h" int win32_has_dos_drive_prefix(const char *path) { @@ -50,3 +51,39 @@ int win32_offset_1st_component(const char *path) return pos + is_dir_sep(*pos) - path; } + +int win32_fspathncmp(const char *a, const char *b, size_t count) +{ + int diff; + + for (;;) { + if (!count--) + return 0; + if (!*a) + return *b ? -1 : 0; + 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 = ignore_case ? + (unsigned char)tolower(*a) - (int)(unsigned char)tolower(*b) : + (unsigned char)*a - (int)(unsigned char)*b; + if (diff) + return diff; + a++; + b++; + } +} + +int win32_fspathcmp(const char *a, const char *b) +{ + return win32_fspathncmp(a, b, (size_t)-1); +} diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h index 65fa3b9263a..a561c700e75 100644 --- a/compat/win32/path-utils.h +++ b/compat/win32/path-utils.h @@ -29,5 +29,9 @@ 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 +int win32_fspathncmp(const char *a, const char *b, size_t count); +#define fspathncmp win32_fspathncmp #endif diff --git a/dir.c b/dir.c index b7a6625ebda..5a23376bdae 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); } @@ -105,7 +105,7 @@ int fspatheq(const char *a, const char *b) return !fspathcmp(a, b); } -int fspathncmp(const char *a, const char *b, size_t count) +int git_fspathncmp(const char *a, const char *b, size_t count) { return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count); } diff --git a/dir.h b/dir.h index 69a76d8bdd3..a3a2f00f5d9 100644 --- a/dir.h +++ b/dir.h @@ -541,9 +541,9 @@ 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); +int git_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..71b4d23f038 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -506,6 +506,14 @@ 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 fspathncmp +#define fspathncmp git_fspathncmp +#endif + #ifndef is_valid_path #define is_valid_path(path) 1 #endif From patchwork Sat Jul 13 21:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13732495 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 145D61411DE for ; Sat, 13 Jul 2024 21:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904914; cv=none; b=GcumEATxoow0qPiord4GQOV3JJ33qSyGiUyAOKFyo3Nj4QzxDZx8a/FsqEqzxif/n0L2TVxN2S/3MFjzs5TheILiNlGFeBfSk5Y2dSFFCF/Gm8Wdpg40HKPbEKqGV/1psG+xkDrrAdP6k9vq8gNPh28Kv86qHwJfMUA+ddb66bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904914; c=relaxed/simple; bh=X4hE+H8Z1mDrZwOiKzXK0l++3FlajlA8Z1GvV7ZqIAg=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ukgRAiO3IFJe+dIiSbW1rMKpXaRL3lkk8uKT7GzdOjSFzHMJ7nlzI9EX54xO1noNt4wXrI2vMDGQtGlS2JJZD0hOJTNVvLssCHApUzexCxdDf9WsS17oS7s6J56Xz1ITajkAl3fCJamuinreYb5kEXFEqGrGOgcxj5pEC55eVU0= 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=MKJc9CCq; arc=none smtp.client-ip=209.85.128.41 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="MKJc9CCq" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4265c2b602aso20416745e9.3 for ; Sat, 13 Jul 2024 14:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720904911; x=1721509711; 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=MKJc9CCqyiFHpRcLpFFEcjMbBAqbaMFB8YelUaVpk4FxFvaHH0mITtI+u+L9XwLc09 TN8pjA7sZpRr6x6gCknBFY+bBMNwMXMFLQUbSznWZv7VNgXcGli5MxL+CYVzvpU7fTg4 go0h5yDpmndTOGjosuEpyFpvouAdEZ42amuQ8Lh5tf3EXUw/npFUTSk17RmYThvACOlR r/bYV1WTv59CASYBe9zmWxGab9wahnN7S88dkJN1gJEkd27H6/5g/M+gUtjceHTB/ybG /pad6qlYt3bk52A80OJuer9DeYkCiJERVtaFP4U0TKIeKVE4VfpsPXl9O4X2HHFAoAy7 csqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720904911; x=1721509711; 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=rdXOHqmqXRVkatoTJaQSmSFKwiso+T7B9KtzORTwkzW/igaHEQCUb/C3jLQves0Tij LYEYy9gc4G/zOFi2xM6b/s5VAZgourq26IX7b0640kAvQDogQqZ9RgUmY+PRHUWsijwv /cOmZ/epXiab6EkpFjldWM+b2NRizff8s0gDHh+i6egzMhsJDU5GngZ63a8SyPW3/GHN 7pFH59Xv9MDFxBSGFpnqb7noEh6o5kiH/ztCEn1BDahtbqrK6E6wJhjEuAel9/zFXP82 1HMd6sAZBlYKGVnkowPFnSmcnk/qDyacKiBoANOBcKc0HklR4HWpbBLkpJPFK6+uH8YY Zc1w== X-Gm-Message-State: AOJu0YwPe7IdcOe7da7sjh8n1bZb6a2Ms+FuMXNdlgP5jywoRng05kCT 3bWiRnFxkNiIA7L4ai3m1pWE+AeuRDcLeNx2SF53yHV7+s7PwrR4ufDOTA== X-Google-Smtp-Source: AGHT+IH1UeknvOA8ABcD9Z/MTIyAhPed3QNSaPtOGGmYCsSCEFwCc/7/RpcYSMmLNgUuE8/YV0ZZVg== X-Received: by 2002:a05:600c:4982:b0:426:6314:3336 with SMTP id 5b1f17b1804b1-426708fa8bbmr98307445e9.36.1720904910866; Sat, 13 Jul 2024 14:08:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427a5edb4a3sm32755025e9.31.2024.07.13.14.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 14:08:29 -0700 (PDT) Message-Id: <60fde81d35ce58975307e507debbb27ade10853d.1720904905.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 13 Jul 2024 21:08:21 +0000 Subject: [PATCH v3 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 Sat Jul 13 21:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13732496 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 2219114C586 for ; Sat, 13 Jul 2024 21:08:33 +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=1720904915; cv=none; b=TOTKsnenslgO158DkCvAg6sBkrcCedHkpQ+1epD78KD48rSHLXJqXJuJyQZDlyg/wcgetRHjbQbaJEt1ri0YPh9fvq6mpfwLHGHmpAgPEV3xBkE1R46PIOCqdAIZxA8CJVTOqe+tuqLZrXYl/R4IC9TlEhWhSpBL7FAQcCOY0Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904915; c=relaxed/simple; bh=Zn6Q79lF4XV6seukFGYGo0mSUEYlc/kiG1ZjPcbLdcs=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=jhXP/WEwom8FlUi2oF8loOggZoITprLu3xoyM2TZ1i2ZQ6F9RenslRCZaViq+6PxC3N0dhwJ/sdTeAC4hGimMF3FTwcKx/p6mBuE6C24jbiZ0hwO1LxylDilE8fpt1mWEZty5QR+P/6qxErbG6lfEwiMIqn0cn3yWmG2WiftJeQ= 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=ltyONaPs; 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="ltyONaPs" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-367818349a0so1760176f8f.1 for ; Sat, 13 Jul 2024 14:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720904912; x=1721509712; 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=ltyONaPsq2QU0Y2HimRJD1u1hiVV2pC48tO8T3qCvTcA4SwfIUFwDvwQ+oeJYLpiOq Y42git/YRuNEdCTHu/0UDfWO8DLiSmjNRHlG/NLR/4MHaT9i59j6J6undoi75l9PKVLY Kb7AkeUxqoSCUhqKZDj/NqPFnxi79Lx5AjnxWKboaefVswCKDa0HVBJy0FNjusYZhPa8 mj2wY7WaKguE4iMNAUE8C0gnuIITKS0etYa51wjqXoAhEw6dr7cg5eAKlhyWwGxWAgca Vxc2UEaZKv9qfl6NNbIbvXqyyCfK7F6McFVwDNdAXdGvg7t1QIaNZ0+ZUYcMTVRrsnwB MC9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720904912; x=1721509712; 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=tw4FwOr41yQkzJ86etsAvvxgIQyxsQt0pZJArIgBZjTOpAmaSdbJOS3+3au/yK7nCh 3hwG6ghaCVRAP7Yzh7yIL+yHfCAik2yYXv/POyP3Dkkc9auq5W6Q9LdFtc3rskd4UTqV 8Kc6gW0rD0vYwnxmLG28p73pbs03Css33OLdRg/Bn0R8AhGbRaymoC9MlOOKc5jF2Woq UcGKQJdklIxD9AHnRCoN7TqTkpwCkoLh7sc5xC2tkUwlyM3T9Y1e67bA9tFaqgpCxq1n jgEanIzPandsjgVdxVRgyAUBLfMP5BDcoQPJOFeWkxywctOYvwGkNu2zU5uTLPTBI3C/ PILQ== X-Gm-Message-State: AOJu0YyvKPL3fBa1DoLcjVqFdPGMoha5ZxZ1OeQDRc/GixhaJFCWn7g/ aupXXFsexnBKFfjKUd8ClQMP2jS/M7nEYFY92TMxeJyaTvC/juXIRgbNEA== X-Google-Smtp-Source: AGHT+IH5Y71I1PDIPC7YQ856+WDHlOWvUzZUSTG5LY0ZaTAaJxpLDwViz2f4V7Ofr1pQ3MgOIzZ1KQ== X-Received: by 2002:a05:6000:156a:b0:366:d5ea:6098 with SMTP id ffacd0b85a97d-367cea46b19mr12580137f8f.3.1720904912101; Sat, 13 Jul 2024 14:08:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3680db0f26esm2360691f8f.116.2024.07.13.14.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 14:08:31 -0700 (PDT) Message-Id: <797cf9094ea39e9bedb2e60ef86fe3ca089009ba.1720904905.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 13 Jul 2024 21:08:22 +0000 Subject: [PATCH v3 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 Sat Jul 13 21:08:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13732497 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 4064E15538C for ; Sat, 13 Jul 2024 21:08:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904916; cv=none; b=ZkcpxUJlQpQ/di6XF9Wmibdy2iGNEI3BjknLO9OCnYNIIFiyFXxEpJhy+Y6ekf9Sn99qW032dbv/buCJ05zry6Pt/fFUsumxc5ABr4e/Fn7kgl5AYSKnCLFPe5cb2rtf5SvnNKyKSRO+Zxu9neuZ7p+3RM6PWZP5Sdq3ack1PxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904916; c=relaxed/simple; bh=wGI/u536ygogFWY5DiujXv3jyD5Cg7FCZEx8VWytJyU=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ISMP9kBDPEovZ95CCQxQIFaLlz4oiV1pXPjlVokXrnc3vbzTYwi9ozQMUWPqbap+d9e/PQGd82TLeFMvHdkRynNTwHOR2Xp60GYGZ+wT+O57L3EIZKpmDclP558FXoIWnmME5rbu3n8IqwrrwOM6ATCW0cnwg3qnF89Qpv5P86s= 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=bNTt5II0; arc=none smtp.client-ip=209.85.221.51 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="bNTt5II0" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3679df4cb4cso1935006f8f.0 for ; Sat, 13 Jul 2024 14:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720904913; x=1721509713; 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=bNTt5II02PhPR4EhcSveoGeUfRupXpeH22Hxnsu7Zo4spIsbDsmxPA1QLnCcvYgJ/+ AEBZhYGPvnanmCZvqViH9YpVn2bOzmLCt5oW0vRyNLERzoFAamINSlU5vY+vx3J+7MFJ VG9RkRDjFLheKjyfX8GZg8AHy9D/qq0YQgbVw/ZN0t5tSvc1/WLgY9fn0sJLmKiLI0In tWzZCC9tXCDUW6Q3AyoS/CDCyVmVOL0xzWYBQe1Rnl5ABmKsVrhFw2VcEdf1e+dzt67S k7Fg8x6pmxv9Pjxttl3Gzf/7Ncu8Da5WyCtC/Df4QxSz1zZIwlcP4rBh5XMd0JcLddTF 8v4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720904913; x=1721509713; 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=rYhJB2KoFOEzlOOxV5vNN1MtvUX+2ZTHm5DmVYFkHSKHOOyiF3A9LEeCRnJ/2XcXZE ArYxbuN05MYs4tUv0Sbls17zk5Qgch2USfo4TU2lGKuGHDp995peCmTCeXFkS0td1Wm0 OWU1pMAnsyInMpDWFTxps2wx1NlR7HoF3ETlhMfOk84bK3IG/P3QjwMoppDhU6u9yahl VL+lmSgSjQu5WowKupqN1k+v0pAYfbTnauA3OnQ6Ii+V2wVlcYeJLq7wGtDqmsLZuzu5 P73ZQdWpQaYJ02b6JjyEDXQFewD6k6yuCmvTTwxdFRlFWmFkCKEl+bhvxrR2GnG41NE0 YJVw== X-Gm-Message-State: AOJu0YySgAq+gPJHMPLseToPzcrFvsH9oZJX7npYNV26gtG3n9l7A5AL OWt6vjzbnF/yHM3K+jURS75kE5+a0ULmUxzPG9QhDb8kNE3KCNyBpUsJgg== X-Google-Smtp-Source: AGHT+IFRh5sUyqNU1jChSAjBa+Us6ZGO3A9Qf6V1OU1NJL2/Q41Wq9sZCfvZ2Zc+GwIKFvagFVkktw== X-Received: by 2002:adf:cd89:0:b0:367:865d:30b6 with SMTP id ffacd0b85a97d-367ff6edda7mr3982896f8f.8.1720904913231; Sat, 13 Jul 2024 14:08:33 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f09d1d8sm66703395e9.0.2024.07.13.14.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 14:08:32 -0700 (PDT) Message-Id: <7c53a4f4707ec1fcc0e0bf6ca049e632922b0bb3.1720904905.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 13 Jul 2024 21:08:23 +0000 Subject: [PATCH v3 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 Sat Jul 13 21:08:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13732498 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 4E16F158853 for ; Sat, 13 Jul 2024 21:08:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904918; cv=none; b=FXj920qMzMFTMI2U98tGvxFYcNVddVFPUq70Y8/jC9eDRlYFs+elTAynNIkkiZ00/zPG4Mm1sVIZpsOz3PfnizdN+I/iVZ3u8jyVjp4kj8MWKWcwqitoYBFZKRDyZwRBzxFVW6wK16409TE7sRxDow4thJtL+g7Mny9PEgPrLb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720904918; c=relaxed/simple; bh=vPT+TOEiMe/bjQeQ0jCb6acz4GYnr54LsJHfh1fhtc4=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Bw1JKjxc0BRtShnzURKO+AC9faf56UNlNEO8itIFVrpUEKglaEJ7rOxYCr60xRPJCHnrqRYKanEsH4xLNRTMg+GOcJhqObjC96Iaxbjvu1qucTtoJnywUzEDHPsz376px3a2zjgheWNVmIldZabEG2Nj67kwvr3nPjscSdwQOe0= 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=WT32jI8t; arc=none smtp.client-ip=209.85.128.50 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="WT32jI8t" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42797bcfc77so21262005e9.2 for ; Sat, 13 Jul 2024 14:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720904914; x=1721509714; 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=WT32jI8tjB0SesX6ufrUmCsxuVnYjCtLZlR/9Mc1wQwZchqyeNEZEgXmReSE+lbXFX nN0C28JxQdVEJCxkRToxtlaOh8IoGzzmHfFn7dOLsTkSXh5b78gtzIwewP/UJGVmnBQF GHK3Vw+Cd6xOc3pRt3AsCDytJ+Yf+inXRFTQzRnrEUt7gCIdGD/cc/WxgcY/3v2Sp3Tk yQYjo7ASL9HglLMgHc/H0I5vcVwe+TvFPQ0rrKktCAaWf+kjWCi9wqPuGBBAZRFSAYVt QO3mtdx/mMTiOBT5nfdWVHP1xIAIqoEriJJedubNnTwBt2aaMWntDMxY+ALhrjmkuo+E bTPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720904914; x=1721509714; 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=IL2fov8GCncs+/3nPGQFllAB0js1PrBDUvKhsxbOEOojpMA819jveVcZKAE1ME4Mgs 7Cj9ZHLem+J5kL7W9SNMQVEHHI+H2L3sYivyq5mWssr0jlP4Zp2pBm7U2Fd1/dY/UPye H4cKb6+08ovcz87MnJKbApTRWmobcDuWcoZFTmDR6mxNqQc75bET+6Z3I3wDWpadM73J k0xC0sm9XTOZzXmWQpjwhH3BiKmff8hx4v1dcMfbm6KST3NyLXmCBJ53U1GUK2Cll+J9 60NSOhU8SFcolDGZarlkG/q+rvxMBQ3r8izoqwAWSYaVwQZaNxlp+XkcjaL+2s218sZp Pehg== X-Gm-Message-State: AOJu0YyLCfdab+F/S12bMVDdVOyue84gAjdpcEv1YTK8ZtwizYy/x17t LnwB7p+m973CpH76PZ1v9qsEU+0Fu8v7xUl5MMqsOc6S6qd3pdZ3XfLOlg== X-Google-Smtp-Source: AGHT+IEB1veNH0QmjUyijd28sd7KW57q6uqysLCWItUbotbZs+CAEvpYC3XXVu+1F+uWZ6nluJUI5g== X-Received: by 2002:a05:600c:245:b0:426:6fd3:1547 with SMTP id 5b1f17b1804b1-426707cf19fmr96370585e9.2.1720904914348; Sat, 13 Jul 2024 14:08:34 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279f2d73bdsm68131615e9.43.2024.07.13.14.08.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 14:08:33 -0700 (PDT) Message-Id: <7c8eba5bfd82944402e90eaaaf5150e9d7e7d8a3.1720904905.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 13 Jul 2024 21:08:24 +0000 Subject: [PATCH v3 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 '