From: Shawn O. Pearce Date: Mon, 29 Jan 2007 11:56:00 +0000 (-0500) Subject: git-gui: Assign background colors to each blame hunk. X-Git-Tag: gitgui-0.6.0~21 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=37f1db80a46cf753308bfc9b5de9dd3b3a551218;p=git.git git-gui: Assign background colors to each blame hunk. To help the user visually see which lines are associated with each other in the file we attempt to sign a unique background color to each commit and then render all text associated with that commit using that color. This works out OK for a file which has very few commits in it; but most files don't have that property. What we really need to do is look at what colors are used by our neighboring commits (if known yet) and pick a color which does not conflict with our neighbor. If we have run out of colors then we should force our neighbor to recolor too. Yes, its the graph coloring problem. Signed-off-by: Shawn O. Pearce --- diff --git a/git-gui.sh b/git-gui.sh index 1f13f7f9b..ef353319e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -3309,6 +3309,8 @@ proc show_blame {commit path} { " } + set blame_data($w,colors) {} + bind $w "focus $w" bind $w " array unset blame_status $w @@ -3366,6 +3368,15 @@ proc read_blame_incremental {fd w return } + set all [list \ + $w_commit \ + $w_author \ + $w_date \ + $w_filename \ + $w_olno \ + $w_lno \ + $w_file] + $w_commit conf -state normal $w_author conf -state normal $w_date conf -state normal @@ -3374,36 +3385,65 @@ proc read_blame_incremental {fd w while {[gets $fd line] >= 0} { if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \ - commit original_line final_line line_count]} { - set blame_data($w,commit) $commit + cmit original_line final_line line_count]} { + set blame_data($w,commit) $cmit set blame_data($w,original_line) $original_line set blame_data($w,final_line) $final_line set blame_data($w,line_count) $line_count + + if {[catch {set g $blame_data($w,$cmit,seen)}]} { + if {$blame_data($w,colors) eq {}} { + set blame_data($w,colors) { + yellow + red + pink + orange + green + grey + } + } + set c [lindex $blame_data($w,colors) 0] + set blame_data($w,colors) \ + [lrange $blame_data($w,colors) 1 end] + foreach t $all { + $t tag conf g$cmit -background $c + } + } else { + set blame_data($w,$cmit,seen) 1 + } } elseif {[string match {filename *} $line]} { set n $blame_data($w,line_count) set lno $blame_data($w,final_line) set ol $blame_data($w,original_line) set file [string range $line 9 end] - set commit $blame_data($w,commit) - set abbrev [string range $commit 0 8] + set cmit $blame_data($w,commit) + set abbrev [string range $cmit 0 8] - if {[catch {set author $blame_data($w,$commit,author)} err]} { - puts $err + if {[catch {set author $blame_data($w,$cmit,author)} err]} { set author {} } - if {[catch {set atime $blame_data($w,$commit,author-time)}]} { + if {[catch {set atime $blame_data($w,$cmit,author-time)}]} { set atime {} } else { set atime [clock format $atime -format {%Y-%m-%d %T}] } while {$n > 0} { - $w_commit delete $lno.0 "$lno.0 lineend" - $w_author delete $lno.0 "$lno.0 lineend" - $w_date delete $lno.0 "$lno.0 lineend" - $w_filename delete $lno.0 "$lno.0 lineend" - $w_olno delete $lno.0 "$lno.0 lineend" + if {![catch {set g g$blame_data($w,line$lno,commit)}]} { + foreach t $all { + $t tag remove $g $lno.0 "$lno.0 lineend + 1c" + } + } + + foreach t [list \ + $w_commit \ + $w_author \ + $w_date \ + $w_filename \ + $w_olno] { + $t delete $lno.0 "$lno.0 lineend" + } $w_commit insert $lno.0 $abbrev $w_author insert $lno.0 $author @@ -3411,7 +3451,12 @@ proc read_blame_incremental {fd w $w_filename insert $lno.0 $file $w_olno insert $lno.0 $ol linenumber - set blame_data($w,line$lno,commit) $commit + set g g$cmit + foreach t $all { + $t tag add $g $lno.0 "$lno.0 lineend + 1c" + } + + set blame_data($w,line$lno,commit) $cmit incr n -1 incr lno