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>
Shawn O. Pearce committed
Jan 29, 2007 at 06:56 UTC
37f1db80a46cf753308bfc9b5de9dd3b3a551218
1 file changed
+58
-13
git-gui.sh
+58
-13
@@ -3309,6 +3309,8 @@ proc show_blame {commit path} {
3309
"
3310
}
3311
3312
+ set blame_data($w,colors) {}
3313
+
3314
bind $w <Visibility> "focus $w"
3315
bind $w <Destroy> "
3316
array unset blame_status $w
@@ -3366,6 +3368,15 @@ proc read_blame_incremental {fd w
3368
return
3369
}
3370
3371
+ set all [list \
3372
+ $w_commit \
3373
+ $w_author \
3374
+ $w_date \
3375
+ $w_filename \
3376
+ $w_olno \
3377
+ $w_lno \
3378
+ $w_file]
3379
+
3380
$w_commit conf -state normal
3381
$w_author conf -state normal
3382
$w_date conf -state normal
@@ -3374,36 +3385,65 @@ proc read_blame_incremental {fd w
3385
3386
while {[gets $fd line] >= 0} {
3387
if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
3377
- commit original_line final_line line_count]} {
3378
- set blame_data($w,commit) $commit
3388
+ cmit original_line final_line line_count]} {
3389
+ set blame_data($w,commit) $cmit
3390
set blame_data($w,original_line) $original_line
3391
set blame_data($w,final_line) $final_line
3392
set blame_data($w,line_count) $line_count
3393
+
3394
+ if {[catch {set g $blame_data($w,$cmit,seen)}]} {
3395
+ if {$blame_data($w,colors) eq {}} {
3396
+ set blame_data($w,colors) {
3397
+ yellow
3398
+ red
3399
+ pink
3400
+ orange
3401
+ green
3402
+ grey
3403
+ }
3404
+ }
3405
+ set c [lindex $blame_data($w,colors) 0]
3406
+ set blame_data($w,colors) \
3407
+ [lrange $blame_data($w,colors) 1 end]
3408
+ foreach t $all {
3409
+ $t tag conf g$cmit -background $c
3410
+ }
3411
+ } else {
3412
+ set blame_data($w,$cmit,seen) 1
3413
+ }
3414
} elseif {[string match {filename *} $line]} {
3415
set n $blame_data($w,line_count)
3416
set lno $blame_data($w,final_line)
3417
set ol $blame_data($w,original_line)
3418
set file [string range $line 9 end]
3387
- set commit $blame_data($w,commit)
3388
- set abbrev [string range $commit 0 8]
3419
+ set cmit $blame_data($w,commit)
3420
+ set abbrev [string range $cmit 0 8]
3421
3390
- if {[catch {set author $blame_data($w,$commit,author)} err]} {
3391
- puts $err
3422
+ if {[catch {set author $blame_data($w,$cmit,author)} err]} {
3423
set author {}
3424
}
3425
3395
- if {[catch {set atime $blame_data($w,$commit,author-time)}]} {
3426
+ if {[catch {set atime $blame_data($w,$cmit,author-time)}]} {
3427
set atime {}
3428
} else {
3429
set atime [clock format $atime -format {%Y-%m-%d %T}]
3430
}
3431
3432
while {$n > 0} {
3402
- $w_commit delete $lno.0 "$lno.0 lineend"
3403
- $w_author delete $lno.0 "$lno.0 lineend"
3404
- $w_date delete $lno.0 "$lno.0 lineend"
3405
- $w_filename delete $lno.0 "$lno.0 lineend"
3406
- $w_olno delete $lno.0 "$lno.0 lineend"
3433
+ if {![catch {set g g$blame_data($w,line$lno,commit)}]} {
3434
+ foreach t $all {
3435
+ $t tag remove $g $lno.0 "$lno.0 lineend + 1c"
3436
+ }
3437
+ }
3438
+
3439
+ foreach t [list \
3440
+ $w_commit \
3441
+ $w_author \
3442
+ $w_date \
3443
+ $w_filename \
3444
+ $w_olno] {
3445
+ $t delete $lno.0 "$lno.0 lineend"
3446
+ }
3447
3448
$w_commit insert $lno.0 $abbrev
3449
$w_author insert $lno.0 $author
@@ -3411,7 +3451,12 @@ proc read_blame_incremental {fd w
3451
$w_filename insert $lno.0 $file
3452
$w_olno insert $lno.0 $ol linenumber
3453
3414
- set blame_data($w,line$lno,commit) $commit
3454
+ set g g$cmit
3455
+ foreach t $all {
3456
+ $t tag add $g $lno.0 "$lno.0 lineend + 1c"
3457
+ }
3458
+
3459
+ set blame_data($w,line$lno,commit) $cmit
3460
3461
incr n -1
3462
incr lno