Skip to content

Commit 66e46f3

Browse files
committed
gitk: Store ids in rowrangelist and idrowranges rather than row numbers
This removes the need for insertrow to go through rowrangelist and idrowranges and adjust a lot of entries. The first entry for a given id is now the row number of the first child, not that row number + 1, and rowranges compensates for that so its callers didn't have to change. This adds a ranges argument to drawlineseg so that we can avoid calling rowranges a second time inside drawlineseg (all its callers already called rowranges). Signed-off-by: Paul Mackerras <[email protected]>
1 parent 0060946 commit 66e46f3

File tree

1 file changed

+28
-48
lines changed

1 file changed

+28
-48
lines changed

gitk

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ proc sanity {row {full 0}} {
24722472
}
24732473

24742474
proc makeuparrow {oid x y z} {
2475-
global rowidlist rowoffsets uparrowlen idrowranges
2475+
global rowidlist rowoffsets uparrowlen idrowranges displayorder
24762476

24772477
for {set i 1} {$i < $uparrowlen && $y > 1} {incr i} {
24782478
incr y -1
@@ -2495,7 +2495,7 @@ proc makeuparrow {oid x y z} {
24952495
}
24962496
set tmp [lreplace [lindex $rowoffsets $y] $x $x {}]
24972497
lset rowoffsets $y [incrange $tmp [expr {$x+1}] -1]
2498-
lappend idrowranges($oid) $y
2498+
lappend idrowranges($oid) [lindex $displayorder $y]
24992499
}
25002500

25012501
proc initlayout {} {
@@ -2609,7 +2609,7 @@ proc layoutmore {tmax allread} {
26092609

26102610
proc showstuff {canshow} {
26112611
global numcommits commitrow pending_select selectedline
2612-
global linesegends idrowranges idrangedrawn curview
2612+
global linesegends idrangedrawn curview
26132613
global displayorder selectfirst
26142614

26152615
if {$numcommits == 0} {
@@ -2627,11 +2627,12 @@ proc showstuff {canshow} {
26272627
for {set r $row} {$r < $canshow} {incr r} {
26282628
foreach id [lindex $linesegends [expr {$r+1}]] {
26292629
set i -1
2630-
foreach {s e} [rowranges $id] {
2630+
set ranges [rowranges $id]
2631+
foreach {s e} $ranges {
26312632
incr i
26322633
if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0
26332634
&& ![info exists idrangedrawn($id,$i)]} {
2634-
drawlineseg $id $i
2635+
drawlineseg $id $i $ranges
26352636
set idrangedrawn($id,$i) 1
26362637
}
26372638
}
@@ -2698,7 +2699,7 @@ proc layoutrows {row endrow last} {
26982699
set idinlist($i) 0
26992700
set rm1 [expr {$row - 1}]
27002701
lappend lse $i
2701-
lappend idrowranges($i) $rm1
2702+
lappend idrowranges($i) [lindex $displayorder $rm1]
27022703
if {[incr nev -1] <= 0} break
27032704
continue
27042705
}
@@ -2730,7 +2731,7 @@ proc layoutrows {row endrow last} {
27302731
set ranges {}
27312732
if {[info exists idrowranges($id)]} {
27322733
set ranges $idrowranges($id)
2733-
lappend ranges $row
2734+
lappend ranges $id
27342735
unset idrowranges($id)
27352736
}
27362737
lappend rowrangelist $ranges
@@ -2755,7 +2756,7 @@ proc layoutrows {row endrow last} {
27552756
}
27562757
foreach i $newolds {
27572758
set idinlist($i) 1
2758-
set idrowranges($i) $row
2759+
set idrowranges($i) $id
27592760
}
27602761
incr col $l
27612762
foreach oid $oldolds {
@@ -2993,16 +2994,22 @@ proc rowranges {id} {
29932994
} elseif {[info exists idrowranges($id)]} {
29942995
set ranges $idrowranges($id)
29952996
}
2996-
return $ranges
2997+
set linenos {}
2998+
foreach rid $ranges {
2999+
lappend linenos $commitrow($curview,$rid)
3000+
}
3001+
if {$linenos ne {}} {
3002+
lset linenos 0 [expr {[lindex $linenos 0] + 1}]
3003+
}
3004+
return $linenos
29973005
}
29983006

2999-
proc drawlineseg {id i} {
3007+
proc drawlineseg {id i ranges} {
30003008
global rowoffsets rowidlist
30013009
global displayorder
30023010
global canv colormap linespc
30033011
global numcommits commitrow curview
30043012

3005-
set ranges [rowranges $id]
30063013
set downarrow 1
30073014
if {[info exists commitrow($curview,$id)]
30083015
&& $commitrow($curview,$id) < $numcommits} {
@@ -3132,10 +3139,11 @@ proc drawlines {id} {
31323139
global children iddrawn commitrow rowidlist curview
31333140

31343141
$canv delete lines.$id
3135-
set nr [expr {[llength [rowranges $id]] / 2}]
3142+
set ranges [rowranges $id]
3143+
set nr [expr {[llength $ranges] / 2}]
31363144
for {set i 0} {$i < $nr} {incr i} {
31373145
if {[info exists idrangedrawn($id,$i)]} {
3138-
drawlineseg $id $i
3146+
drawlineseg $id $i $ranges
31393147
}
31403148
}
31413149
foreach child $children($curview,$id) {
@@ -3216,13 +3224,14 @@ proc drawcmitrow {row} {
32163224
foreach id [lindex $rowidlist $row] {
32173225
if {$id eq {}} continue
32183226
set i -1
3219-
foreach {s e} [rowranges $id] {
3227+
set ranges [rowranges $id]
3228+
foreach {s e} $ranges {
32203229
incr i
32213230
if {$row < $s} continue
32223231
if {$e eq {}} break
32233232
if {$row <= $e} {
32243233
if {$e < $numcommits && ![info exists idrangedrawn($id,$i)]} {
3225-
drawlineseg $id $i
3234+
drawlineseg $id $i $ranges
32263235
set idrangedrawn($id,$i) 1
32273236
}
32283237
break
@@ -3528,7 +3537,7 @@ proc show_status {msg} {
35283537
proc insertrow {row newcmit} {
35293538
global displayorder parentlist childlist commitlisted
35303539
global commitrow curview rowidlist rowoffsets numcommits
3531-
global rowrangelist idrowranges rowlaidout rowoptim numcommits
3540+
global rowrangelist rowlaidout rowoptim numcommits
35323541
global linesegends selectedline
35333542

35343543
if {$row >= $numcommits} {
@@ -3572,45 +3581,16 @@ proc insertrow {row newcmit} {
35723581
set rowoffsets [linsert $rowoffsets [expr {$row+1}] $newoffs]
35733582

35743583
set rowrangelist [linsert $rowrangelist $row {}]
3575-
set l [llength $rowrangelist]
3576-
for {set r 0} {$r < $l} {incr r} {
3577-
set ranges [lindex $rowrangelist $r]
3578-
if {$ranges ne {} && [lindex $ranges end] >= $row} {
3579-
set newranges {}
3580-
foreach x $ranges {
3581-
if {$x >= $row} {
3582-
lappend newranges [expr {$x + 1}]
3583-
} else {
3584-
lappend newranges $x
3585-
}
3586-
}
3587-
lset rowrangelist $r $newranges
3588-
}
3589-
}
35903584
if {[llength $kids] > 1} {
35913585
set rp1 [expr {$row + 1}]
35923586
set ranges [lindex $rowrangelist $rp1]
35933587
if {$ranges eq {}} {
3594-
set ranges [list $row $rp1]
3595-
} elseif {[lindex $ranges end-1] == $rp1} {
3596-
lset ranges end-1 $row
3588+
set ranges [list $newcmit $p]
3589+
} elseif {[lindex $ranges end-1] eq $p} {
3590+
lset ranges end-1 $newcmit
35973591
}
35983592
lset rowrangelist $rp1 $ranges
35993593
}
3600-
foreach id [array names idrowranges] {
3601-
set ranges $idrowranges($id)
3602-
if {$ranges ne {} && [lindex $ranges end] >= $row} {
3603-
set newranges {}
3604-
foreach x $ranges {
3605-
if {$x >= $row} {
3606-
lappend newranges [expr {$x + 1}]
3607-
} else {
3608-
lappend newranges $x
3609-
}
3610-
}
3611-
set idrowranges($id) $newranges
3612-
}
3613-
}
36143594

36153595
set linesegends [linsert $linesegends $row {}]
36163596

0 commit comments

Comments
 (0)