Skip to content

Commit 3e76608

Browse files
committed
gitk: Select head of current branch by default
Instead of selecting the first commit that appears, this makes gitk select the currently checked out head, if the user hasn't explicitly selected some other commit by the time it appears. If the head hasn't appeared by the time the graph is complete, then we select the first real commit. This applies both for graph updates and when the graph is being read in initially. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 17529cf commit 3e76608

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

gitk

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ proc start_rev_list {view} {
9898
global showlocalchanges commitinterest mainheadid
9999
global progressdirn progresscoords proglastnc curview
100100
global viewincl viewactive loginstance viewinstances
101+
global pending_select mainheadid
101102

102103
set startmsecs [clock clicks -milliseconds]
103104
set commitidx($view) 0
@@ -138,6 +139,7 @@ proc start_rev_list {view} {
138139
set progressdirn 1
139140
set progresscoords {0 0}
140141
set proglastnc 0
142+
set pending_select $mainheadid
141143
}
142144
}
143145

@@ -170,7 +172,7 @@ proc updatecommits {} {
170172
global curview viewargs viewfiles viewincl viewinstances
171173
global viewactive viewcomplete loginstance tclencoding mainheadid
172174
global varcid startmsecs commfd showneartags showlocalchanges leftover
173-
global mainheadid
175+
global mainheadid pending_select
174176

175177
set oldmainid $mainheadid
176178
rereadrefs
@@ -228,6 +230,7 @@ proc updatecommits {} {
228230
filerun $fd [list getcommitlines $fd $i $view]
229231
incr viewactive($view)
230232
set viewcomplete($view) 0
233+
set pending_select $mainheadid
231234
nowbusy $view "Reading"
232235
if {$showneartags} {
233236
getallcommits
@@ -2748,9 +2751,9 @@ proc showview {n} {
27482751
global numcommits viewcomplete
27492752
global selectedline currentid canv canvy0
27502753
global treediffs
2751-
global pending_select
2754+
global pending_select mainheadid
27522755
global commitidx
2753-
global selectedview selectfirst
2756+
global selectedview
27542757
global hlview selectedhlview commitinterest
27552758

27562759
if {$n == $curview} return
@@ -2812,7 +2815,6 @@ proc showview {n} {
28122815
setcanvscroll
28132816
set yf 0
28142817
set row {}
2815-
set selectfirst 0
28162818
if {$selid ne {} && [commitinview $selid $n]} {
28172819
set row [rowofcommit $selid]
28182820
# try to get the selected row in the same position on the screen
@@ -2827,14 +2829,18 @@ proc showview {n} {
28272829
drawvisible
28282830
if {$row ne {}} {
28292831
selectline $row 0
2830-
} elseif {$selid ne {}} {
2831-
set pending_select $selid
2832+
} elseif {$mainheadid ne {} && [commitinview $mainheadid $curview]} {
2833+
selectline [rowofcommit $mainheadid] 1
2834+
} elseif {!$viewcomplete($n)} {
2835+
if {$selid ne {}} {
2836+
set pending_select $selid
2837+
} else {
2838+
set pending_select $mainheadid
2839+
}
28322840
} else {
28332841
set row [first_real_row]
28342842
if {$row < $numcommits} {
28352843
selectline $row 0
2836-
} else {
2837-
set selectfirst 1
28382844
}
28392845
}
28402846
if {!$viewcomplete($n)} {
@@ -3440,7 +3446,6 @@ proc initlayout {} {
34403446
global numcommits canvxmax canv
34413447
global nextcolor
34423448
global colormap rowtextx
3443-
global selectfirst
34443449

34453450
set numcommits 0
34463451
set displayorder {}
@@ -3452,7 +3457,6 @@ proc initlayout {} {
34523457
set canvxmax [$canv cget -width]
34533458
catch {unset colormap}
34543459
catch {unset rowtextx}
3455-
set selectfirst 1
34563460
}
34573461

34583462
proc setcanvscroll {} {
@@ -3486,7 +3490,7 @@ proc visiblerows {} {
34863490
proc layoutmore {} {
34873491
global commitidx viewcomplete curview
34883492
global numcommits pending_select selectedline curview
3489-
global selectfirst lastscrollset commitinterest
3493+
global lastscrollset commitinterest
34903494

34913495
set canshow $commitidx($curview)
34923496
if {$canshow <= $numcommits && !$viewcomplete($curview)} return
@@ -3513,15 +3517,6 @@ proc layoutmore {} {
35133517
[commitinview $pending_select $curview]} {
35143518
selectline [rowofcommit $pending_select] 1
35153519
}
3516-
if {$selectfirst} {
3517-
if {[info exists selectedline] || [info exists pending_select]} {
3518-
set selectfirst 0
3519-
} else {
3520-
set l [first_real_row]
3521-
selectline $l 1
3522-
set selectfirst 0
3523-
}
3524-
}
35253520
}
35263521

35273522
proc doshowlocalchanges {} {

0 commit comments

Comments
 (0)