aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2022-12-04 22:56:08 +0100
committerPratyush Yadav <me@yadavpratyush.com>2023-01-24 14:10:40 +0100
commitc5766eae6f2b002396b6cd4f85b62317b707174e (patch)
treeb945c37f7af9c1ebe56b299091bcd4411b4bf814
parent8f23432b38d9b122be8179295a56688391dc8ad6 (diff)
downloadgit-c5766eae6f2b002396b6cd4f85b62317b707174e.tar.xz
is_Cygwin: avoid `exec`ing anything
The `is_Cygwin` function is used, among other things, to determine how executables are discovered in the `PATH` list by the `_which` function. We are about to change the behavior of the `_which` function on Windows (but not Cygwin): On Windows, we want it to ignore empty elements of the `PATH` instead of treating them as referring to the current directory (which is a "legacy feature" according to https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03, but apparently not explicitly deprecated, the POSIX documentation is quite unclear on that even if the Cygwin project itself considers it to be deprecated: https://github.com/cygwin/cygwin/commit/fc74dbf22f5c). This is important because on Windows, `exec` does something very unsafe by default (unless we're running a Cygwin version of Tcl, which follows Unix semantics). However, we try to `exec` something _inside_ `is_Cygwin` to determine whether we're running within Cygwin or not, i.e. before we determined whether we need to handle `PATH` specially or not. That's a Catch-22. Therefore, and because it is much cleaner anyway, use the `$::tcl_platform(os)` value which is guaranteed to start with `CYGWIN_` when running a Cygwin variant of Tcl/Tk, instead of executing `cygpath --windir`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
-rwxr-xr-xgit-gui.sh12
1 files changed, 2 insertions, 10 deletions
diff --git a/git-gui.sh b/git-gui.sh
index 0cf625ca01..0fe60f80cc 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -269,16 +269,8 @@ proc is_Windows {} {
proc is_Cygwin {} {
global _iscygwin
if {$_iscygwin eq {}} {
- if {$::tcl_platform(platform) eq {windows}} {
- if {[catch {set p [exec cygpath --windir]} err]} {
- set _iscygwin 0
- } else {
- set _iscygwin 1
- # Handle MSys2 which is only cygwin when MSYSTEM is MSYS.
- if {[info exists ::env(MSYSTEM)] && $::env(MSYSTEM) ne "MSYS"} {
- set _iscygwin 0
- }
- }
+ if {[string match "CYGWIN_*" $::tcl_platform(os)]} {
+ set _iscygwin 1
} else {
set _iscygwin 0
}