gitk: Index line[hnd]tag arrays by id rather than row number
This simplifies things a bit and is better because ids are stable but row numbers aren't. It also means we can avoid one [rowofcommit] call. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Nov 13, 2008 at 23:01 UTC
28593d3fa0e667bfccfe48e87a580db7c1a8d769
1 file changed
+58
-59
gitk
+58
-59
@@ -4004,31 +4004,31 @@ proc ishighlighted {id} {
4004
return 0
4005
}
4006
4007
-proc bolden {row font} {
4008
- global canv linehtag selectedline boldrows need_redisplay
4007
+proc bolden {id font} {
4008
+ global canv linehtag currentid boldids need_redisplay
4009
4010
# need_redisplay = 1 means the display is stale and about to be redrawn
4011
if {$need_redisplay} return
4012
- lappend boldrows $row
4013
- $canv itemconf $linehtag($row) -font $font
4014
- if {$row == $selectedline} {
4012
+ lappend boldids $id
4013
+ $canv itemconf $linehtag($id) -font $font
4014
+ if {[info exists currentid] && $id eq $currentid} {
4015
$canv delete secsel
4016
- set t [eval $canv create rect [$canv bbox $linehtag($row)] \
4016
+ set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4017
-outline {{}} -tags secsel \
4018
-fill [$canv cget -selectbackground]]
4019
$canv lower $t
4020
}
4021
}
4022
4023
-proc bolden_name {row font} {
4024
- global canv2 linentag selectedline boldnamerows need_redisplay
4023
+proc bolden_name {id font} {
4024
+ global canv2 linentag currentid boldnameids need_redisplay
4025
4026
if {$need_redisplay} return
4027
- lappend boldnamerows $row
4028
- $canv2 itemconf $linentag($row) -font $font
4029
- if {$row == $selectedline} {
4027
+ lappend boldnameids $id
4028
+ $canv2 itemconf $linentag($id) -font $font
4029
+ if {[info exists currentid] && $id eq $currentid} {
4030
$canv2 delete secsel
4031
- set t [eval $canv2 create rect [$canv2 bbox $linentag($row)] \
4031
+ set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4032
-outline {{}} -tags secsel \
4033
-fill [$canv2 cget -selectbackground]]
4034
$canv2 lower $t
@@ -4036,17 +4036,17 @@ proc bolden_name {row font} {
4036
}
4037
4038
proc unbolden {} {
4039
- global boldrows
4039
+ global boldids
4040
4041
set stillbold {}
4042
- foreach row $boldrows {
4043
- if {![ishighlighted [commitonrow $row]]} {
4044
- bolden $row mainfont
4042
+ foreach id $boldids {
4043
+ if {![ishighlighted $id]} {
4044
+ bolden $id mainfont
4045
} else {
4046
- lappend stillbold $row
4046
+ lappend stillbold $id
4047
}
4048
}
4049
- set boldrows $stillbold
4049
+ set boldids $stillbold
4050
}
4051
4052
proc addvhighlight {n} {
@@ -4087,7 +4087,7 @@ proc vhighlightmore {} {
4087
set row [rowofcommit $id]
4088
if {$r0 <= $row && $row <= $r1} {
4089
if {![highlighted $row]} {
4090
- bolden $row mainfontbold
4090
+ bolden $id mainfontbold
4091
}
4092
set vhighlights($id) 1
4093
}
@@ -4102,7 +4102,7 @@ proc askvhighlight {row id} {
4102
4103
if {[commitinview $id $hlview]} {
4104
if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4105
- bolden $row mainfontbold
4105
+ bolden $id mainfontbold
4106
}
4107
set vhighlights($id) 1
4108
} else {
@@ -4170,15 +4170,15 @@ proc find_change {name ix op} {
4170
}
4171
4172
proc findcom_change args {
4173
- global nhighlights boldnamerows
4173
+ global nhighlights boldnameids
4174
global findpattern findtype findstring gdttype
4175
4176
stopfinding
4177
# delete previous highlights, if any
4178
- foreach row $boldnamerows {
4179
- bolden_name $row mainfont
4178
+ foreach id $boldnameids {
4179
+ bolden_name $id mainfont
4180
}
4181
- set boldnamerows {}
4181
+ set boldnameids {}
4182
catch {unset nhighlights}
4183
unbolden
4184
unmarkmatches
@@ -4267,9 +4267,8 @@ proc readfhighlight {} {
4267
set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4268
if {$line eq {}} continue
4269
if {![commitinview $line $curview]} continue
4270
- set row [rowofcommit $line]
4270
if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4272
- bolden $row mainfontbold
4271
+ bolden $line mainfontbold
4272
}
4273
set fhighlights($line) 1
4274
}
@@ -4321,9 +4320,9 @@ proc askfindhighlight {row id} {
4320
}
4321
if {$isbold && [info exists iddrawn($id)]} {
4322
if {![ishighlighted $id]} {
4324
- bolden $row mainfontbold
4323
+ bolden $id mainfontbold
4324
if {$isbold > 1} {
4326
- bolden_name $row mainfontbold
4325
+ bolden_name $id mainfontbold
4326
}
4327
}
4328
if {$markingmatches} {
@@ -4343,15 +4342,15 @@ proc markrowmatches {row id} {
4342
if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4343
set m [findmatches $headline]
4344
if {$m ne {}} {
4346
- markmatches $canv $row $headline $linehtag($row) $m \
4347
- [$canv itemcget $linehtag($row) -font] $row
4345
+ markmatches $canv $row $headline $linehtag($id) $m \
4346
+ [$canv itemcget $linehtag($id) -font] $row
4347
}
4348
}
4349
if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4350
set m [findmatches $author]
4351
if {$m ne {}} {
4353
- markmatches $canv2 $row $author $linentag($row) $m \
4354
- [$canv2 itemcget $linentag($row) -font] $row
4352
+ markmatches $canv2 $row $author $linentag($id) $m \
4353
+ [$canv2 itemcget $linentag($id) -font] $row
4354
}
4355
}
4356
}
@@ -4476,7 +4475,7 @@ proc askrelhighlight {row id} {
4475
}
4476
if {[info exists iddrawn($id)]} {
4477
if {$isbold && ![ishighlighted $id]} {
4479
- bolden $row mainfontbold
4478
+ bolden $id mainfontbold
4479
}
4480
}
4481
set rhighlights($id) $isbold
@@ -5469,7 +5468,7 @@ proc drawcmittext {id row col} {
5468
global cmitlisted commitinfo rowidlist parentlist
5469
global rowtextx idpos idtags idheads idotherrefs
5470
global linehtag linentag linedtag selectedline
5472
- global canvxmax boldrows boldnamerows fgcolor
5471
+ global canvxmax boldids boldnameids fgcolor
5472
global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5473
5474
# listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
@@ -5534,22 +5533,22 @@ proc drawcmittext {id row col} {
5533
set nfont mainfont
5534
set isbold [ishighlighted $id]
5535
if {$isbold > 0} {
5537
- lappend boldrows $row
5536
+ lappend boldids $id
5537
set font mainfontbold
5538
if {$isbold > 1} {
5540
- lappend boldnamerows $row
5539
+ lappend boldnameids $id
5540
set nfont mainfontbold
5541
}
5542
}
5544
- set linehtag($row) [$canv create text $xt $y -anchor w -fill $fgcolor \
5545
- -text $headline -font $font -tags text]
5546
- $canv bind $linehtag($row) $ctxbut "rowmenu %X %Y $id"
5547
- set linentag($row) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
5548
- -text $name -font $nfont -tags text]
5549
- set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
5550
- -text $date -font mainfont -tags text]
5543
+ set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
5544
+ -text $headline -font $font -tags text]
5545
+ $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
5546
+ set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
5547
+ -text $name -font $nfont -tags text]
5548
+ set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
5549
+ -text $date -font mainfont -tags text]
5550
if {$selectedline == $row} {
5552
- make_secsel $row
5551
+ make_secsel $id
5552
}
5553
set xr [expr {$xt + [font measure $font $headline]}]
5554
if {$xr > $canvxmax} {
@@ -5757,7 +5756,7 @@ proc drawvisible {} {
5756
proc clear_display {} {
5757
global iddrawn linesegs need_redisplay nrows_drawn
5758
global vhighlights fhighlights nhighlights rhighlights
5760
- global linehtag linentag linedtag boldrows boldnamerows
5759
+ global linehtag linentag linedtag boldids boldnameids
5760
5761
allcanvs delete all
5762
catch {unset iddrawn}
@@ -5765,8 +5764,8 @@ proc clear_display {} {
5764
catch {unset linehtag}
5765
catch {unset linentag}
5766
catch {unset linedtag}
5768
- set boldrows {}
5769
- set boldnamerows {}
5767
+ set boldids {}
5768
+ set boldnameids {}
5769
catch {unset vhighlights}
5770
catch {unset fhighlights}
5771
catch {unset nhighlights}
@@ -6474,20 +6473,20 @@ proc dispnexttag {} {
6473
}
6474
}
6475
6477
-proc make_secsel {l} {
6476
+proc make_secsel {id} {
6477
global linehtag linentag linedtag canv canv2 canv3
6478
6480
- if {![info exists linehtag($l)]} return
6479
+ if {![info exists linehtag($id)]} return
6480
$canv delete secsel
6482
- set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
6481
+ set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
6482
-tags secsel -fill [$canv cget -selectbackground]]
6483
$canv lower $t
6484
$canv2 delete secsel
6486
- set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
6485
+ set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
6486
-tags secsel -fill [$canv2 cget -selectbackground]]
6487
$canv2 lower $t
6488
$canv3 delete secsel
6490
- set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
6489
+ set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
6490
-tags secsel -fill [$canv3 cget -selectbackground]]
6491
$canv3 lower $t
6492
}
@@ -6553,7 +6552,7 @@ proc selectline {l isnew {desired_loc {}}} {
6552
drawvisible
6553
}
6554
6556
- make_secsel $l
6555
+ make_secsel $id
6556
6557
if {$isnew} {
6558
addtohistory [list selbyid $id]
@@ -8109,16 +8108,16 @@ proc redrawtags {id} {
8108
$canv itemconf $circleitem($row) -fill $ofill
8109
$canv delete tag.$id
8110
set xt [eval drawtags $id $idpos($id)]
8112
- $canv coords $linehtag($row) $xt [lindex $idpos($id) 2]
8113
- set text [$canv itemcget $linehtag($row) -text]
8114
- set font [$canv itemcget $linehtag($row) -font]
8111
+ $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
8112
+ set text [$canv itemcget $linehtag($id) -text]
8113
+ set font [$canv itemcget $linehtag($id) -font]
8114
set xr [expr {$xt + [font measure $font $text]}]
8115
if {$xr > $canvxmax} {
8116
set canvxmax $xr
8117
setcanvscroll
8118
}
8119
if {[info exists currentid] && $currentid == $id} {
8121
- make_secsel $row
8120
+ make_secsel $id
8121
}
8122
}
8123
@@ -10766,8 +10765,8 @@ set nhl_names {}
10765
set highlight_paths {}
10766
set findpattern {}
10767
set searchdirn -forwards
10769
-set boldrows {}
10770
-set boldnamerows {}
10768
+set boldids {}
10769
+set boldnameids {}
10770
set diffelide {0 0}
10771
set markingmatches 0
10772
set linkentercount 0