Skip to content

Commit 31c0eaa

Browse files
committed
gitk: Keep the same commits visible as other commits come in
Since commits come in out of order and get sorted as we see them, we can have commits coming in and being placed before the commits that are visible in the graph display pane. Previously we just displayed a certain range of row numbers, meaning that when incoming commits were placed before the displayed range, the displayed commits were displaced downwards. This makes it so that we keep the same set of commits displayed, unless the user explicitly scrolls the pane, in which case it scrolls as expected. We do this by having a "target" commit which we try to keep in the same visible position. If commits have come in before it we scroll the canvases by the number of rows that it has moved in the display order. This also fixes a bug in rowofcommit where it would test cached_commitrow before possibly calling update_arcrows, which is where cached_commitrow gets invalidated if things have changed. Now we call update_arcrows if necessary first. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent eb5f8c9 commit 31c0eaa

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

gitk

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,6 @@ proc rowofcommit {id} {
734734
global varcid varccommits varcrow curview cached_commitrow
735735
global varctok vtokmod
736736

737-
if {[info exists cached_commitrow($id)]} {
738-
return $cached_commitrow($id)
739-
}
740737
set v $curview
741738
if {![info exists varcid($v,$id)]} {
742739
puts "oops rowofcommit no arc for [shortids $id]"
@@ -746,6 +743,9 @@ proc rowofcommit {id} {
746743
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
747744
update_arcrows $v
748745
}
746+
if {[info exists cached_commitrow($id)]} {
747+
return $cached_commitrow($id)
748+
}
749749
set i [lsearch -exact $varccommits($v,$a) $id]
750750
if {$i < 0} {
751751
puts "oops didn't find commit [shortids $id] in arc $a"
@@ -1299,7 +1299,7 @@ proc confirm_popup msg {
12991299
}
13001300

13011301
proc makewindow {} {
1302-
global canv canv2 canv3 linespc charspc ctext cflist
1302+
global canv canv2 canv3 linespc charspc ctext cflist cscroll
13031303
global tabstop
13041304
global findtype findtypemenu findloc findstring fstring geometry
13051305
global entries sha1entry sha1string sha1but
@@ -1774,7 +1774,7 @@ proc canvscan {op w x y} {
17741774

17751775
proc scrollcanv {cscroll f0 f1} {
17761776
$cscroll set $f0 $f1
1777-
drawfrac $f0 $f1
1777+
drawvisible
17781778
flushhighlights
17791779
}
17801780

@@ -4538,23 +4538,52 @@ proc undolayout {row} {
45384538
}
45394539
}
45404540

4541-
proc drawfrac {f0 f1} {
4542-
global canv linespc
4541+
proc drawvisible {} {
4542+
global canv linespc curview vrowmod selectedline targetrow targetid
4543+
global need_redisplay cscroll
45434544

4545+
set fs [$canv yview]
45444546
set ymax [lindex [$canv cget -scrollregion] 3]
45454547
if {$ymax eq {} || $ymax == 0} return
4548+
set f0 [lindex $fs 0]
4549+
set f1 [lindex $fs 1]
45464550
set y0 [expr {int($f0 * $ymax)}]
4547-
set row [expr {int(($y0 - 3) / $linespc) - 1}]
45484551
set y1 [expr {int($f1 * $ymax)}]
4552+
4553+
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
4569+
}
4570+
}
4571+
4572+
set row [expr {int(($y0 - 3) / $linespc) - 1}]
45494573
set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
4574+
if {$endrow >= $vrowmod($curview)} {
4575+
update_arcrows $curview
4576+
}
4577+
if {[info exists selectedline] &&
4578+
$row <= $selectedline && $selectedline <= $endrow} {
4579+
set targetrow $selectedline
4580+
} else {
4581+
set targetrow [expr {int(($row + $endrow) / 2)}]
4582+
}
4583+
set targetid [commitonrow $targetrow]
45504584
drawcommits $row $endrow
45514585
}
45524586

4553-
proc drawvisible {} {
4554-
global canv
4555-
eval drawfrac [$canv yview]
4556-
}
4557-
45584587
proc clear_display {} {
45594588
global iddrawn linesegs need_redisplay nrows_drawn
45604589
global vhighlights fhighlights nhighlights rhighlights

0 commit comments

Comments
 (0)