Skip to content

Commit 4eb9b11

Browse files
j6tttaylorr
authored andcommitted
git-gui: remove special treatment of Windows from open_cmd_pipe
Commit 7d076d5 (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 <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 02dd866 commit 4eb9b11

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

git-gui.sh

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -559,22 +559,13 @@ proc is_shellscript {filename} {
559559
return [expr {$magic eq "#!"}]
560560
}
561561

562-
# Run a command connected via pipes on stdout.
562+
# Run a shell command connected via pipes on stdout.
563563
# This is for use with textconv filters and uses sh -c "..." to allow it to
564-
# contain a command with arguments. On windows we must check for shell
565-
# scripts specifically otherwise just call the filter command.
564+
# contain a command with arguments. We presume this
565+
# to be a shellscript that the configured shell (/bin/sh by default) knows
566+
# how to run.
566567
proc open_cmd_pipe {cmd path} {
567-
global env
568-
if {[is_Windows]} {
569-
set exe [auto_execok [lindex $cmd 0]]
570-
if {[is_shellscript [lindex $exe 0]]} {
571-
set run [linsert [auto_execok sh] end -c "$cmd \"\$0\"" $path]
572-
} else {
573-
set run [concat $exe [lrange $cmd 1 end] $path]
574-
}
575-
} else {
576-
set run [list [shellpath] -c "$cmd \"\$0\"" $path]
577-
}
568+
set run [list [shellpath] -c "$cmd \"\$0\"" $path]
578569
return [open |$run r]
579570
}
580571

0 commit comments

Comments
 (0)