Skip to content

Commit ac1276a

Browse files
committed
gitk: Fix problems with target row stuff
Occasionally the target row stuff would scroll the display to some uninteresting commit while reading. There were two problems: one was that drawvisible would set targetrow even if there was no target previously and no row selected, and the other was that it was possible for the target row to get pushed down past numcommits, if drawvisible was called after rows were added but before layoutmore got run. The first problem is fixed by just not setting targetrow/id unless there is a selected row or they were set previously. The second problem is fixed by updating numcommits immediately new rows are added. This leads to a simplification of layoutmore and chewcommits but also means that some of the things that were done in layoutmore now need to be done elsewhere, since layoutmore can no longer use numcommits to know how much it has seen previously. Hence the changes to getcommits, initlayout and setcanvscroll. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent f806f0f commit ac1276a

File tree

1 file changed

+51
-54
lines changed

1 file changed

+51
-54
lines changed

gitk

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,12 @@ proc stop_rev_list {view} {
161161
}
162162

163163
proc getcommits {} {
164-
global canv curview
164+
global canv curview need_redisplay
165165

166166
initlayout
167167
start_rev_list $curview
168168
show_status [mc "Reading commits..."]
169+
set need_redisplay 1
169170
}
170171

171172
proc updatecommits {} {
@@ -1048,7 +1049,7 @@ proc getcommitlines {fd inst view updating} {
10481049
adjustprogress
10491050
}
10501051
if {$view == $curview} {
1051-
run chewcommits $view
1052+
run chewcommits
10521053
}
10531054
return 0
10541055
}
@@ -1183,7 +1184,16 @@ proc getcommitlines {fd inst view updating} {
11831184
set gotsome 1
11841185
}
11851186
if {$gotsome} {
1186-
run chewcommits $view
1187+
global numcommits hlview
1188+
1189+
if {$view == $curview} {
1190+
set numcommits $commitidx($view)
1191+
run chewcommits
1192+
}
1193+
if {[info exists hlview] && $view == $hlview} {
1194+
# we never actually get here...
1195+
run vhighlightmore
1196+
}
11871197
foreach s $scripts {
11881198
eval $s
11891199
}
@@ -1218,33 +1228,28 @@ proc getcommitlines {fd inst view updating} {
12181228
return 2
12191229
}
12201230

1221-
proc chewcommits {view} {
1231+
proc chewcommits {} {
12221232
global curview hlview viewcomplete
12231233
global pending_select
12241234

1225-
if {$view == $curview} {
1226-
layoutmore
1227-
if {$viewcomplete($view)} {
1228-
global commitidx varctok
1229-
global numcommits startmsecs
1230-
global mainheadid commitinfo nullid
1231-
1232-
if {[info exists pending_select]} {
1233-
set row [first_real_row]
1234-
selectline $row 1
1235-
}
1236-
if {$commitidx($curview) > 0} {
1237-
#set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1238-
#puts "overall $ms ms for $numcommits commits"
1239-
#puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1240-
} else {
1241-
show_status [mc "No commits selected"]
1242-
}
1243-
notbusy layout
1235+
layoutmore
1236+
if {$viewcomplete($curview)} {
1237+
global commitidx varctok
1238+
global numcommits startmsecs
1239+
global mainheadid commitinfo nullid
1240+
1241+
if {[info exists pending_select]} {
1242+
set row [first_real_row]
1243+
selectline $row 1
12441244
}
1245-
}
1246-
if {[info exists hlview] && $view == $hlview} {
1247-
vhighlightmore
1245+
if {$commitidx($curview) > 0} {
1246+
#set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1247+
#puts "overall $ms ms for $numcommits commits"
1248+
#puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1249+
} else {
1250+
show_status [mc "No commits selected"]
1251+
}
1252+
notbusy layout
12481253
}
12491254
return 0
12501255
}
@@ -3064,6 +3069,7 @@ proc vhighlightmore {} {
30643069
}
30653070
}
30663071
set vhl_done $max
3072+
return 0
30673073
}
30683074

30693075
proc askvhighlight {row id} {
@@ -3562,15 +3568,19 @@ proc initlayout {} {
35623568
set canvxmax [$canv cget -width]
35633569
catch {unset colormap}
35643570
catch {unset rowtextx}
3571+
setcanvscroll
35653572
}
35663573

35673574
proc setcanvscroll {} {
35683575
global canv canv2 canv3 numcommits linespc canvxmax canvy0
3576+
global lastscrollset lastscrollrows
35693577

35703578
set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
35713579
$canv conf -scrollregion [list 0 0 $canvxmax $ymax]
35723580
$canv2 conf -scrollregion [list 0 0 0 $ymax]
35733581
$canv3 conf -scrollregion [list 0 0 0 $ymax]
3582+
set lastscrollset [clock clicks -milliseconds]
3583+
set lastscrollrows $numcommits
35743584
}
35753585

35763586
proc visiblerows {} {
@@ -3595,33 +3605,17 @@ proc visiblerows {} {
35953605
proc layoutmore {} {
35963606
global commitidx viewcomplete curview
35973607
global numcommits pending_select selectedline curview
3598-
global lastscrollset commitinterest
3599-
3600-
set canshow $commitidx($curview)
3601-
if {$canshow <= $numcommits && !$viewcomplete($curview)} return
3602-
if {$numcommits == 0} {
3603-
allcanvs delete all
3604-
}
3605-
set r0 $numcommits
3606-
set prev $numcommits
3607-
set numcommits $canshow
3608-
set t [clock clicks -milliseconds]
3609-
if {$prev < 100 || $viewcomplete($curview) || $t - $lastscrollset > 500} {
3610-
set lastscrollset $t
3608+
global lastscrollset lastscrollrows commitinterest
3609+
3610+
if {$lastscrollrows < 100 || $viewcomplete($curview) ||
3611+
[clock clicks -milliseconds] - $lastscrollset > 500} {
36113612
setcanvscroll
36123613
}
3613-
set rows [visiblerows]
3614-
set r1 [lindex $rows 1]
3615-
if {$r1 >= $canshow} {
3616-
set r1 [expr {$canshow - 1}]
3617-
}
3618-
if {$r0 <= $r1} {
3619-
drawcommits $r0 $r1
3620-
}
36213614
if {[info exists pending_select] &&
36223615
[commitinview $pending_select $curview]} {
36233616
selectline [rowofcommit $pending_select] 1
36243617
}
3618+
drawvisible
36253619
}
36263620

36273621
proc doshowlocalchanges {} {
@@ -4714,13 +4708,15 @@ proc drawvisible {} {
47144708
if {[info exists selectedline] &&
47154709
$row <= $selectedline && $selectedline <= $endrow} {
47164710
set targetrow $selectedline
4717-
} else {
4711+
} elseif {[info exists targetid]} {
47184712
set targetrow [expr {int(($row + $endrow) / 2)}]
47194713
}
4720-
if {$targetrow >= $numcommits} {
4721-
set targetrow [expr {$numcommits - 1}]
4714+
if {[info exists targetrow]} {
4715+
if {$targetrow >= $numcommits} {
4716+
set targetrow [expr {$numcommits - 1}]
4717+
}
4718+
set targetid [commitonrow $targetrow]
47224719
}
4723-
set targetid [commitonrow $targetrow]
47244720
drawcommits $row $endrow
47254721
}
47264722

@@ -5459,6 +5455,10 @@ proc selectline {l isnew} {
54595455
unsel_reflist
54605456
stopfinding
54615457
if {$l < 0 || $l >= $numcommits} return
5458+
set id [commitonrow $l]
5459+
set targetid $id
5460+
set targetrow $l
5461+
54625462
set y [expr {$canvy0 + $l * $linespc}]
54635463
set ymax [lindex [$canv cget -scrollregion] 3]
54645464
set ytop [expr {$y - $linespc - 1}]
@@ -5497,15 +5497,12 @@ proc selectline {l isnew} {
54975497

54985498
make_secsel $l
54995499

5500-
set id [commitonrow $l]
55015500
if {$isnew} {
55025501
addtohistory [list selbyid $id]
55035502
}
55045503

55055504
set selectedline $l
55065505
set currentid $id
5507-
set targetid $id
5508-
set targetrow $l
55095506
$sha1entry delete 0 end
55105507
$sha1entry insert 0 $id
55115508
$sha1entry selection from 0

0 commit comments

Comments
 (0)