git-gui: Show author initials in blame groups
[gitweb.git] / lib / blame.tcl
index fef28a347e84752f0357d061c95db307ad3caf8b..02e439cbc6a2c6aec238d1eb656ce26c594cbb3f 100644 (file)
@@ -43,6 +43,7 @@ variable group_colors {
 }
 
 constructor new {i_commit i_path} {
+       variable active_color
        global cursor_ptr
 
        set commit $i_commit
@@ -139,6 +140,14 @@ constructor new {i_commit i_path} {
                -xscrollcommand [list $w.cm.sbx set] \
                -yscrollcommand [list $w.cm.sby set] \
                -font font_diff
+       $w_cmit tag conf header_key \
+               -tabs {3c} \
+               -background $active_color \
+               -font font_uibold
+       $w_cmit tag conf header_val \
+               -background $active_color \
+               -font font_ui
+       $w_cmit tag raise sel
        scrollbar $w.cm.sbx -orient h -command [list $w_cmit xview]
        scrollbar $w.cm.sby -orient v -command [list $w_cmit yview]
        pack $w.cm.sby -side right -fill y
@@ -164,7 +173,7 @@ constructor new {i_commit i_path} {
                        $w_line \
                        $w_file \
                        ] yview $w.out.sby]
-               bind $i <Button-1>   "
+               bind $i <Button-1> "
                        [cb _hide_tooltip]
                        [cb _click $i @%x,%y]
                        focus $i
@@ -285,16 +294,39 @@ method _read_blame {fd} {
                        set cmit $r_commit
 
                        if {[regexp {^0{40}$} $cmit]} {
-                               set abbr work
+                               set commit_abbr work
                        } else {
-                               set abbr [string range $cmit 0 4]
+                               set commit_abbr [string range $cmit 0 4]
                        }
 
-                       if {![catch {set ncmit $line_commit([expr {$lno - 1}])}]} {
-                               if {$ncmit eq $cmit} {
-                                       set abbr |
+                       set author_abbr {}
+                       set a_name {}
+                       catch {set a_name $header($cmit,author)}
+                       while {$a_name ne {}} {
+                               if {![regexp {^([[:upper:]])} $a_name _a]} break
+                               append author_abbr $_a
+                               unset _a
+                               if {![regsub \
+                                       {^[[:upper:]][^\s]*\s+} \
+                                       $a_name {} a_name ]} break
+                       }
+                       if {$author_abbr eq {}} {
+                               set author_abbr { |}
+                       } else {
+                               set author_abbr [string range $author_abbr 0 3]
+                               while {[string length $author_abbr] < 4} {
+                                       set author_abbr " $author_abbr"
                                }
                        }
+                       unset a_name
+
+                       set first_lno $lno
+                       while {
+                       ![catch {set ncmit $line_commit([expr {$first_lno - 1}])}]
+                       && $ncmit eq $cmit
+                       } {
+                               incr first_lno -1
+                       }
 
                        while {$n > 0} {
                                set lno_e "$lno.0 lineend + 1c"
@@ -314,8 +346,13 @@ method _read_blame {fd} {
                                set line_file($lno)   $file
 
                                $w_cgrp delete $lno.0 "$lno.0 lineend"
-                               $w_cgrp insert $lno.0 $abbr
-                               set abbr |
+                               if {$lno == $first_lno} {
+                                       $w_cgrp insert $lno.0 $commit_abbr
+                               } elseif {$lno == [expr {$first_lno + 1}]} {
+                                       $w_cgrp insert $lno.0 $author_abbr
+                               } else {
+                                       $w_cgrp insert $lno.0 { |}
+                               }
 
                                $w_cgrp tag add g$cmit $lno.0 $lno_e
                                $w_line tag add g$cmit $lno.0 $lno_e
@@ -339,18 +376,20 @@ method _read_blame {fd} {
                                incr blame_lines
                        }
 
-                       if {![catch {set ncmit $line_commit($lno)}]} {
-                               if {$ncmit eq $cmit} {
-                                       $w_cgrp delete $lno.0 "$lno.0 lineend + 1c"
-                                       $w_cgrp insert $lno.0 "|\n"
+                       while {![catch {set ncmit $line_commit($lno)}]
+                               && $ncmit eq $cmit} {
+                               $w_cgrp delete $lno.0 "$lno.0 lineend"
+
+                               if {$lno == $first_lno} {
+                                       $w_cgrp insert $lno.0 $commit_abbr
+                               } elseif {$lno == [expr {$first_lno + 1}]} {
+                                       $w_cgrp insert $lno.0 $author_abbr
+                               } else {
+                                       $w_cgrp insert $lno.0 { |}
                                }
+                               incr lno
                        }
 
-                       set hc $highlight_commit
-                       if {$hc ne {}
-                               && [expr {$order($hc) + 1}] == $order($cmit)} {
-                               _showcommit $this $highlight_line
-                       }
                } elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
                        set header($r_commit,$key) $data
                }
@@ -449,12 +488,21 @@ method _showcommit {lno} {
                        set header($cmit,message) $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)]
+               $w_cmit insert end "commit $cmit\n" header_key
+               $w_cmit insert end "Author:\t" header_key
+               $w_cmit insert end "$author_name $author_email" header_val
+               $w_cmit insert end "$author_time\n" header_val
+
+               $w_cmit insert end "Committer:\t" header_key
+               $w_cmit insert end "$committer_name $committer_email" header_val
+               $w_cmit insert end "$committer_time\n" header_val
+
+               if {$line_file($lno) ne $path} {
+                       $w_cmit insert end "Original File:\t" header_key
+                       $w_cmit insert end "[escape_path $line_file($lno)]\n" header_val
+               }
 
-$msg"
+               $w_cmit insert end "\n$msg"
        }
        $w_cmit conf -state disabled