@matheusbsbs / matheus-bagliano / commits / 5d198d6766
Fork 0

git-gui: Use three colors for the blame viewer background

To prevent neighboring lines that are different commits from using the same background color we now use 3 colors and assign them by selecting the color that is not used before or after the line in question. We still color "on the fly" as we receive hunks from git-blame, but we delay our color decisions until we are getting the original location data (the slower -M -C -C pass) as that is usually more fine-grained than the current location data. Credit goes to Martin Waitz for the tri-coloring concept. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jun 6, 2007 at 02:53 UTC 5d198d676667ecd3beeac816049bfc777b9c8566
1 file changed +61 -19
lib/blame.tcl
+61 -19
@@ -26,8 +26,8 @@ field old_height ; # last known height of $w.file_pane
26
27 # Tk UI colors
28 #
29 -field active_color #c0edc5
30 -field group_colors {
29 +variable active_color #c0edc5
30 +variable group_colors {
31 #d6d6d6
32 #e1e1e1
33 #ececec
@@ -42,11 +42,9 @@ field current_fd {} ; # background process running
42 field highlight_line -1 ; # current line selected
43 field highlight_column {} ; # current commit column selected
44 field highlight_commit {} ; # sha1 of commit selected
45 -field old_bgcolor {} ; # background of current selection
45
46 field total_lines 0 ; # total length of file
47 field blame_lines 0 ; # number of lines computed
49 -field have_commit ; # array commit -> 1
48 field amov_data ; # list of {commit origfile origline}
49 field asim_data ; # list of {commit origfile origline}
50
@@ -62,6 +60,8 @@ field tooltip_commit {} ; # Commit(s) in tooltip
60
61 constructor new {i_commit i_path} {
62 global cursor_ptr
63 + variable active_color
64 + variable group_colors
65
66 set commit $i_commit
67 set path $i_path
@@ -250,6 +250,10 @@ constructor new {i_commit i_path} {
250 -command [cb _copycommit]
251
252 foreach i $w_columns {
253 + for {set g 0} {$g < [llength $group_colors]} {incr g} {
254 + $i tag conf color$g -background [lindex $group_colors $g]
255 + }
256 +
257 $i conf -cursor $cursor_ptr
258 $i conf -yscrollcommand [list many2scrollbar \
259 $w_columns yview $w.file_pane.out.sby]
@@ -314,6 +318,8 @@ constructor new {i_commit i_path} {
318 }
319
320 method _load {jump} {
321 + variable group_colors
322 +
323 _hide_tooltip $this
324
325 if {$total_lines != 0 || $current_fd ne {}} {
@@ -325,8 +331,10 @@ method _load {jump} {
331 foreach i $w_columns {
332 $i conf -state normal
333 $i delete 0.0 end
328 - foreach cmit [array names have_commit] {
329 - $i tag delete g$cmit
334 + foreach g [$i tag names] {
335 + if {[regexp {^g[0-9a-f]{40}$} $g]} {
336 + $i tag delete $g
337 + }
338 }
339 $i conf -state disabled
340 }
@@ -339,7 +347,6 @@ method _load {jump} {
347 set highlight_column {}
348 set highlight_commit {}
349 set total_lines 0
342 - array unset have_commit
350 }
351
352 if {[winfo exists $w.status.c]} {
@@ -494,6 +501,7 @@ method _exec_blame {cur_w cur_d options cur_s} {
501
502 method _read_blame {fd cur_w cur_d cur_s} {
503 upvar #0 $cur_d line_data
504 + variable group_colors
505
506 if {$fd ne $current_fd} {
507 catch {close $fd}
@@ -508,16 +516,6 @@ method _read_blame {fd cur_w cur_d cur_s} {
516 set r_orig_line $original_line
517 set r_final_line $final_line
518 set r_line_count $line_count
511 -
512 - if {[catch {set g $have_commit($cmit)}]} {
513 - set bg [lindex $group_colors 0]
514 - set group_colors [lrange $group_colors 1 end]
515 - lappend group_colors $bg
516 - foreach i $w_columns {
517 - $i tag conf g$cmit -background $bg
518 - }
519 - set have_commit($cmit) 1
520 - }
519 } elseif {[string match {filename *} $line]} {
520 set file [string range $line 9 end]
521 set n $r_line_count
@@ -563,6 +561,30 @@ method _read_blame {fd cur_w cur_d cur_s} {
561 incr first_lno -1
562 }
563
564 + set color {}
565 + if {$first_lno < $lno} {
566 + foreach g [$w_file tag names $first_lno.0] {
567 + if {[regexp {^color[0-9]+$} $g]} {
568 + set color $g
569 + break
570 + }
571 + }
572 + } else {
573 + set i [lsort [concat \
574 + [$w_file tag names "[expr {$first_lno - 1}].0"] \
575 + [$w_file tag names "[expr {$lno + $n}].0"] \
576 + ]]
577 + for {set g 0} {$g < [llength $group_colors]} {incr g} {
578 + if {[lsearch -sorted -exact $i color$g] == -1} {
579 + set color color$g
580 + break
581 + }
582 + }
583 + }
584 + if {$color eq {}} {
585 + set color color0
586 + }
587 +
588 while {$n > 0} {
589 set lno_e "$lno.0 lineend + 1c"
590 if {[lindex $line_data $lno] ne {}} {
@@ -583,6 +605,14 @@ method _read_blame {fd cur_w cur_d cur_s} {
605 }
606
607 foreach i $w_columns {
608 + if {$cur_w eq $w_amov} {
609 + for {set g 0} \
610 + {$g < [llength $group_colors]} \
611 + {incr g} {
612 + $i tag remove color$g $lno.0 $lno_e
613 + }
614 + $i tag add $color $lno.0 $lno_e
615 + }
616 $i tag add g$cmit $lno.0 $lno_e
617 }
618
@@ -616,6 +646,18 @@ method _read_blame {fd cur_w cur_d cur_s} {
646 } else {
647 $cur_w insert $lno.0 { |}
648 }
649 +
650 + if {$cur_w eq $w_amov} {
651 + foreach i $w_columns {
652 + for {set g 0} \
653 + {$g < [llength $group_colors]} \
654 + {incr g} {
655 + $i tag remove color$g $lno.0 $lno_e
656 + }
657 + $i tag add $color $lno.0 $lno_e
658 + }
659 + }
660 +
661 incr lno
662 }
663
@@ -678,10 +720,11 @@ method _load_commit {cur_w cur_d pos} {
720
721 method _showcommit {cur_w lno} {
722 global repo_config
723 + variable active_color
724
725 if {$highlight_commit ne {}} {
726 foreach i $w_columns {
684 - $i tag conf g$highlight_commit -background $old_bgcolor
727 + $i tag conf g$highlight_commit -background {}
728 $i tag lower g$highlight_commit
729 }
730 }
@@ -704,7 +747,6 @@ method _showcommit {cur_w lno} {
747 set cmit [lindex $dat 0]
748 set file [lindex $dat 1]
749
707 - set old_bgcolor [$w_file tag cget g$cmit -background]
750 foreach i $w_columns {
751 $i tag conf g$cmit -background $active_color
752 $i tag raise g$cmit