@matheusbsbs / matheus-bagliano / commits / e5b37ac1ec
Fork 0

gitk: Fix more bugs resulting in Tcl "no such element in array" errors

First, update_arcrows was being overly aggressive in trimming displayorder, resulting in calls to rowofcommit sometimes trimming off commits that layoutrows had asked for in make_disporder and was relying on having present. This adds a vrowmod($view) variable that lets update_arcrows be more precise in trimming off the invalid bits of displayorder (and it also simplifies the check in make_disporder). This modifies modify_arc and its callers so that vrowmod($view) is updated appropriately. Secondly, we were sometimes calling idcol with $i==-1, which resulted in a call to ordertoken with the null string. This fixes it by forcing $i to 0 if it is less than zero. This also fixes a possible infinite recursion with rowofcommit and update_arcrows calling each other ad infinitum. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Dec 12, 2007 at 18:13 UTC e5b37ac1ec6f1500a47a320a261933bccbdeb4f7
1 file changed +35 -24
gitk
+35 -24
@@ -268,7 +268,7 @@ proc strrep {n} {
268
269 proc varcinit {view} {
270 global vseeds varcstart vupptr vdownptr vleftptr varctok varcrow
271 - global vtokmod varcmod varcix uat
271 + global vtokmod varcmod vrowmod varcix uat
272
273 set vseeds($view) {}
274 set varcstart($view) {{}}
@@ -279,6 +279,7 @@ proc varcinit {view} {
279 set varcrow($view) {{}}
280 set vtokmod($view) {}
281 set varcmod($view) 0
282 + set vrowmod($view) 0
283 set varcix($view) {{}}
284 set uat 0
285 }
@@ -307,7 +308,7 @@ proc resetvarcs {view} {
308 proc newvarc {view id} {
309 global varcid varctok parents children vseeds
310 global vupptr vdownptr vleftptr varcrow varcix varcstart
310 - global commitdata commitinfo vseedcount
311 + global commitdata commitinfo vseedcount varccommits
312
313 set a [llength $varctok($view)]
314 set vid $view,$id
@@ -377,6 +378,7 @@ proc newvarc {view id} {
378 lappend vdownptr($view) 0
379 lappend varcrow($view) {}
380 lappend varcix($view) {}
381 + set varccommits($view,$a) {}
382 return $a
383 }
384
@@ -547,7 +549,7 @@ proc insertrow {id p v} {
549 # note we deliberately don't update varcstart($v) even if $i == 0
550 set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id]
551 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
550 - modify_arc $v $a
552 + modify_arc $v $a $i
553 }
554 drawvisible
555 }
@@ -579,7 +581,7 @@ proc removerow {id v} {
581 }
582 set tok [lindex $varctok($v) $a]
583 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
582 - modify_arc $v $a
584 + modify_arc $v $a $i
585 }
586 drawvisible
587 }
@@ -591,22 +593,30 @@ proc vtokcmp {v a b} {
593 [lindex $varctok($v) $varcid($v,$b)]]
594 }
595
594 -proc modify_arc {v a} {
595 - global varctok vtokmod varcmod varcrow vupptr curview
596 +proc modify_arc {v a {lim {}}} {
597 + global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
598
599 set vtokmod($v) [lindex $varctok($v) $a]
600 set varcmod($v) $a
601 if {$v == $curview} {
602 while {$a != 0 && [lindex $varcrow($v) $a] eq {}} {
603 set a [lindex $vupptr($v) $a]
604 + set lim {}
605 }
603 - set r [expr {$a == 0? 0: [lindex $varcrow($v) $a]}]
606 + set r 0
607 + if {$a != 0} {
608 + if {$lim eq {}} {
609 + set lim [llength $varccommits($v,$a)]
610 + }
611 + set r [expr {[lindex $varcrow($v) $a] + $lim}]
612 + }
613 + set vrowmod($v) $r
614 undolayout $r
615 }
616 }
617
618 proc update_arcrows {v} {
609 - global vtokmod varcmod varcrow commitidx currentid selectedline
619 + global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
620 global varcid vseeds vrownum varcorder varcix varccommits
621 global vupptr vdownptr vleftptr varctok
622 global uat displayorder parentlist curview cached_commitrow
@@ -640,11 +650,11 @@ proc update_arcrows {v} {
650 }
651 set row [lindex $varcrow($v) $a]
652 }
643 - if {[llength $displayorder] > $row} {
644 - set displayorder [lrange $displayorder 0 [expr {$row - 1}]]
645 - set parentlist [lrange $parentlist 0 [expr {$row - 1}]]
646 - }
653 if {$v == $curview} {
654 + if {[llength $displayorder] > $vrowmod($v)} {
655 + set displayorder [lrange $displayorder 0 [expr {$vrowmod($v) - 1}]]
656 + set parentlist [lrange $parentlist 0 [expr {$vrowmod($v) - 1}]]
657 + }
658 catch {unset cached_commitrow}
659 }
660 while {1} {
@@ -668,11 +678,12 @@ proc update_arcrows {v} {
678 lset varcix($v) $a $arcn
679 lset varcrow($v) $a $row
680 }
681 + set vtokmod($v) [lindex $varctok($v) $p]
682 + set varcmod($v) $p
683 + set vrowmod($v) $row
684 if {[info exists currentid]} {
685 set selectedline [rowofcommit $currentid]
686 }
674 - set vtokmod($v) [lindex $varctok($v) $p]
675 - set varcmod($v) $p
687 set t2 [clock clicks -milliseconds]
688 incr uat [expr {$t2-$t1}]
689 }
@@ -734,13 +745,10 @@ proc bsearch {l elt} {
745 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
746 proc make_disporder {start end} {
747 global vrownum curview commitidx displayorder parentlist
737 - global varccommits varcorder parents varcmod varcrow
748 + global varccommits varcorder parents vrowmod varcrow
749 global d_valid_start d_valid_end
750
740 - set la $varcmod($curview)
741 - set lrow [lindex $varcrow($curview) $la]
742 - if {$la == 0 || $lrow eq {} || \
743 - $end > $lrow + [llength $varccommits($curview,$la)]} {
751 + if {$end > $vrowmod($curview)} {
752 update_arcrows $curview
753 }
754 set ai [bsearch $vrownum($curview) $start]
@@ -808,10 +816,10 @@ proc closevarcs {v} {
816 set b [newvarc $v $p]
817 }
818 set varcid($v,$p) $b
811 - lappend varccommits($v,$b) $p
819 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
820 modify_arc $v $b
821 }
822 + lappend varccommits($v,$b) $p
823 incr commitidx($v)
824 if {[info exists commitinterest($p)]} {
825 foreach script $commitinterest($p) {
@@ -958,8 +966,11 @@ proc getcommitlines {fd inst view} {
966 set a [newvarc $view $id]
967 }
968 set varcid($vid) $a
969 + if {[string compare [lindex $varctok($view) $a] $vtokmod($view)] < 0} {
970 + modify_arc $view $a
971 + }
972 lappend varccommits($view,$a) $id
962 - set tok [lindex $varctok($view) $a]
973 +
974 set i 0
975 foreach p $olds {
976 if {$i == 0 || [lsearch -exact $olds $p] >= $i} {
@@ -976,9 +987,6 @@ proc getcommitlines {fd inst view} {
987 }
988 incr i
989 }
979 - if {[string compare $tok $vtokmod($view)] < 0} {
980 - modify_arc $view $a
981 - }
990
991 incr commitidx($view)
992 if {[info exists commitinterest($id)]} {
@@ -3345,6 +3353,9 @@ proc ordertoken {id} {
3353 # values increase from left to right
3354 proc idcol {idlist id {i 0}} {
3355 set t [ordertoken $id]
3356 + if {$i < 0} {
3357 + set i 0
3358 + }
3359 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
3360 if {$i > [llength $idlist]} {
3361 set i [llength $idlist]