@matheusbsbs / matheus-bagliano / commits / 14c4dfd3d1
Fork 0

git-gui: Cleanup redundant column management in blame viewer

The code to handle our three different text widgets is a bit on the messy side as we issue the same command on all three widgets one at a time. Adding (or removing) columns from the viewer is messy, as a lot of locations need to have the new column added into the sequence, or removed from it. We also now delete the tags we create for each commit when we switch to display another "commit:path" pair. This way the text viewer doesn't get bogged down with a massive number of tags as we traverse through history. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jun 2, 2007 at 15:34 UTC 14c4dfd3d1807885121b5e7b16610e335f824da4
1 file changed +46 -75
lib/blame.tcl
+46 -75
@@ -15,6 +15,7 @@ field header ; # array commit,key -> header field
15 field w ; # top window in this viewer
16 field w_back ; # our back button
17 field w_path ; # label showing the current file path
18 +field w_columns ; # list of all column widgets in the viewer
19 field w_line ; # text column: all line numbers
20 field w_cgrp ; # text column: abbreviated commit SHA-1s
21 field w_file ; # text column: actual file data
@@ -39,6 +40,7 @@ field path ; # input filename to view in $commit
40 field current_fd {} ; # background process running
41 field highlight_line -1 ; # current line selected
42 field highlight_commit {} ; # sha1 of commit selected
43 +field old_bgcolor {} ; # background of current selection
44
45 field total_lines 0 ; # total length of file
46 field blame_lines 0 ; # number of lines computed
@@ -164,24 +166,23 @@ constructor new {i_commit i_path} {
166 -xscrollcommand [list $w.file_pane.out.sbx set] \
167 -font font_diff
168
169 + set w_columns [list $w_cgrp $w_line $w_file]
170 +
171 scrollbar $w.file_pane.out.sbx \
172 -orient h \
173 -command [list $w_file xview]
174 scrollbar $w.file_pane.out.sby \
175 -orient v \
172 - -command [list scrollbar2many [list \
173 - $w_line \
174 - $w_cgrp \
175 - $w_file \
176 - ] yview]
177 - grid \
178 - $w_cgrp \
179 - $w_line \
180 - $w_file \
181 - $w.file_pane.out.sby \
182 - -sticky nsew
183 - grid conf $w.file_pane.out.sbx -column 2 -sticky we
184 - grid columnconfigure $w.file_pane.out 2 -weight 1
176 + -command [list scrollbar2many $w_columns yview]
177 + eval grid $w_columns $w.file_pane.out.sby -sticky nsew
178 + grid conf \
179 + $w.file_pane.out.sbx \
180 + -column [expr {[llength $w_columns] - 1}] \
181 + -sticky we
182 + grid columnconfigure \
183 + $w.file_pane.out \
184 + [expr {[llength $w_columns] - 1}] \
185 + -weight 1
186 grid rowconfigure $w.file_pane.out 0 -weight 1
187
188 set w_cmit $w.file_pane.cm.t
@@ -226,17 +227,10 @@ constructor new {i_commit i_path} {
227 -label "Copy Commit" \
228 -command [cb _copycommit]
229
229 - foreach i [list \
230 - $w_cgrp \
231 - $w_line \
232 - $w_file] {
230 + foreach i $w_columns {
231 $i conf -cursor $cursor_ptr
234 - $i conf -yscrollcommand \
235 - [list many2scrollbar [list \
236 - $w_cgrp \
237 - $w_line \
238 - $w_file \
239 - ] yview $w.file_pane.out.sby]
232 + $i conf -yscrollcommand [list many2scrollbar \
233 + $w_columns yview $w.file_pane.out.sby]
234 bind $i <Button-1> "
235 [cb _hide_tooltip]
236 [cb _click $i @%x,%y]
@@ -254,11 +248,7 @@ constructor new {i_commit i_path} {
248 "
249 }
250
257 - foreach i [list \
258 - $w_cgrp \
259 - $w_line \
260 - $w_file \
261 - $w_cmit] {
251 + foreach i [concat $w_columns $w_cmit] {
252 bind $i <Key-Up> {catch {%W yview scroll -1 units};break}
253 bind $i <Key-Down> {catch {%W yview scroll 1 units};break}
254 bind $i <Key-Left> {catch {%W xview scroll -1 units};break}
@@ -310,6 +300,15 @@ method _load {} {
300 set current_fd {}
301 }
302
303 + foreach i $w_columns {
304 + $i conf -state normal
305 + $i delete 0.0 end
306 + foreach cmit [array names have_commit] {
307 + $i tag delete g$cmit
308 + }
309 + $i conf -state disabled
310 + }
311 +
312 set highlight_line -1
313 set highlight_commit {}
314 set total_lines 0
@@ -317,18 +316,6 @@ method _load {} {
316 array unset have_commit
317 array unset line_commit
318 array unset line_file
320 -
321 - $w_cgrp conf -state normal
322 - $w_line conf -state normal
323 - $w_file conf -state normal
324 -
325 - $w_cgrp delete 0.0 end
326 - $w_line delete 0.0 end
327 - $w_file delete 0.0 end
328 -
329 - $w_cgrp conf -state disabled
330 - $w_line conf -state disabled
331 - $w_file conf -state disabled
319 }
320
321 if {[winfo exists $w.status.c]} {
@@ -410,17 +397,13 @@ method _read_file {fd} {
397 return
398 }
399
413 - $w_cgrp conf -state normal
414 - $w_line conf -state normal
415 - $w_file conf -state normal
400 + foreach i $w_columns {$i conf -state normal}
401 while {[gets $fd line] >= 0} {
402 regsub "\r\$" $line {} line
403 incr total_lines
404
405 if {$total_lines > 1} {
421 - $w_cgrp insert end "\n"
422 - $w_line insert end "\n"
423 - $w_file insert end "\n"
406 + foreach i $w_columns {$i insert end "\n"}
407 }
408
409 $w_line insert end "$total_lines" linenumber
@@ -432,9 +415,7 @@ method _read_file {fd} {
415 $w_line conf -width $ln_wc
416 }
417
435 - $w_cgrp conf -state disabled
436 - $w_line conf -state disabled
437 - $w_file conf -state disabled
418 + foreach i $w_columns {$i conf -state disabled}
419
420 if {[eof $fd]} {
421 close $fd
@@ -473,11 +454,9 @@ method _read_blame {fd} {
454 set bg [lindex $group_colors 0]
455 set group_colors [lrange $group_colors 1 end]
456 lappend group_colors $bg
476 -
477 - $w_cgrp tag conf g$cmit -background $bg
478 - $w_line tag conf g$cmit -background $bg
479 - $w_file tag conf g$cmit -background $bg
480 -
457 + foreach i $w_columns {
458 + $i tag conf g$cmit -background $bg
459 + }
460 set have_commit($cmit) 1
461 }
462 } elseif {[string match {filename *} $line]} {
@@ -531,13 +510,9 @@ method _read_blame {fd} {
510 while {$n > 0} {
511 set lno_e "$lno.0 lineend + 1c"
512 if {![catch {set g g$line_commit($lno)}]} {
534 - $w_cgrp tag remove g$g $lno.0 $lno_e
535 - $w_line tag remove g$g $lno.0 $lno_e
536 - $w_file tag remove g$g $lno.0 $lno_e
537 -
538 - $w_cgrp tag remove a$g $lno.0 $lno_e
539 - $w_line tag remove a$g $lno.0 $lno_e
540 - $w_file tag remove a$g $lno.0 $lno_e
513 + foreach i $w_columns {
514 + $i tag remove g$g $lno.0 $lno_e
515 + }
516 }
517
518 set line_commit($lno) $cmit
@@ -552,13 +527,9 @@ method _read_blame {fd} {
527 $w_cgrp insert $lno.0 { |}
528 }
529
555 - $w_cgrp tag add g$cmit $lno.0 $lno_e
556 - $w_line tag add g$cmit $lno.0 $lno_e
557 - $w_file tag add g$cmit $lno.0 $lno_e
558 -
559 - $w_cgrp tag add a$cmit $lno.0 $lno_e
560 - $w_line tag add a$cmit $lno.0 $lno_e
561 - $w_file tag add a$cmit $lno.0 $lno_e
530 + foreach i $w_columns {
531 + $i tag add g$cmit $lno.0 $lno_e
532 + }
533
534 if {$highlight_line == -1} {
535 if {[lindex [$w_file yview] 0] == 0} {
@@ -640,10 +611,9 @@ method _showcommit {lno} {
611 global repo_config
612
613 if {$highlight_commit ne {}} {
643 - set cmit $highlight_commit
644 - $w_cgrp tag conf a$cmit -background {}
645 - $w_line tag conf a$cmit -background {}
646 - $w_file tag conf a$cmit -background {}
614 + foreach i $w_columns {
615 + $i tag conf g$highlight_commit -background $old_bgcolor
616 + }
617 }
618
619 $w_cmit conf -state normal
@@ -652,9 +622,10 @@ method _showcommit {lno} {
622 set cmit {}
623 $w_cmit insert end "Loading annotation..."
624 } else {
655 - $w_cgrp tag conf a$cmit -background $active_color
656 - $w_line tag conf a$cmit -background $active_color
657 - $w_file tag conf a$cmit -background $active_color
625 + set old_bgcolor [$w_file tag cget g$cmit -background]
626 + foreach i $w_columns {
627 + $i tag conf g$cmit -background $active_color
628 + }
629
630 set author_name {}
631 set author_email {}