]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: remove special treatment of Windows from open_cmd_pipe
authorJohannes Sixt <j6t@kdbg.org>
Sun, 18 May 2025 14:08:06 +0000 (16:08 +0200)
committerTaylor Blau <me@ttaylorr.com>
Fri, 23 May 2025 21:04:23 +0000 (17:04 -0400)
Commit 7d076d56757c (git-gui: handle shell script text filters when
loading for blame, 2011-12-09) added open_cmd_pipe to run text
conversion in support of blame, with special handling for shell
scripts on Windows. To determine whether the command is a shell
script, 'lindex' is used to pick off the first token from the command.
However, cmd is actually a command string taken from .gitconfig
literally and is not necessarily a syntactically correct Tcl list.
Hence, it cannot be processed by 'lindex' and 'lrange' reliably.
Pass the command string to the shell just like on non-Windows
platforms to avoid the potentially incorrect treatment.

A use of 'auto_execok' is removed by this change. This function is
dangerous on Windows, because it searches programs in the current
directory. Delegating the path lookup to the shell is safe, because
/bin/sh and /bin/bash follow POSIX on all platforms, including the
Git for Windows port.

A possible regression is that the old code, given filter command of
'foo', could find 'foo.bat' as a script, and not just bare 'foo', or
'foo.exe'.  This rewrite requires explicitly giving the suffix if it is
not .exe.

This part of Git GUI can be exercised using

    git gui blame -- some.file

while some.file has a textconv filter configured and has unstaged
modifications.

Helped-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
git-gui.sh

index d56610c8922fd85b716f2993299aa88fce8c3987..cb0c02e5b8f439e3c6040f16e8b61c13e308a7ee 100755 (executable)
@@ -559,22 +559,13 @@ proc is_shellscript {filename} {
        return [expr {$magic eq "#!"}]
 }
 
-# Run a command connected via pipes on stdout.
+# Run a shell command connected via pipes on stdout.
 # This is for use with textconv filters and uses sh -c "..." to allow it to
-# contain a command with arguments. On windows we must check for shell
-# scripts specifically otherwise just call the filter command.
+# contain a command with arguments. We presume this
+# to be a shellscript that the configured shell (/bin/sh by default) knows
+# how to run.
 proc open_cmd_pipe {cmd path} {
-       global env
-       if {[is_Windows]} {
-               set exe [auto_execok [lindex $cmd 0]]
-               if {[is_shellscript [lindex $exe 0]]} {
-                       set run [linsert [auto_execok sh] end -c "$cmd \"\$0\"" $path]
-               } else {
-                       set run [concat $exe [lrange $cmd 1 end] $path]
-               }
-       } else {
-               set run [list [shellpath] -c "$cmd \"\$0\"" $path]
-       }
+       set run [list [shellpath] -c "$cmd \"\$0\"" $path]
        return [open |$run r]
 }