Browse Source

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 <spearce@spearce.org>
maint
Shawn O. Pearce 18 years ago
parent
commit
37f1db80a4
  1. 71
      git-gui.sh

71
git-gui.sh

@ -3309,6 +3309,8 @@ proc show_blame {commit path} {
" "
} }


set blame_data($w,colors) {}

bind $w <Visibility> "focus $w" bind $w <Visibility> "focus $w"
bind $w <Destroy> " bind $w <Destroy> "
array unset blame_status $w array unset blame_status $w
@ -3366,6 +3368,15 @@ proc read_blame_incremental {fd w
return return
} }


set all [list \
$w_commit \
$w_author \
$w_date \
$w_filename \
$w_olno \
$w_lno \
$w_file]

$w_commit conf -state normal $w_commit conf -state normal
$w_author conf -state normal $w_author conf -state normal
$w_date conf -state normal $w_date conf -state normal
@ -3374,36 +3385,65 @@ proc read_blame_incremental {fd w


while {[gets $fd line] >= 0} { while {[gets $fd line] >= 0} {
if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \ if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
commit original_line final_line line_count]} { cmit original_line final_line line_count]} {
set blame_data($w,commit) $commit set blame_data($w,commit) $cmit
set blame_data($w,original_line) $original_line set blame_data($w,original_line) $original_line
set blame_data($w,final_line) $final_line set blame_data($w,final_line) $final_line
set blame_data($w,line_count) $line_count 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]} { } elseif {[string match {filename *} $line]} {
set n $blame_data($w,line_count) set n $blame_data($w,line_count)
set lno $blame_data($w,final_line) set lno $blame_data($w,final_line)
set ol $blame_data($w,original_line) set ol $blame_data($w,original_line)
set file [string range $line 9 end] set file [string range $line 9 end]
set commit $blame_data($w,commit) set cmit $blame_data($w,commit)
set abbrev [string range $commit 0 8] set abbrev [string range $cmit 0 8]


if {[catch {set author $blame_data($w,$commit,author)} err]} { if {[catch {set author $blame_data($w,$cmit,author)} err]} {
puts $err
set author {} set author {}
} }


if {[catch {set atime $blame_data($w,$commit,author-time)}]} { if {[catch {set atime $blame_data($w,$cmit,author-time)}]} {
set atime {} set atime {}
} else { } else {
set atime [clock format $atime -format {%Y-%m-%d %T}] set atime [clock format $atime -format {%Y-%m-%d %T}]
} }


while {$n > 0} { while {$n > 0} {
$w_commit delete $lno.0 "$lno.0 lineend" if {![catch {set g g$blame_data($w,line$lno,commit)}]} {
$w_author delete $lno.0 "$lno.0 lineend" foreach t $all {
$w_date delete $lno.0 "$lno.0 lineend" $t tag remove $g $lno.0 "$lno.0 lineend + 1c"
$w_filename delete $lno.0 "$lno.0 lineend" }
$w_olno delete $lno.0 "$lno.0 lineend" }

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_commit insert $lno.0 $abbrev
$w_author insert $lno.0 $author $w_author insert $lno.0 $author
@ -3411,7 +3451,12 @@ proc read_blame_incremental {fd w
$w_filename insert $lno.0 $file $w_filename insert $lno.0 $file
$w_olno insert $lno.0 $ol linenumber $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 n -1
incr lno incr lno

Loading…
Cancel
Save