Skip to content

Commit c11ff12

Browse files
committed
gitk: Handle detached heads better
This draws the currently checked-out head with a yellow circle, as suggested by Linus Torvalds, and fixes various places in the code where we assumed that the current head always had a branch. Now we can display the fake commits for local changes on a detached head. Signed-off-by: Paul Mackerras <[email protected]>
1 parent a977953 commit c11ff12

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

gitk

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ proc start_rev_list {view} {
296296
global startmsecs commitidx viewcomplete curview
297297
global commfd leftover tclencoding
298298
global viewargs viewargscmd viewfiles vfilelimit
299-
global showlocalchanges commitinterest mainheadid
299+
global showlocalchanges commitinterest
300300
global viewactive loginstance viewinstances vmergeonly
301301
global pending_select mainheadid
302302
global vcanopt vflags vrevs vorigargs
@@ -358,7 +358,7 @@ proc start_rev_list {view} {
358358
set viewinstances($view) [list $i]
359359
set commfd($i) $fd
360360
set leftover($i) {}
361-
if {$showlocalchanges} {
361+
if {$showlocalchanges && $mainheadid ne {}} {
362362
lappend commitinterest($mainheadid) {dodiffindex}
363363
}
364364
fconfigure $fd -blocking 0 -translation lf -eofchar {}
@@ -406,7 +406,7 @@ proc getcommits {} {
406406

407407
proc updatecommits {} {
408408
global curview vcanopt vorigargs vfilelimit viewinstances
409-
global viewactive viewcomplete loginstance tclencoding mainheadid
409+
global viewactive viewcomplete loginstance tclencoding
410410
global startmsecs commfd showneartags showlocalchanges leftover
411411
global mainheadid pending_select
412412
global isworktree
@@ -1467,7 +1467,6 @@ proc chewcommits {} {
14671467
if {$viewcomplete($curview)} {
14681468
global commitidx varctok
14691469
global numcommits startmsecs
1470-
global mainheadid nullid
14711470

14721471
if {[info exists pending_select]} {
14731472
set row [first_real_row]
@@ -1604,12 +1603,10 @@ proc readrefs {} {
16041603
set mainhead {}
16051604
set mainheadid {}
16061605
catch {
1606+
set mainheadid [exec git rev-parse HEAD]
16071607
set thehead [exec git symbolic-ref HEAD]
16081608
if {[string match "refs/heads/*" $thehead]} {
16091609
set mainhead [string range $thehead 11 end]
1610-
if {[info exists headids($mainhead)]} {
1611-
set mainheadid $headids($mainhead)
1612-
}
16131610
}
16141611
}
16151612
}
@@ -4022,6 +4019,7 @@ proc layoutmore {} {
40224019
proc doshowlocalchanges {} {
40234020
global curview mainheadid
40244021

4022+
if {$mainheadid eq {}} return
40254023
if {[commitinview $mainheadid $curview]} {
40264024
dodiffindex
40274025
} else {
@@ -4841,16 +4839,19 @@ proc drawcmittext {id row col} {
48414839
global cmitlisted commitinfo rowidlist parentlist
48424840
global rowtextx idpos idtags idheads idotherrefs
48434841
global linehtag linentag linedtag selectedline
4844-
global canvxmax boldrows boldnamerows fgcolor nullid nullid2
4842+
global canvxmax boldrows boldnamerows fgcolor
4843+
global mainheadid nullid nullid2 circleitem circlecolors
48454844

48464845
# listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
48474846
set listed $cmitlisted($curview,$id)
48484847
if {$id eq $nullid} {
48494848
set ofill red
48504849
} elseif {$id eq $nullid2} {
48514850
set ofill green
4851+
} elseif {$id eq $mainheadid} {
4852+
set ofill yellow
48524853
} else {
4853-
set ofill [expr {$listed != 0 ? $listed == 2 ? "gray" : "blue" : "white"}]
4854+
set ofill [lindex $circlecolors $listed]
48544855
}
48554856
set x [xc $row $col]
48564857
set y [yc $row]
@@ -4874,6 +4875,7 @@ proc drawcmittext {id row col} {
48744875
[expr {$x - $orad}] [expr {$y + $orad - 1}] \
48754876
-fill $ofill -outline $fgcolor -width 1 -tags circle]
48764877
}
4878+
set circleitem($row) $t
48774879
$canv raise $t
48784880
$canv bind $t <1> {selcanvline {} %x %y}
48794881
set rmx [llength [lindex $rowidlist $row]]
@@ -7399,12 +7401,18 @@ proc domktag {} {
73997401
}
74007402

74017403
proc redrawtags {id} {
7402-
global canv linehtag idpos currentid curview
7403-
global canvxmax iddrawn
7404+
global canv linehtag idpos currentid curview cmitlisted
7405+
global canvxmax iddrawn circleitem mainheadid circlecolors
74047406

74057407
if {![commitinview $id $curview]} return
74067408
if {![info exists iddrawn($id)]} return
74077409
set row [rowofcommit $id]
7410+
if {$id eq $mainheadid} {
7411+
set ofill yellow
7412+
} else {
7413+
set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
7414+
}
7415+
$canv itemconf $circleitem($row) -fill $ofill
74087416
$canv delete tag.$id
74097417
set xt [eval drawtags $id $idpos($id)]
74107418
$canv coords $linehtag($row) $xt [lindex $idpos($id) 2]
@@ -7574,8 +7582,8 @@ proc cherrypick {} {
75747582
if {$mainhead ne {}} {
75757583
movehead $newhead $mainhead
75767584
movedhead $newhead $mainhead
7577-
set mainheadid $newhead
75787585
}
7586+
set mainheadid $newhead
75797587
redrawtags $oldhead
75807588
redrawtags $newhead
75817589
selbyid $newhead
@@ -7675,7 +7683,7 @@ proc headmenu {x y id head} {
76757683
}
76767684

76777685
proc cobranch {} {
7678-
global headmenuid headmenuhead mainhead headids
7686+
global headmenuid headmenuhead headids
76797687
global showlocalchanges mainheadid
76807688

76817689
# check the tree is clean first??
@@ -7711,12 +7719,10 @@ proc readcheckoutstat {fd newhead newheadid} {
77117719
if {[catch {close $fd} err]} {
77127720
error_popup $err
77137721
}
7714-
set oldmainhead $mainhead
7722+
set oldmainid $mainheadid
77157723
set mainhead $newhead
77167724
set mainheadid $newheadid
7717-
if {[info exists headids($oldmainhead)]} {
7718-
redrawtags $headids($oldmainhead)
7719-
}
7725+
redrawtags $oldmainid
77207726
redrawtags $newheadid
77217727
selbyid $newheadid
77227728
if {$showlocalchanges} {
@@ -9016,12 +9022,14 @@ proc rereadrefs {} {
90169022
[array names idheads] [array names idotherrefs]]]
90179023
foreach id $refids {
90189024
set v [listrefs $id]
9019-
if {![info exists ref($id)] || $ref($id) != $v ||
9020-
($id eq $oldmainhead && $id ne $mainheadid) ||
9021-
($id eq $mainheadid && $id ne $oldmainhead)} {
9025+
if {![info exists ref($id)] || $ref($id) != $v} {
90229026
redrawtags $id
90239027
}
90249028
}
9029+
if {$oldmainhead ne $mainheadid} {
9030+
redrawtags $oldmainhead
9031+
redrawtags $mainheadid
9032+
}
90259033
run refill_reflist
90269034
}
90279035

@@ -9761,6 +9769,8 @@ set diffcontext 3
97619769
set ignorespace 0
97629770
set selectbgcolor gray85
97639771

9772+
set circlecolors {white blue gray blue blue}
9773+
97649774
## For msgcat loading, first locate the installation location.
97659775
if { [info exists ::env(GITK_MSGSDIR)] } {
97669776
## Msgsdir was manually set in the environment.

0 commit comments

Comments
 (0)