From: Pat Thoyts Date: Fri, 9 Dec 2011 15:14:32 +0000 (+0000) Subject: git-gui: handle shell script text filters when loading for blame. X-Git-Tag: gitgui-0.16.0~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7d076d56757c238aa1b90534cd0d2450528b3580;p=git.git 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 Signed-off-by: Pat Thoyts --- diff --git a/git-gui.sh b/git-gui.sh index 2c57fb4a6..ba4e5c133 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 diff --git a/lib/blame.tcl b/lib/blame.tcl index b031e66a4..324f7744c 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -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 \