summaryrefslogtreecommitdiff
path: root/lib/blame.tcl
diff options
context:
space:
mode:
authorLibravatar Shawn O. Pearce <spearce@spearce.org>2007-06-02 15:34:52 -0400
committerLibravatar Shawn O. Pearce <spearce@spearce.org>2007-06-06 01:26:50 -0400
commit14c4dfd3d1807885121b5e7b16610e335f824da4 (patch)
treee1d278375731b65e55df4e3b534454a6a4cb158e /lib/blame.tcl
parentgit-gui: Better document our blame variables (diff)
downloadtgif-14c4dfd3d1807885121b5e7b16610e335f824da4.tar.xz
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>
Diffstat (limited to 'lib/blame.tcl')
-rw-r--r--lib/blame.tcl121
1 files changed, 46 insertions, 75 deletions
diff --git a/lib/blame.tcl b/lib/blame.tcl
index 24965d9915..5fb3df4de7 100644
--- a/lib/blame.tcl
+++ b/lib/blame.tcl
@@ -15,6 +15,7 @@ field header ; # array commit,key -> header field
field w ; # top window in this viewer
field w_back ; # our back button
field w_path ; # label showing the current file path
+field w_columns ; # list of all column widgets in the viewer
field w_line ; # text column: all line numbers
field w_cgrp ; # text column: abbreviated commit SHA-1s
field w_file ; # text column: actual file data
@@ -39,6 +40,7 @@ field path ; # input filename to view in $commit
field current_fd {} ; # background process running
field highlight_line -1 ; # current line selected
field highlight_commit {} ; # sha1 of commit selected
+field old_bgcolor {} ; # background of current selection
field total_lines 0 ; # total length of file
field blame_lines 0 ; # number of lines computed
@@ -164,24 +166,23 @@ constructor new {i_commit i_path} {
-xscrollcommand [list $w.file_pane.out.sbx set] \
-font font_diff
+ set w_columns [list $w_cgrp $w_line $w_file]
+
scrollbar $w.file_pane.out.sbx \
-orient h \
-command [list $w_file xview]
scrollbar $w.file_pane.out.sby \
-orient v \
- -command [list scrollbar2many [list \
- $w_line \
- $w_cgrp \
- $w_file \
- ] yview]
- grid \
- $w_cgrp \
- $w_line \
- $w_file \
- $w.file_pane.out.sby \
- -sticky nsew
- grid conf $w.file_pane.out.sbx -column 2 -sticky we
- grid columnconfigure $w.file_pane.out 2 -weight 1
+ -command [list scrollbar2many $w_columns yview]
+ eval grid $w_columns $w.file_pane.out.sby -sticky nsew
+ grid conf \
+ $w.file_pane.out.sbx \
+ -column [expr {[llength $w_columns] - 1}] \
+ -sticky we
+ grid columnconfigure \
+ $w.file_pane.out \
+ [expr {[llength $w_columns] - 1}] \
+ -weight 1
grid rowconfigure $w.file_pane.out 0 -weight 1
set w_cmit $w.file_pane.cm.t
@@ -226,17 +227,10 @@ constructor new {i_commit i_path} {
-label "Copy Commit" \
-command [cb _copycommit]
- foreach i [list \
- $w_cgrp \
- $w_line \
- $w_file] {
+ foreach i $w_columns {
$i conf -cursor $cursor_ptr
- $i conf -yscrollcommand \
- [list many2scrollbar [list \
- $w_cgrp \
- $w_line \
- $w_file \
- ] yview $w.file_pane.out.sby]
+ $i conf -yscrollcommand [list many2scrollbar \
+ $w_columns yview $w.file_pane.out.sby]
bind $i <Button-1> "
[cb _hide_tooltip]
[cb _click $i @%x,%y]
@@ -254,11 +248,7 @@ constructor new {i_commit i_path} {
"
}
- foreach i [list \
- $w_cgrp \
- $w_line \
- $w_file \
- $w_cmit] {
+ foreach i [concat $w_columns $w_cmit] {
bind $i <Key-Up> {catch {%W yview scroll -1 units};break}
bind $i <Key-Down> {catch {%W yview scroll 1 units};break}
bind $i <Key-Left> {catch {%W xview scroll -1 units};break}
@@ -310,6 +300,15 @@ method _load {} {
set current_fd {}
}
+ foreach i $w_columns {
+ $i conf -state normal
+ $i delete 0.0 end
+ foreach cmit [array names have_commit] {
+ $i tag delete g$cmit
+ }
+ $i conf -state disabled
+ }
+
set highlight_line -1
set highlight_commit {}
set total_lines 0
@@ -317,18 +316,6 @@ method _load {} {
array unset have_commit
array unset line_commit
array unset line_file
-
- $w_cgrp conf -state normal
- $w_line conf -state normal
- $w_file conf -state normal
-
- $w_cgrp delete 0.0 end
- $w_line delete 0.0 end
- $w_file delete 0.0 end
-
- $w_cgrp conf -state disabled
- $w_line conf -state disabled
- $w_file conf -state disabled
}
if {[winfo exists $w.status.c]} {
@@ -410,17 +397,13 @@ method _read_file {fd} {
return
}
- $w_cgrp conf -state normal
- $w_line conf -state normal
- $w_file conf -state normal
+ foreach i $w_columns {$i conf -state normal}
while {[gets $fd line] >= 0} {
regsub "\r\$" $line {} line
incr total_lines
if {$total_lines > 1} {
- $w_cgrp insert end "\n"
- $w_line insert end "\n"
- $w_file insert end "\n"
+ foreach i $w_columns {$i insert end "\n"}
}
$w_line insert end "$total_lines" linenumber
@@ -432,9 +415,7 @@ method _read_file {fd} {
$w_line conf -width $ln_wc
}
- $w_cgrp conf -state disabled
- $w_line conf -state disabled
- $w_file conf -state disabled
+ foreach i $w_columns {$i conf -state disabled}
if {[eof $fd]} {
close $fd
@@ -473,11 +454,9 @@ method _read_blame {fd} {
set bg [lindex $group_colors 0]
set group_colors [lrange $group_colors 1 end]
lappend group_colors $bg
-
- $w_cgrp tag conf g$cmit -background $bg
- $w_line tag conf g$cmit -background $bg
- $w_file tag conf g$cmit -background $bg
-
+ foreach i $w_columns {
+ $i tag conf g$cmit -background $bg
+ }
set have_commit($cmit) 1
}
} elseif {[string match {filename *} $line]} {
@@ -531,13 +510,9 @@ method _read_blame {fd} {
while {$n > 0} {
set lno_e "$lno.0 lineend + 1c"
if {![catch {set g g$line_commit($lno)}]} {
- $w_cgrp tag remove g$g $lno.0 $lno_e
- $w_line tag remove g$g $lno.0 $lno_e
- $w_file tag remove g$g $lno.0 $lno_e
-
- $w_cgrp tag remove a$g $lno.0 $lno_e
- $w_line tag remove a$g $lno.0 $lno_e
- $w_file tag remove a$g $lno.0 $lno_e
+ foreach i $w_columns {
+ $i tag remove g$g $lno.0 $lno_e
+ }
}
set line_commit($lno) $cmit
@@ -552,13 +527,9 @@ method _read_blame {fd} {
$w_cgrp insert $lno.0 { |}
}
- $w_cgrp tag add g$cmit $lno.0 $lno_e
- $w_line tag add g$cmit $lno.0 $lno_e
- $w_file tag add g$cmit $lno.0 $lno_e
-
- $w_cgrp tag add a$cmit $lno.0 $lno_e
- $w_line tag add a$cmit $lno.0 $lno_e
- $w_file tag add a$cmit $lno.0 $lno_e
+ foreach i $w_columns {
+ $i tag add g$cmit $lno.0 $lno_e
+ }
if {$highlight_line == -1} {
if {[lindex [$w_file yview] 0] == 0} {
@@ -640,10 +611,9 @@ method _showcommit {lno} {
global repo_config
if {$highlight_commit ne {}} {
- set cmit $highlight_commit
- $w_cgrp tag conf a$cmit -background {}
- $w_line tag conf a$cmit -background {}
- $w_file tag conf a$cmit -background {}
+ foreach i $w_columns {
+ $i tag conf g$highlight_commit -background $old_bgcolor
+ }
}
$w_cmit conf -state normal
@@ -652,9 +622,10 @@ method _showcommit {lno} {
set cmit {}
$w_cmit insert end "Loading annotation..."
} else {
- $w_cgrp tag conf a$cmit -background $active_color
- $w_line tag conf a$cmit -background $active_color
- $w_file tag conf a$cmit -background $active_color
+ set old_bgcolor [$w_file tag cget g$cmit -background]
+ foreach i $w_columns {
+ $i tag conf g$cmit -background $active_color
+ }
set author_name {}
set author_email {}