Code

git-gui: Factor out common fast-forward merge case
[git.git] / lib / blame.tcl
index 13bfab3352518af99f87186246d57982a4ac35ad..96072847a2ffeec814f499657744e5ed4f8988c0 100644 (file)
@@ -370,9 +370,9 @@ method _load {jump} {
        $w_path conf -text [escape_path $path]
        if {$commit eq {}} {
                set fd [open $path r]
+               fconfigure $fd -eofchar {}
        } else {
-               set cmd [list git cat-file blob "$commit:$path"]
-               set fd [open "| $cmd" r]
+               set fd [git_read cat-file blob "$commit:$path"]
        }
        fconfigure $fd -blocking 0 -translation lf -encoding binary
        fileevent $fd readable [cb _read_file $fd $jump]
@@ -475,20 +475,14 @@ method _read_file {fd jump} {
 } ifdeleted { catch {close $fd} }
 
 method _exec_blame {cur_w cur_d options cur_s} {
-       set cmd [list]
-       if {![is_Windows] || [is_Cygwin]} {
-               lappend cmd nice
-       }
-       lappend cmd git blame
-       set cmd [concat $cmd $options]
-       lappend cmd --incremental
+       lappend options --incremental
        if {$commit eq {}} {
-               lappend cmd --contents $path
+               lappend options --contents $path
        } else {
-               lappend cmd $commit
+               lappend options $commit
        }
-       lappend cmd -- $path
-       set fd [open "| $cmd" r]
+       lappend options -- $path
+       set fd [eval git_read --nice blame $options]
        fconfigure $fd -blocking 0 -translation lf -encoding binary
        fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
        set current_fd $fd
@@ -767,7 +761,7 @@ method _showcommit {cur_w lno} {
                if {[catch {set msg $header($cmit,message)}]} {
                        set msg {}
                        catch {
-                               set fd [open "| git cat-file commit $cmit" r]
+                               set fd [git_read cat-file commit $cmit]
                                fconfigure $fd -encoding binary -translation lf
                                if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
                                        set enc utf-8
@@ -777,15 +771,20 @@ method _showcommit {cur_w lno} {
                                                set enc [string tolower [string range $line 9 end]]
                                        }
                                }
-                               set msg [encoding convertfrom $enc [read $fd]]
-                               set msg [string trim $msg]
+                               set msg [read $fd]
                                close $fd
 
-                               set author_name [encoding convertfrom $enc $author_name]
-                               set committer_name [encoding convertfrom $enc $committer_name]
-
-                               set header($cmit,author) $author_name
-                               set header($cmit,committer) $committer_name
+                               set enc [tcl_encoding $enc]
+                               if {$enc ne {}} {
+                                       set msg [encoding convertfrom $enc $msg]
+                                       set author_name [encoding convertfrom $enc $author_name]
+                                       set committer_name [encoding convertfrom $enc $committer_name]
+                                       set header($cmit,author) $author_name
+                                       set header($cmit,committer) $committer_name
+                                       set header($cmit,summary) \
+                                       [encoding convertfrom $enc $header($cmit,summary)]
+                               }
+                               set msg [string trim $msg]
                        }
                        set header($cmit,message) $msg
                }
@@ -880,6 +879,11 @@ method _open_tooltip {cur_w} {
                set org [lindex $amov_data $lno]
        }
 
+       if {$dat eq {}} {
+               _hide_tooltip $this
+               return
+       }
+
        set cmit [lindex $dat 0]
        set tooltip_commit [list $cmit]