@matheusbsbs / matheus-bagliano / commits / 223475a77c
Fork 0

git-gui: Show author initials in blame groups

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>

Shawn O. Pearce committed Jun 1, 2007 at 16:10 UTC 223475a77c36919942c92f66c87b1e772a0ee2af
1 file changed +47 -11
lib/blame.tcl
+47 -11
@@ -294,16 +294,39 @@ method _read_blame {fd} {
294 set cmit $r_commit
295
296 if {[regexp {^0{40}$} $cmit]} {
297 - set abbr work
297 + set commit_abbr work
298 } else {
299 - set abbr [string range $cmit 0 4]
299 + set commit_abbr [string range $cmit 0 4]
300 }
301
302 - if {![catch {set ncmit $line_commit([expr {$lno - 1}])}]} {
303 - if {$ncmit eq $cmit} {
304 - set abbr { |}
302 + set author_abbr {}
303 + set a_name {}
304 + catch {set a_name $header($cmit,author)}
305 + while {$a_name ne {}} {
306 + if {![regexp {^([[:upper:]])} $a_name _a]} break
307 + append author_abbr $_a
308 + unset _a
309 + if {![regsub \
310 + {^[[:upper:]][^\s]*\s+} \
311 + $a_name {} a_name ]} break
312 + }
313 + if {$author_abbr eq {}} {
314 + set author_abbr { |}
315 + } else {
316 + set author_abbr [string range $author_abbr 0 3]
317 + while {[string length $author_abbr] < 4} {
318 + set author_abbr " $author_abbr"
319 }
320 }
321 + unset a_name
322 +
323 + set first_lno $lno
324 + while {
325 + ![catch {set ncmit $line_commit([expr {$first_lno - 1}])}]
326 + && $ncmit eq $cmit
327 + } {
328 + incr first_lno -1
329 + }
330
331 while {$n > 0} {
332 set lno_e "$lno.0 lineend + 1c"
@@ -323,8 +346,13 @@ method _read_blame {fd} {
346 set line_file($lno) $file
347
348 $w_cgrp delete $lno.0 "$lno.0 lineend"
326 - $w_cgrp insert $lno.0 $abbr
327 - set abbr { |}
349 + if {$lno == $first_lno} {
350 + $w_cgrp insert $lno.0 $commit_abbr
351 + } elseif {$lno == [expr {$first_lno + 1}]} {
352 + $w_cgrp insert $lno.0 $author_abbr
353 + } else {
354 + $w_cgrp insert $lno.0 { |}
355 + }
356
357 $w_cgrp tag add g$cmit $lno.0 $lno_e
358 $w_line tag add g$cmit $lno.0 $lno_e
@@ -348,12 +376,20 @@ method _read_blame {fd} {
376 incr blame_lines
377 }
378
351 - if {![catch {set ncmit $line_commit($lno)}]} {
352 - if {$ncmit eq $cmit} {
353 - $w_cgrp delete $lno.0 "$lno.0 lineend + 1c"
354 - $w_cgrp insert $lno.0 " |\n"
379 + while {![catch {set ncmit $line_commit($lno)}]
380 + && $ncmit eq $cmit} {
381 + $w_cgrp delete $lno.0 "$lno.0 lineend"
382 +
383 + if {$lno == $first_lno} {
384 + $w_cgrp insert $lno.0 $commit_abbr
385 + } elseif {$lno == [expr {$first_lno + 1}]} {
386 + $w_cgrp insert $lno.0 $author_abbr
387 + } else {
388 + $w_cgrp insert $lno.0 { |}
389 }
390 + incr lno
391 }
392 +
393 } elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
394 set header($r_commit,$key) $data
395 }