Skip to content

Commit

Permalink
git-gui: Show author initials in blame groups
Browse files Browse the repository at this point in the history
Frequently when I'm looking at blocks of code in the blame
viewer I want to know who is the culprit, or who I should
be praising for a job well done.  The tooltips nicely show
this if I mouse over a block, but it doesn't work to get
this detail at a glance.

Since we don't use the leftmost commit column for anything
after the first line within a commit group I'm now tossing
the author's initials into that field, right justified.  It
is quite clearly not a SHA-1 number as we always show the
SHA-1 in lowercase, while we explicitly select only the
uppercase characters from an author's name field, and only
those that are following whitespace.

I'm using initials here over anything else as they are quite
commonly unique within small development teams.  The leading
part of the email address field was out for some of the teams
I work with, as there the email addresses are all of the form
"Givenname.Surname@initech.com".  That will never fit into the
4 characters available.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
spearce committed Jun 6, 2007
1 parent ddc1fa8 commit 223475a
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions lib/blame.tcl
Expand Up @@ -294,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"
Expand All @@ -323,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
Expand All @@ -348,12 +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
}

} elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
set header($r_commit,$key) $data
}
Expand Down

0 comments on commit 223475a

Please sign in to comment.