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

gitk: Fix potential bug with fake commit IDs in renumbervarc

When a fake row is added, we add its (fake) ID to the children list for its (fake) parent. If renumbervarc were to then renumber the parent it would incorrectly use the fake child. This avoids the problem by adding a last_real_child procedure which won't return a fake ID, and using it in renumbervarc. For symmetry this also adds a first_real_child procedure and uses it in ordertoken. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Jan 6, 2008 at 13:54 UTC c8c9f3d9cc9a21084c9fe4742d0e66b7c988635c
1 file changed +28 -9
gitk
+28 -9
@@ -462,8 +462,8 @@ proc renumbervarc {a v} {
462 set tok $oldtok
463 }
464 set ka 0
465 - if {[llength $children($v,$id)] > 0} {
466 - set kid [lindex $children($v,$id) end]
465 + set kid [last_real_child $v,$id]
466 + if {$kid ne {}} {
467 set k $varcid($v,$kid)
468 if {[string compare [lindex $varctok($v) $k] $tok] > 0} {
469 set ki $kid
@@ -628,6 +628,30 @@ proc removerow {id v} {
628 drawvisible
629 }
630
631 +proc first_real_child {vp} {
632 + global children nullid nullid2
633 +
634 + foreach id $children($vp) {
635 + if {$id ne $nullid && $id ne $nullid2} {
636 + return $id
637 + }
638 + }
639 + return {}
640 +}
641 +
642 +proc last_real_child {vp} {
643 + global children nullid nullid2
644 +
645 + set kids $children($vp)
646 + for {set i [llength $kids]} {[incr i -1] >= 0} {} {
647 + set id [lindex $kids $i]
648 + if {$id ne $nullid && $id ne $nullid2} {
649 + return $id
650 + }
651 + }
652 + return {}
653 +}
654 +
655 proc vtokcmp {v a b} {
656 global varctok varcid
657
@@ -3376,17 +3400,12 @@ proc ordertoken {id} {
3400 set tok $ordertok($p)
3401 break
3402 }
3379 - if {[llength $children($curview,$p)] == 0} {
3403 + set id [first_real_child $curview,$p]
3404 + if {$id eq {}} {
3405 # it's a root
3406 set tok [lindex $varctok($curview) $a]
3407 break
3408 }
3384 - set id [lindex $children($curview,$p) 0]
3385 - if {$id eq $nullid || $id eq $nullid2} {
3386 - # XXX treat it as a root
3387 - set tok [lindex $varctok($curview) $a]
3388 - break
3389 - }
3409 if {[llength $parents($curview,$id)] == 1} {
3410 lappend todo [list $p {}]
3411 } else {