@matheusbsbs / matheus-bagliano / commits / 42a671fc00
Fork 0

gitk: Fix some corner cases in the targetid/targetrow stuff

* Make sure targetrow is never >= numcommits * Don't try to do anything about the target row if the targetid is no longer in the view; it'll just cause Tcl errors * In insertrow, increment targetrow if we are inserting the fake commit at or before the target row * In removerow, if we are removing the target row, make it the next one instead. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Jan 2, 2008 at 09:59 UTC 42a671fc006122159aec06da28045ffee49d3244
1 file changed +51 -18
gitk
+51 -18
@@ -234,7 +234,7 @@ proc updatecommits {} {
234 proc reloadcommits {} {
235 global curview viewcomplete selectedline currentid thickerline
236 global showneartags treediffs commitinterest cached_commitrow
237 - global progresscoords
237 + global progresscoords targetid
238
239 if {!$viewcomplete($curview)} {
240 stop_rev_list $curview
@@ -254,6 +254,7 @@ proc reloadcommits {} {
254 clear_display
255 catch {unset commitinterest}
256 catch {unset cached_commitrow}
257 + catch {unset targetid}
258 setcanvscroll
259 getcommits
260 }
@@ -561,7 +562,7 @@ proc fix_reversal {p a v} {
562
563 proc insertrow {id p v} {
564 global varcid varccommits parents children cmitlisted
564 - global commitidx varctok vtokmod
565 + global commitidx varctok vtokmod targetid targetrow
566
567 set a $varcid($v,$p)
568 set i [lsearch -exact $varccommits($v,$a) $p]
@@ -580,12 +581,18 @@ proc insertrow {id p v} {
581 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
582 modify_arc $v $a $i
583 }
584 + if {[info exists targetid]} {
585 + if {![comes_before $targetid $p]} {
586 + incr targetrow
587 + }
588 + }
589 drawvisible
590 }
591
592 proc removerow {id v} {
593 global varcid varccommits parents children commitidx
594 global varctok vtokmod cmitlisted currentid selectedline
595 + global targetid
596
597 if {[llength $parents($v,$id)] != 1} {
598 puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents"
@@ -615,6 +622,9 @@ proc removerow {id v} {
622 unset currentid
623 unset selectedline
624 }
625 + if {[info exists targetid] && $targetid eq $id} {
626 + set targetid $p
627 + }
628 drawvisible
629 }
630
@@ -756,6 +766,22 @@ proc rowofcommit {id} {
766 return $i
767 }
768
769 +# Returns 1 if a is on an earlier row than b, otherwise 0
770 +proc comes_before {a b} {
771 + global varcid varctok curview
772 +
773 + set v $curview
774 + if {$a eq $b || ![info exists varcid($v,$a)] || \
775 + ![info exists varcid($v,$b)]} {
776 + return 0
777 + }
778 + if {$varcid($v,$a) != $varcid($v,$b)} {
779 + return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \
780 + [lindex $varctok($v) $varcid($v,$b)]] < 0}]
781 + }
782 + return [expr {[rowofcommit $a] < [rowofcommit $b]}]
783 +}
784 +
785 proc bsearch {l elt} {
786 if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
787 return 0
@@ -4540,7 +4566,7 @@ proc undolayout {row} {
4566
4567 proc drawvisible {} {
4568 global canv linespc curview vrowmod selectedline targetrow targetid
4543 - global need_redisplay cscroll
4569 + global need_redisplay cscroll numcommits
4570
4571 set fs [$canv yview]
4572 set ymax [lindex [$canv cget -scrollregion] 3]
@@ -4551,21 +4577,25 @@ proc drawvisible {} {
4577 set y1 [expr {int($f1 * $ymax)}]
4578
4579 if {[info exists targetid]} {
4554 - set r [rowofcommit $targetid]
4555 - if {$r != $targetrow} {
4556 - # Fix up the scrollregion and change the scrolling position
4557 - # now that our target row has moved.
4558 - set diff [expr {($r - $targetrow) * $linespc}]
4559 - set targetrow $r
4560 - setcanvscroll
4561 - set ymax [lindex [$canv cget -scrollregion] 3]
4562 - incr y0 $diff
4563 - incr y1 $diff
4564 - set f0 [expr {$y0 / $ymax}]
4565 - set f1 [expr {$y1 / $ymax}]
4566 - allcanvs yview moveto $f0
4567 - $cscroll set $f0 $f1
4568 - set need_redisplay 1
4580 + if {[commitinview $targetid $curview]} {
4581 + set r [rowofcommit $targetid]
4582 + if {$r != $targetrow} {
4583 + # Fix up the scrollregion and change the scrolling position
4584 + # now that our target row has moved.
4585 + set diff [expr {($r - $targetrow) * $linespc}]
4586 + set targetrow $r
4587 + setcanvscroll
4588 + set ymax [lindex [$canv cget -scrollregion] 3]
4589 + incr y0 $diff
4590 + incr y1 $diff
4591 + set f0 [expr {$y0 / $ymax}]
4592 + set f1 [expr {$y1 / $ymax}]
4593 + allcanvs yview moveto $f0
4594 + $cscroll set $f0 $f1
4595 + set need_redisplay 1
4596 + }
4597 + } else {
4598 + unset targetid
4599 }
4600 }
4601
@@ -4580,6 +4610,9 @@ proc drawvisible {} {
4610 } else {
4611 set targetrow [expr {int(($row + $endrow) / 2)}]
4612 }
4613 + if {$targetrow >= $numcommits} {
4614 + set targetrow [expr {$numcommits - 1}]
4615 + }
4616 set targetid [commitonrow $targetrow]
4617 drawcommits $row $endrow
4618 }