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>
This commit is contained in:
Paul Mackerras
2008-01-13 17:26:30 +11:00
parent 17529cf9bc
commit 3e76608d39

35
gitk
View File

@ -98,6 +98,7 @@ proc start_rev_list {view} {
global showlocalchanges commitinterest mainheadid global showlocalchanges commitinterest mainheadid
global progressdirn progresscoords proglastnc curview global progressdirn progresscoords proglastnc curview
global viewincl viewactive loginstance viewinstances global viewincl viewactive loginstance viewinstances
global pending_select mainheadid
set startmsecs [clock clicks -milliseconds] set startmsecs [clock clicks -milliseconds]
set commitidx($view) 0 set commitidx($view) 0
@ -138,6 +139,7 @@ proc start_rev_list {view} {
set progressdirn 1 set progressdirn 1
set progresscoords {0 0} set progresscoords {0 0}
set proglastnc 0 set proglastnc 0
set pending_select $mainheadid
} }
} }
@ -170,7 +172,7 @@ proc updatecommits {} {
global curview viewargs viewfiles viewincl viewinstances global curview viewargs viewfiles viewincl viewinstances
global viewactive viewcomplete loginstance tclencoding mainheadid global viewactive viewcomplete loginstance tclencoding mainheadid
global varcid startmsecs commfd showneartags showlocalchanges leftover global varcid startmsecs commfd showneartags showlocalchanges leftover
global mainheadid global mainheadid pending_select
set oldmainid $mainheadid set oldmainid $mainheadid
rereadrefs rereadrefs
@ -228,6 +230,7 @@ proc updatecommits {} {
filerun $fd [list getcommitlines $fd $i $view] filerun $fd [list getcommitlines $fd $i $view]
incr viewactive($view) incr viewactive($view)
set viewcomplete($view) 0 set viewcomplete($view) 0
set pending_select $mainheadid
nowbusy $view "Reading" nowbusy $view "Reading"
if {$showneartags} { if {$showneartags} {
getallcommits getallcommits
@ -2748,9 +2751,9 @@ proc showview {n} {
global numcommits viewcomplete global numcommits viewcomplete
global selectedline currentid canv canvy0 global selectedline currentid canv canvy0
global treediffs global treediffs
global pending_select global pending_select mainheadid
global commitidx global commitidx
global selectedview selectfirst global selectedview
global hlview selectedhlview commitinterest global hlview selectedhlview commitinterest
if {$n == $curview} return if {$n == $curview} return
@ -2812,7 +2815,6 @@ proc showview {n} {
setcanvscroll setcanvscroll
set yf 0 set yf 0
set row {} set row {}
set selectfirst 0
if {$selid ne {} && [commitinview $selid $n]} { if {$selid ne {} && [commitinview $selid $n]} {
set row [rowofcommit $selid] set row [rowofcommit $selid]
# try to get the selected row in the same position on the screen # try to get the selected row in the same position on the screen
@ -2827,14 +2829,18 @@ proc showview {n} {
drawvisible drawvisible
if {$row ne {}} { if {$row ne {}} {
selectline $row 0 selectline $row 0
} elseif {$selid ne {}} { } elseif {$mainheadid ne {} && [commitinview $mainheadid $curview]} {
set pending_select $selid selectline [rowofcommit $mainheadid] 1
} elseif {!$viewcomplete($n)} {
if {$selid ne {}} {
set pending_select $selid
} else {
set pending_select $mainheadid
}
} else { } else {
set row [first_real_row] set row [first_real_row]
if {$row < $numcommits} { if {$row < $numcommits} {
selectline $row 0 selectline $row 0
} else {
set selectfirst 1
} }
} }
if {!$viewcomplete($n)} { if {!$viewcomplete($n)} {
@ -3440,7 +3446,6 @@ proc initlayout {} {
global numcommits canvxmax canv global numcommits canvxmax canv
global nextcolor global nextcolor
global colormap rowtextx global colormap rowtextx
global selectfirst
set numcommits 0 set numcommits 0
set displayorder {} set displayorder {}
@ -3452,7 +3457,6 @@ proc initlayout {} {
set canvxmax [$canv cget -width] set canvxmax [$canv cget -width]
catch {unset colormap} catch {unset colormap}
catch {unset rowtextx} catch {unset rowtextx}
set selectfirst 1
} }
proc setcanvscroll {} { proc setcanvscroll {} {
@ -3486,7 +3490,7 @@ proc visiblerows {} {
proc layoutmore {} { proc layoutmore {} {
global commitidx viewcomplete curview global commitidx viewcomplete curview
global numcommits pending_select selectedline curview global numcommits pending_select selectedline curview
global selectfirst lastscrollset commitinterest global lastscrollset commitinterest
set canshow $commitidx($curview) set canshow $commitidx($curview)
if {$canshow <= $numcommits && !$viewcomplete($curview)} return if {$canshow <= $numcommits && !$viewcomplete($curview)} return
@ -3513,15 +3517,6 @@ proc layoutmore {} {
[commitinview $pending_select $curview]} { [commitinview $pending_select $curview]} {
selectline [rowofcommit $pending_select] 1 selectline [rowofcommit $pending_select] 1
} }
if {$selectfirst} {
if {[info exists selectedline] || [info exists pending_select]} {
set selectfirst 0
} else {
set l [first_real_row]
selectline $l 1
set selectfirst 0
}
}
} }
proc doshowlocalchanges {} { proc doshowlocalchanges {} {