gitk: Get rid of idinlist array
This changes layoutrows to use information from rowidlist and children to work out which parent ids are appearing for the first time or need an up arrow, instead of using idinlist. To detect the situation where git log doesn't give us all the commits it references, this adds an idpending array that is updated and used by getcommitlines. This also fixes a bug where we weren't resetting the ordertok array when updating the list of commits; this fixes that too, and a bug where we could try to access an undefined element of commitrow if the user did an update before gitk had finished reading in the graph. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Aug 23, 2007 at 19:35 UTC
b0cdca996a3717552ee30e8cc2bd157bb32fd213
1 file changed
+46
-38
gitk
+46
-38
@@ -151,7 +151,7 @@ proc getcommitlines {fd view} {
151
global displayorder commitidx commitrow commitdata
152
global parentlist children curview hlview
153
global vparentlist vdisporder vcmitlisted
154
- global ordertok vnextroot
154
+ global ordertok vnextroot idpending
155
156
set stuff [read $fd 500000]
157
# git log doesn't terminate the last commit with a null...
@@ -162,6 +162,23 @@ proc getcommitlines {fd view} {
162
if {![eof $fd]} {
163
return 1
164
}
165
+ # Check if we have seen any ids listed as parents that haven't
166
+ # appeared in the list
167
+ foreach vid [array names idpending "$view,*"] {
168
+ # should only get here if git log is buggy
169
+ set id [lindex [split $vid ","] 1]
170
+ set commitrow($vid) $commitidx($view)
171
+ incr commitidx($view)
172
+ if {$view == $curview} {
173
+ lappend parentlist {}
174
+ lappend displayorder $id
175
+ lappend commitlisted 0
176
+ } else {
177
+ lappend vparentlist($view) {}
178
+ lappend vdisporder($view) $id
179
+ lappend vcmitlisted($view) 0
180
+ }
181
+ }
182
global viewname
183
unset commfd($view)
184
notbusy $view
@@ -242,6 +259,7 @@ proc getcommitlines {fd view} {
259
set ordertok($view,$id) $otok
260
} else {
261
set otok $ordertok($view,$id)
262
+ unset idpending($view,$id)
263
}
264
if {$listed} {
265
set olds [lrange $ids 1 end]
@@ -250,6 +268,7 @@ proc getcommitlines {fd view} {
268
lappend children($view,$p) $id
269
if {![info exists ordertok($view,$p)]} {
270
set ordertok($view,$p) $ordertok($view,$id)
271
+ set idpending($view,$p) 1
272
}
273
} else {
274
set i 0
@@ -259,6 +278,7 @@ proc getcommitlines {fd view} {
278
}
279
if {![info exists ordertok($view,$p)]} {
280
set ordertok($view,$p) "$otok[strrep $i]]"
281
+ set idpending($view,$p) 1
282
}
283
incr i
284
}
@@ -328,7 +348,7 @@ proc readcommit {id} {
348
}
349
350
proc updatecommits {} {
331
- global viewdata curview phase displayorder
351
+ global viewdata curview phase displayorder ordertok idpending
352
global children commitrow selectedline thickerline showneartags
353
354
if {$phase ne {}} {
@@ -339,6 +359,10 @@ proc updatecommits {} {
359
foreach id $displayorder {
360
catch {unset children($n,$id)}
361
catch {unset commitrow($n,$id)}
362
+ catch {unset ordertok($n,$id)}
363
+ }
364
+ foreach vid [array names idpending "$n,*"] {
365
+ unset idpending($vid)
366
}
367
set curview -1
368
catch {unset selectedline}
@@ -1963,13 +1987,11 @@ proc showview {n} {
1987
set vcmitlisted($curview) $commitlisted
1988
if {$phase ne {}} {
1989
set viewdata($curview) \
1966
- [list $phase $rowidlist {} {} \
1967
- {} [flatten idinlist] \
1968
- $rowlaidout $rowoptim $numcommits]
1990
+ [list $phase $rowidlist $rowlaidout $rowoptim $numcommits]
1991
} elseif {![info exists viewdata($curview)]
1992
|| [lindex $viewdata($curview) 0] ne {}} {
1993
set viewdata($curview) \
1972
- [list {} $rowidlist {} {}]
1994
+ [list {} $rowidlist]
1995
}
1996
}
1997
catch {unset treediffs}
@@ -2001,10 +2023,9 @@ proc showview {n} {
2023
if {$phase eq {}} {
2024
set numcommits [llength $displayorder]
2025
} else {
2004
- unflatten idinlist [lindex $v 5]
2005
- set rowlaidout [lindex $v 6]
2006
- set rowoptim [lindex $v 7]
2007
- set numcommits [lindex $v 8]
2026
+ set rowlaidout [lindex $v 2]
2027
+ set rowoptim [lindex $v 3]
2028
+ set numcommits [lindex $v 4]
2029
catch {unset rowchk}
2030
}
2031
@@ -2123,7 +2144,7 @@ proc addvhighlight {n} {
2144
}
2145
set hlview $n
2146
if {$n != $curview && ![info exists viewdata($n)]} {
2126
- set viewdata($n) [list getcommits {{}} {{}} {} {} {} 0 0 0 {}]
2147
+ set viewdata($n) [list getcommits {{}} 0 0 0]
2148
set vparentlist($n) {}
2149
set vdisporder($n) {}
2150
set vcmitlisted($n) {}
@@ -2635,9 +2656,11 @@ proc usedinrange {id l1 l2} {
2656
}
2657
set kids $children($curview,$id)
2658
foreach c $kids {
2638
- set r $commitrow($curview,$c)
2639
- if {$l1 <= $r && $r <= $l2} {
2640
- return [expr {$r - $l1 + 1}]
2659
+ if {[info exists commitrow($curview,$c)]} {
2660
+ set r $commitrow($curview,$c)
2661
+ if {$l1 <= $r && $r <= $l2} {
2662
+ return [expr {$r - $l1 + 1}]
2663
+ }
2664
}
2665
}
2666
return 0
@@ -2680,7 +2703,7 @@ proc makeuparrow {oid y x} {
2703
proc initlayout {} {
2704
global rowidlist displayorder commitlisted
2705
global rowlaidout rowoptim
2683
- global idinlist rowchk
2706
+ global rowchk
2707
global numcommits canvxmax canv
2708
global nextcolor
2709
global parentlist
@@ -2693,7 +2716,6 @@ proc initlayout {} {
2716
set parentlist {}
2717
set nextcolor 0
2718
set rowidlist {{}}
2696
- catch {unset idinlist}
2719
catch {unset rowchk}
2720
set rowlaidout 0
2721
set rowoptim 0
@@ -2733,7 +2755,7 @@ proc visiblerows {} {
2755
2756
proc layoutmore {tmax allread} {
2757
global rowlaidout rowoptim commitidx numcommits optim_delay
2736
- global uparrowlen curview rowidlist idinlist
2758
+ global uparrowlen curview rowidlist
2759
2760
set showlast 0
2761
set showdelay $optim_delay
@@ -2763,8 +2785,7 @@ proc layoutmore {tmax allread} {
2785
} elseif {$allread} {
2786
set optdelay 0
2787
set nrows $commitidx($curview)
2766
- if {[lindex $rowidlist $nrows] ne {} ||
2767
- [array names idinlist] ne {}} {
2788
+ if {[lindex $rowidlist $nrows] ne {}} {
2789
layouttail
2790
set rowlaidout $commitidx($curview)
2791
} elseif {$rowoptim == $nrows} {
@@ -2947,7 +2968,7 @@ proc layoutrows {row endrow last} {
2968
global uparrowlen downarrowlen maxwidth mingaplen
2969
global children parentlist
2970
global commitidx curview
2950
- global idinlist rowchk
2971
+ global rowchk
2972
2973
set idlist [lindex $rowidlist $row]
2974
while {$row < $endrow} {
@@ -2962,7 +2983,6 @@ proc layoutrows {row endrow last} {
2983
[expr {$row + $uparrowlen + $mingaplen}]]
2984
if {$r == 0} {
2985
set idlist [lreplace $idlist $x $x]
2965
- set idinlist($i) 0
2986
continue
2987
}
2988
set rowchk($i) [expr {$row + $r}]
@@ -2973,12 +2993,12 @@ proc layoutrows {row endrow last} {
2993
set oldolds {}
2994
set newolds {}
2995
foreach p [lindex $parentlist $row] {
2976
- if {![info exists idinlist($p)]} {
2996
+ # is id the first child of this parent?
2997
+ if {$id eq [lindex $children($curview,$p) 0]} {
2998
lappend newolds $p
2978
- } elseif {!$idinlist($p)} {
2999
+ } elseif {[lsearch -exact $idlist $p] < 0} {
3000
lappend oldolds $p
3001
}
2981
- set idinlist($p) 1
3002
}
3003
set col [lsearch -exact $idlist $id]
3004
if {$col < 0} {
@@ -2986,11 +3006,8 @@ proc layoutrows {row endrow last} {
3006
set idlist [linsert $idlist $col $id]
3007
lset rowidlist $row $idlist
3008
if {$children($curview,$id) ne {}} {
2989
- unset idinlist($id)
3009
makeuparrow $id $row $col
3010
}
2992
- } else {
2993
- unset idinlist($id)
3011
}
3012
incr row
3013
set idlist [lreplace $idlist $col $col]
@@ -3029,7 +3046,7 @@ proc addextraid {id row} {
3046
}
3047
3048
proc layouttail {} {
3032
- global rowidlist idinlist commitidx curview
3049
+ global rowidlist commitidx curview
3050
3051
set row $commitidx($curview)
3052
set idlist [lindex $rowidlist $row]
@@ -3037,20 +3054,10 @@ proc layouttail {} {
3054
set col [expr {[llength $idlist] - 1}]
3055
set id [lindex $idlist $col]
3056
addextraid $id $row
3040
- catch {unset idinlist($id)}
3057
incr row
3058
set idlist [lreplace $idlist $col $col]
3059
lappend rowidlist $idlist
3060
}
3045
-
3046
- foreach id [array names idinlist] {
3047
- unset idinlist($id)
3048
- addextraid $id $row
3049
- lset rowidlist $row [list $id]
3050
- makeuparrow $id $row 0
3051
- incr row
3052
- lappend rowidlist {}
3053
- }
3061
}
3062
3063
proc insert_pad {row col npad} {
@@ -4205,6 +4212,7 @@ proc findmorerev {} {
4212
set last 0
4213
for {} {$l > $lim} {incr l -1} {
4214
set id [lindex $displayorder $l]
4215
+ if {![info exists commitdata($id)]} continue
4216
if {![doesmatch $commitdata($id)]} continue
4217
if {![info exists commitinfo($id)]} {
4218
getcommit $id