diff options
author | Pat Thoyts <patthoyts@users.sourceforge.net> | 2011-12-09 15:14:32 +0000 |
---|---|---|
committer | Pat Thoyts <patthoyts@users.sourceforge.net> | 2011-12-09 15:14:32 +0000 |
commit | 7d076d56757c238aa1b90534cd0d2450528b3580 (patch) | |
tree | 416957a5a46a6ff8a5acfe38989ed42a19e55aa9 /git-gui.sh | |
parent | git-gui: Set both 16x16 and 32x32 icons on X to pacify Xming. (diff) | |
download | tgif-7d076d56757c238aa1b90534cd0d2450528b3580.tar.xz |
git-gui: handle shell script text filters when loading for blame.
When loading a file into the blame window git-gui does all the work and
must handle the text conversion filters if defined. On Windows it is
necessary to detect the need for a shell script explicitly.
Such filter commands are run using non-blocking I/O but this has the
unfortunate side effect of losing any error that might be reported when
the pipe is closed. Switching to blocking mode just before closing
enables reporting of errors in the filter scripts to the user.
Tested-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
Diffstat (limited to 'git-gui.sh')
-rwxr-xr-x | git-gui.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/git-gui.sh b/git-gui.sh index 2c57fb4a6b..ba4e5c1330 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -464,6 +464,35 @@ proc _which {what args} { return {} } +# Test a file for a hashbang to identify executable scripts on Windows. +proc is_shellscript {filename} { + if {![file exists $filename]} {return 0} + set f [open $filename r] + fconfigure $f -encoding binary + set magic [read $f 2] + close $f + return [expr {$magic eq "#!"}] +} + +# Run a 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. +proc open_cmd_pipe {cmd path} { + global env + if {![file executable [shellpath]]} { + 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] + } + return [open |$run r] +} + proc _lappend_nice {cmd_var} { global _nice upvar $cmd_var cmd |