Skip to content

Commit 28593d3

Browse files
committed
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 <[email protected]>
1 parent d98d50e commit 28593d3

File tree

1 file changed

+58
-59
lines changed

1 file changed

+58
-59
lines changed

gitk

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,49 +4004,49 @@ proc ishighlighted {id} {
40044004
return 0
40054005
}
40064006

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
40094009

40104010
# need_redisplay = 1 means the display is stale and about to be redrawn
40114011
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} {
40154015
$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)] \
40174017
-outline {{}} -tags secsel \
40184018
-fill [$canv cget -selectbackground]]
40194019
$canv lower $t
40204020
}
40214021
}
40224022

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
40254025

40264026
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} {
40304030
$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)] \
40324032
-outline {{}} -tags secsel \
40334033
-fill [$canv2 cget -selectbackground]]
40344034
$canv2 lower $t
40354035
}
40364036
}
40374037

40384038
proc unbolden {} {
4039-
global boldrows
4039+
global boldids
40404040

40414041
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
40454045
} else {
4046-
lappend stillbold $row
4046+
lappend stillbold $id
40474047
}
40484048
}
4049-
set boldrows $stillbold
4049+
set boldids $stillbold
40504050
}
40514051

40524052
proc addvhighlight {n} {
@@ -4087,7 +4087,7 @@ proc vhighlightmore {} {
40874087
set row [rowofcommit $id]
40884088
if {$r0 <= $row && $row <= $r1} {
40894089
if {![highlighted $row]} {
4090-
bolden $row mainfontbold
4090+
bolden $id mainfontbold
40914091
}
40924092
set vhighlights($id) 1
40934093
}
@@ -4102,7 +4102,7 @@ proc askvhighlight {row id} {
41024102

41034103
if {[commitinview $id $hlview]} {
41044104
if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4105-
bolden $row mainfontbold
4105+
bolden $id mainfontbold
41064106
}
41074107
set vhighlights($id) 1
41084108
} else {
@@ -4170,15 +4170,15 @@ proc find_change {name ix op} {
41704170
}
41714171

41724172
proc findcom_change args {
4173-
global nhighlights boldnamerows
4173+
global nhighlights boldnameids
41744174
global findpattern findtype findstring gdttype
41754175

41764176
stopfinding
41774177
# delete previous highlights, if any
4178-
foreach row $boldnamerows {
4179-
bolden_name $row mainfont
4178+
foreach id $boldnameids {
4179+
bolden_name $id mainfont
41804180
}
4181-
set boldnamerows {}
4181+
set boldnameids {}
41824182
catch {unset nhighlights}
41834183
unbolden
41844184
unmarkmatches
@@ -4267,9 +4267,8 @@ proc readfhighlight {} {
42674267
set fhl_list [lrange $fhl_list [expr {$i+1}] end]
42684268
if {$line eq {}} continue
42694269
if {![commitinview $line $curview]} continue
4270-
set row [rowofcommit $line]
42714270
if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4272-
bolden $row mainfontbold
4271+
bolden $line mainfontbold
42734272
}
42744273
set fhighlights($line) 1
42754274
}
@@ -4321,9 +4320,9 @@ proc askfindhighlight {row id} {
43214320
}
43224321
if {$isbold && [info exists iddrawn($id)]} {
43234322
if {![ishighlighted $id]} {
4324-
bolden $row mainfontbold
4323+
bolden $id mainfontbold
43254324
if {$isbold > 1} {
4326-
bolden_name $row mainfontbold
4325+
bolden_name $id mainfontbold
43274326
}
43284327
}
43294328
if {$markingmatches} {
@@ -4343,15 +4342,15 @@ proc markrowmatches {row id} {
43434342
if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
43444343
set m [findmatches $headline]
43454344
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
43484347
}
43494348
}
43504349
if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
43514350
set m [findmatches $author]
43524351
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
43554354
}
43564355
}
43574356
}
@@ -4476,7 +4475,7 @@ proc askrelhighlight {row id} {
44764475
}
44774476
if {[info exists iddrawn($id)]} {
44784477
if {$isbold && ![ishighlighted $id]} {
4479-
bolden $row mainfontbold
4478+
bolden $id mainfontbold
44804479
}
44814480
}
44824481
set rhighlights($id) $isbold
@@ -5469,7 +5468,7 @@ proc drawcmittext {id row col} {
54695468
global cmitlisted commitinfo rowidlist parentlist
54705469
global rowtextx idpos idtags idheads idotherrefs
54715470
global linehtag linentag linedtag selectedline
5472-
global canvxmax boldrows boldnamerows fgcolor
5471+
global canvxmax boldids boldnameids fgcolor
54735472
global mainheadid nullid nullid2 circleitem circlecolors ctxbut
54745473

54755474
# 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} {
55345533
set nfont mainfont
55355534
set isbold [ishighlighted $id]
55365535
if {$isbold > 0} {
5537-
lappend boldrows $row
5536+
lappend boldids $id
55385537
set font mainfontbold
55395538
if {$isbold > 1} {
5540-
lappend boldnamerows $row
5539+
lappend boldnameids $id
55415540
set nfont mainfontbold
55425541
}
55435542
}
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]
55515550
if {$selectedline == $row} {
5552-
make_secsel $row
5551+
make_secsel $id
55535552
}
55545553
set xr [expr {$xt + [font measure $font $headline]}]
55555554
if {$xr > $canvxmax} {
@@ -5757,16 +5756,16 @@ proc drawvisible {} {
57575756
proc clear_display {} {
57585757
global iddrawn linesegs need_redisplay nrows_drawn
57595758
global vhighlights fhighlights nhighlights rhighlights
5760-
global linehtag linentag linedtag boldrows boldnamerows
5759+
global linehtag linentag linedtag boldids boldnameids
57615760

57625761
allcanvs delete all
57635762
catch {unset iddrawn}
57645763
catch {unset linesegs}
57655764
catch {unset linehtag}
57665765
catch {unset linentag}
57675766
catch {unset linedtag}
5768-
set boldrows {}
5769-
set boldnamerows {}
5767+
set boldids {}
5768+
set boldnameids {}
57705769
catch {unset vhighlights}
57715770
catch {unset fhighlights}
57725771
catch {unset nhighlights}
@@ -6474,20 +6473,20 @@ proc dispnexttag {} {
64746473
}
64756474
}
64766475

6477-
proc make_secsel {l} {
6476+
proc make_secsel {id} {
64786477
global linehtag linentag linedtag canv canv2 canv3
64796478

6480-
if {![info exists linehtag($l)]} return
6479+
if {![info exists linehtag($id)]} return
64816480
$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 {{}} \
64836482
-tags secsel -fill [$canv cget -selectbackground]]
64846483
$canv lower $t
64856484
$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 {{}} \
64876486
-tags secsel -fill [$canv2 cget -selectbackground]]
64886487
$canv2 lower $t
64896488
$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 {{}} \
64916490
-tags secsel -fill [$canv3 cget -selectbackground]]
64926491
$canv3 lower $t
64936492
}
@@ -6553,7 +6552,7 @@ proc selectline {l isnew {desired_loc {}}} {
65536552
drawvisible
65546553
}
65556554

6556-
make_secsel $l
6555+
make_secsel $id
65576556

65586557
if {$isnew} {
65596558
addtohistory [list selbyid $id]
@@ -8109,16 +8108,16 @@ proc redrawtags {id} {
81098108
$canv itemconf $circleitem($row) -fill $ofill
81108109
$canv delete tag.$id
81118110
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]
81158114
set xr [expr {$xt + [font measure $font $text]}]
81168115
if {$xr > $canvxmax} {
81178116
set canvxmax $xr
81188117
setcanvscroll
81198118
}
81208119
if {[info exists currentid] && $currentid == $id} {
8121-
make_secsel $row
8120+
make_secsel $id
81228121
}
81238122
}
81248123

@@ -10766,8 +10765,8 @@ set nhl_names {}
1076610765
set highlight_paths {}
1076710766
set findpattern {}
1076810767
set searchdirn -forwards
10769-
set boldrows {}
10770-
set boldnamerows {}
10768+
set boldids {}
10769+
set boldnameids {}
1077110770
set diffelide {0 0}
1077210771
set markingmatches 0
1077310772
set linkentercount 0

0 commit comments

Comments
 (0)