git-gui: Allow creating a branch when none exists
[gitweb.git] / lib / blame.tcl
index 37ce3e7a86a828d35369f2e7b59a94456c13e637..8b032d959011f111c052fb4eee8be02aa6d45dd9 100644 (file)
@@ -166,12 +166,16 @@ constructor new {i_commit i_path} {
                bind $i <Control-Key-f> {catch {%W yview scroll  1 pages};break}
        }
 
-       bind $w.cm.t <Button-1> "focus $w.cm.t"
-       bind $top <Visibility> "focus $top"
+       bind $w.cm.t <Button-1> [list focus $w.cm.t]
+       bind $top <Visibility> [list focus $top]
        bind $top <Destroy> [list delete_this $this]
 
-       set cmd [list git cat-file blob "$commit:$path"]
-       set fd [open "| $cmd" r]
+       if {$commit eq {}} {
+               set fd [open $path r]
+       } else {
+               set cmd [list git cat-file blob "$commit:$path"]
+               set fd [open "| $cmd" r]
+       }
        fconfigure $fd -blocking 0 -translation lf -encoding binary
        fileevent $fd readable [cb _read_file $fd]
 }
@@ -194,7 +198,13 @@ method _read_file {fd} {
        if {[eof $fd]} {
                close $fd
                _status $this
-               set cmd [list git blame -M -C --incremental $commit -- $path]
+               set cmd [list git blame -M -C --incremental]
+               if {$commit eq {}} {
+                       lappend cmd --contents $path
+               } else {
+                       lappend cmd $commit
+               }
+               lappend cmd -- $path
                set fd [open "| $cmd" r]
                fconfigure $fd -blocking 0 -translation lf -encoding binary
                fileevent $fd readable [cb _read_blame $fd]
@@ -227,17 +237,18 @@ method _read_blame {fd} {
                        set cmit $r_commit
 
                        while {$n > 0} {
+                               set lno_e "$lno.0 lineend + 1c"
                                if {[catch {set g g$line_commit($lno)}]} {
-                                       $w_load tag add annotated $lno.0 "$lno.0 lineend + 1c"
+                                       $w_load tag add annotated $lno.0 $lno_e
                                } else {
-                                       $w_line tag remove g$g $lno.0 "$lno.0 lineend + 1c"
-                                       $w_file tag remove g$g $lno.0 "$lno.0 lineend + 1c"
+                                       $w_line tag remove g$g $lno.0 $lno_e
+                                       $w_file tag remove g$g $lno.0 $lno_e
                                }
 
                                set line_commit($lno) $cmit
                                set line_file($lno)   $file
-                               $w_line tag add g$cmit $lno.0 "$lno.0 lineend + 1c"
-                               $w_file tag add g$cmit $lno.0 "$lno.0 lineend + 1c"
+                               $w_line tag add g$cmit $lno.0 $lno_e
+                               $w_file tag add g$cmit $lno.0 $lno_e
 
                                if {$highlight_line == -1} {
                                        if {[lindex [$w_file yview] 0] == 0} {
@@ -286,10 +297,11 @@ method _click {cur_w pos} {
        set lno [lindex [split [$cur_w index $pos] .] 0]
        if {$lno eq {}} return
 
+       set lno_e "$lno.0 + 1 line"
        $w_line tag remove in_sel 0.0 end
        $w_file tag remove in_sel 0.0 end
-       $w_line tag add in_sel $lno.0 "$lno.0 + 1 line"
-       $w_file tag add in_sel $lno.0 "$lno.0 + 1 line"
+       $w_line tag add in_sel $lno.0 $lno_e
+       $w_file tag add in_sel $lno.0 $lno_e
 
        _showcommit $this $lno
 }
@@ -317,8 +329,7 @@ method _showcommit {lno} {
 
        $w_cmit conf -state normal
        $w_cmit delete 0.0 end
-       if {[catch {set cmit $line_commit($lno)} myerr]} {
-               puts "myerr = $myerr"
+       if {[catch {set cmit $line_commit($lno)}]} {
                set cmit {}
                $w_cmit insert end "Loading annotation..."
        } else {
@@ -336,14 +347,20 @@ method _showcommit {lno} {
                set author_time {}
                catch {set author_name $header($cmit,author)}
                catch {set author_email $header($cmit,author-mail)}
-               catch {set author_time [clock format $header($cmit,author-time)]}
+               catch {set author_time [clock format \
+                       $header($cmit,author-time) \
+                       -format {%Y-%m-%d %H:%M:%S}
+               ]}
 
                set committer_name {}
                set committer_email {}
                set committer_time {}
                catch {set committer_name $header($cmit,committer)}
                catch {set committer_email $header($cmit,committer-mail)}
-               catch {set committer_time [clock format $header($cmit,committer-time)]}
+               catch {set committer_time [clock format \
+                       $header($cmit,committer-time) \
+                       -format {%Y-%m-%d %H:%M:%S}
+               ]}
 
                if {[catch {set msg $header($cmit,message)}]} {
                        set msg {}
@@ -371,12 +388,12 @@ method _showcommit {lno} {
                        set header($cmit,message) $msg
                }
 
-               $w_cmit insert end "commit $cmit\n"
-               $w_cmit insert end "Author: $author_name $author_email $author_time\n"
-               $w_cmit insert end "Committer: $committer_name $committer_email $committer_time\n"
-               $w_cmit insert end "Original File: [escape_path $line_file($lno)]\n"
-               $w_cmit insert end "\n"
-               $w_cmit insert end $msg
+               $w_cmit insert end "commit $cmit
+Author: $author_name $author_email  $author_time
+Committer: $committer_name $committer_email  $committer_time
+Original File: [escape_path $line_file($lno)]
+
+$msg"
        }
        $w_cmit conf -state disabled