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>
This commit is contained in:
Pat Thoyts 2011-12-09 15:14:32 +00:00
parent 215d4fdbaa
commit 7d076d5675
2 changed files with 37 additions and 11 deletions

View File

@ -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

View File

@ -476,14 +476,7 @@ method _load {jump} {
}
if {$commit eq {}} {
if {$do_textconv ne 0} {
# Run textconv with sh -c "..." to allow it to
# contain command + arguments. On windows, just
# call the filter command.
if {![file executable [shellpath]]} {
set fd [open |[linsert $textconv end $path] r]
} else {
set fd [open |[list [shellpath] -c "$textconv \"\$0\"" $path] r]
}
set fd [open_cmd_pipe $textconv $path]
} else {
set fd [open $path r]
}
@ -575,7 +568,11 @@ method _read_file {fd jump} {
foreach i $w_columns {$i conf -state disabled}
if {[eof $fd]} {
close $fd
fconfigure $fd -blocking 1; # enable error reporting on close
if {[catch {close $fd} err]} {
tk_messageBox -icon error -title [mc Error] \
-message $err
}
# If we don't force Tk to update the widgets *right now*
# none of our jump commands will cause a change in the UI.
@ -1065,7 +1062,7 @@ method _gitkcommit {} {
set radius [get_config gui.blamehistoryctx]
set cmdline [list --select-commit=$cmit]
if {$radius > 0} {
if {$radius > 0} {
set author_time {}
set committer_time {}
@ -1173,7 +1170,7 @@ method _read_diff_load_commit {fd cparent new_path tline} {
}
if {[eof $fd]} {
close $fd;
close $fd
set current_fd {}
_load_new_commit $this \