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>
This commit is contained in:
69
gitk
69
gitk
@ -234,7 +234,7 @@ proc updatecommits {} {
|
|||||||
proc reloadcommits {} {
|
proc reloadcommits {} {
|
||||||
global curview viewcomplete selectedline currentid thickerline
|
global curview viewcomplete selectedline currentid thickerline
|
||||||
global showneartags treediffs commitinterest cached_commitrow
|
global showneartags treediffs commitinterest cached_commitrow
|
||||||
global progresscoords
|
global progresscoords targetid
|
||||||
|
|
||||||
if {!$viewcomplete($curview)} {
|
if {!$viewcomplete($curview)} {
|
||||||
stop_rev_list $curview
|
stop_rev_list $curview
|
||||||
@ -254,6 +254,7 @@ proc reloadcommits {} {
|
|||||||
clear_display
|
clear_display
|
||||||
catch {unset commitinterest}
|
catch {unset commitinterest}
|
||||||
catch {unset cached_commitrow}
|
catch {unset cached_commitrow}
|
||||||
|
catch {unset targetid}
|
||||||
setcanvscroll
|
setcanvscroll
|
||||||
getcommits
|
getcommits
|
||||||
}
|
}
|
||||||
@ -561,7 +562,7 @@ proc fix_reversal {p a v} {
|
|||||||
|
|
||||||
proc insertrow {id p v} {
|
proc insertrow {id p v} {
|
||||||
global varcid varccommits parents children cmitlisted
|
global varcid varccommits parents children cmitlisted
|
||||||
global commitidx varctok vtokmod
|
global commitidx varctok vtokmod targetid targetrow
|
||||||
|
|
||||||
set a $varcid($v,$p)
|
set a $varcid($v,$p)
|
||||||
set i [lsearch -exact $varccommits($v,$a) $p]
|
set i [lsearch -exact $varccommits($v,$a) $p]
|
||||||
@ -580,12 +581,18 @@ proc insertrow {id p v} {
|
|||||||
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
|
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
|
||||||
modify_arc $v $a $i
|
modify_arc $v $a $i
|
||||||
}
|
}
|
||||||
|
if {[info exists targetid]} {
|
||||||
|
if {![comes_before $targetid $p]} {
|
||||||
|
incr targetrow
|
||||||
|
}
|
||||||
|
}
|
||||||
drawvisible
|
drawvisible
|
||||||
}
|
}
|
||||||
|
|
||||||
proc removerow {id v} {
|
proc removerow {id v} {
|
||||||
global varcid varccommits parents children commitidx
|
global varcid varccommits parents children commitidx
|
||||||
global varctok vtokmod cmitlisted currentid selectedline
|
global varctok vtokmod cmitlisted currentid selectedline
|
||||||
|
global targetid
|
||||||
|
|
||||||
if {[llength $parents($v,$id)] != 1} {
|
if {[llength $parents($v,$id)] != 1} {
|
||||||
puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents"
|
puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents"
|
||||||
@ -615,6 +622,9 @@ proc removerow {id v} {
|
|||||||
unset currentid
|
unset currentid
|
||||||
unset selectedline
|
unset selectedline
|
||||||
}
|
}
|
||||||
|
if {[info exists targetid] && $targetid eq $id} {
|
||||||
|
set targetid $p
|
||||||
|
}
|
||||||
drawvisible
|
drawvisible
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -756,6 +766,22 @@ proc rowofcommit {id} {
|
|||||||
return $i
|
return $i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Returns 1 if a is on an earlier row than b, otherwise 0
|
||||||
|
proc comes_before {a b} {
|
||||||
|
global varcid varctok curview
|
||||||
|
|
||||||
|
set v $curview
|
||||||
|
if {$a eq $b || ![info exists varcid($v,$a)] || \
|
||||||
|
![info exists varcid($v,$b)]} {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if {$varcid($v,$a) != $varcid($v,$b)} {
|
||||||
|
return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \
|
||||||
|
[lindex $varctok($v) $varcid($v,$b)]] < 0}]
|
||||||
|
}
|
||||||
|
return [expr {[rowofcommit $a] < [rowofcommit $b]}]
|
||||||
|
}
|
||||||
|
|
||||||
proc bsearch {l elt} {
|
proc bsearch {l elt} {
|
||||||
if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
|
if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
|
||||||
return 0
|
return 0
|
||||||
@ -4540,7 +4566,7 @@ proc undolayout {row} {
|
|||||||
|
|
||||||
proc drawvisible {} {
|
proc drawvisible {} {
|
||||||
global canv linespc curview vrowmod selectedline targetrow targetid
|
global canv linespc curview vrowmod selectedline targetrow targetid
|
||||||
global need_redisplay cscroll
|
global need_redisplay cscroll numcommits
|
||||||
|
|
||||||
set fs [$canv yview]
|
set fs [$canv yview]
|
||||||
set ymax [lindex [$canv cget -scrollregion] 3]
|
set ymax [lindex [$canv cget -scrollregion] 3]
|
||||||
@ -4551,21 +4577,25 @@ proc drawvisible {} {
|
|||||||
set y1 [expr {int($f1 * $ymax)}]
|
set y1 [expr {int($f1 * $ymax)}]
|
||||||
|
|
||||||
if {[info exists targetid]} {
|
if {[info exists targetid]} {
|
||||||
set r [rowofcommit $targetid]
|
if {[commitinview $targetid $curview]} {
|
||||||
if {$r != $targetrow} {
|
set r [rowofcommit $targetid]
|
||||||
# Fix up the scrollregion and change the scrolling position
|
if {$r != $targetrow} {
|
||||||
# now that our target row has moved.
|
# Fix up the scrollregion and change the scrolling position
|
||||||
set diff [expr {($r - $targetrow) * $linespc}]
|
# now that our target row has moved.
|
||||||
set targetrow $r
|
set diff [expr {($r - $targetrow) * $linespc}]
|
||||||
setcanvscroll
|
set targetrow $r
|
||||||
set ymax [lindex [$canv cget -scrollregion] 3]
|
setcanvscroll
|
||||||
incr y0 $diff
|
set ymax [lindex [$canv cget -scrollregion] 3]
|
||||||
incr y1 $diff
|
incr y0 $diff
|
||||||
set f0 [expr {$y0 / $ymax}]
|
incr y1 $diff
|
||||||
set f1 [expr {$y1 / $ymax}]
|
set f0 [expr {$y0 / $ymax}]
|
||||||
allcanvs yview moveto $f0
|
set f1 [expr {$y1 / $ymax}]
|
||||||
$cscroll set $f0 $f1
|
allcanvs yview moveto $f0
|
||||||
set need_redisplay 1
|
$cscroll set $f0 $f1
|
||||||
|
set need_redisplay 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unset targetid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4580,6 +4610,9 @@ proc drawvisible {} {
|
|||||||
} else {
|
} else {
|
||||||
set targetrow [expr {int(($row + $endrow) / 2)}]
|
set targetrow [expr {int(($row + $endrow) / 2)}]
|
||||||
}
|
}
|
||||||
|
if {$targetrow >= $numcommits} {
|
||||||
|
set targetrow [expr {$numcommits - 1}]
|
||||||
|
}
|
||||||
set targetid [commitonrow $targetrow]
|
set targetid [commitonrow $targetrow]
|
||||||
drawcommits $row $endrow
|
drawcommits $row $endrow
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user