@matheusbsbs / matheus-bagliano / commits / 31c0eaa8cc
Fork 0

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>

Paul Mackerras committed Dec 30, 2007 at 22:41 UTC 31c0eaa8cc10944ebca8aa31fb59f0b77b1b6e77
1 file changed +42 -13
gitk
+42 -13
@@ -734,9 +734,6 @@ proc rowofcommit {id} {
734 global varcid varccommits varcrow curview cached_commitrow
735 global varctok vtokmod
736
737 - if {[info exists cached_commitrow($id)]} {
738 - return $cached_commitrow($id)
739 - }
737 set v $curview
738 if {![info exists varcid($v,$id)]} {
739 puts "oops rowofcommit no arc for [shortids $id]"
@@ -746,6 +743,9 @@ proc rowofcommit {id} {
743 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
744 update_arcrows $v
745 }
746 + if {[info exists cached_commitrow($id)]} {
747 + return $cached_commitrow($id)
748 + }
749 set i [lsearch -exact $varccommits($v,$a) $id]
750 if {$i < 0} {
751 puts "oops didn't find commit [shortids $id] in arc $a"
@@ -1299,7 +1299,7 @@ proc confirm_popup msg {
1299 }
1300
1301 proc makewindow {} {
1302 - global canv canv2 canv3 linespc charspc ctext cflist
1302 + global canv canv2 canv3 linespc charspc ctext cflist cscroll
1303 global tabstop
1304 global findtype findtypemenu findloc findstring fstring geometry
1305 global entries sha1entry sha1string sha1but
@@ -1774,7 +1774,7 @@ proc canvscan {op w x y} {
1774
1775 proc scrollcanv {cscroll f0 f1} {
1776 $cscroll set $f0 $f1
1777 - drawfrac $f0 $f1
1777 + drawvisible
1778 flushhighlights
1779 }
1780
@@ -4538,23 +4538,52 @@ proc undolayout {row} {
4538 }
4539 }
4540
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
4544
4545 + set fs [$canv yview]
4546 set ymax [lindex [$canv cget -scrollregion] 3]
4547 if {$ymax eq {} || $ymax == 0} return
4548 + set f0 [lindex $fs 0]
4549 + set f1 [lindex $fs 1]
4550 set y0 [expr {int($f0 * $ymax)}]
4547 - set row [expr {int(($y0 - 3) / $linespc) - 1}]
4551 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}]
4573 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]
4584 drawcommits $row $endrow
4585 }
4586
4553 -proc drawvisible {} {
4554 - global canv
4555 - eval drawfrac [$canv yview]
4556 -}
4557 -
4587 proc clear_display {} {
4588 global iddrawn linesegs need_redisplay nrows_drawn
4589 global vhighlights fhighlights nhighlights rhighlights