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 <paulus@samba.org>
Paul Mackerras committed
May 26, 2008 at 10:11 UTC
c11ff120f359bd7bd79c425135f85e1dca5ae252
1 file changed
+30
-20
gitk
+30
-20
@@ -296,7 +296,7 @@ proc start_rev_list {view} {
296
global startmsecs commitidx viewcomplete curview
297
global commfd leftover tclencoding
298
global viewargs viewargscmd viewfiles vfilelimit
299
- global showlocalchanges commitinterest mainheadid
299
+ global showlocalchanges commitinterest
300
global viewactive loginstance viewinstances vmergeonly
301
global pending_select mainheadid
302
global vcanopt vflags vrevs vorigargs
@@ -358,7 +358,7 @@ proc start_rev_list {view} {
358
set viewinstances($view) [list $i]
359
set commfd($i) $fd
360
set leftover($i) {}
361
- if {$showlocalchanges} {
361
+ if {$showlocalchanges && $mainheadid ne {}} {
362
lappend commitinterest($mainheadid) {dodiffindex}
363
}
364
fconfigure $fd -blocking 0 -translation lf -eofchar {}
@@ -406,7 +406,7 @@ proc getcommits {} {
406
407
proc updatecommits {} {
408
global curview vcanopt vorigargs vfilelimit viewinstances
409
- global viewactive viewcomplete loginstance tclencoding mainheadid
409
+ global viewactive viewcomplete loginstance tclencoding
410
global startmsecs commfd showneartags showlocalchanges leftover
411
global mainheadid pending_select
412
global isworktree
@@ -1467,7 +1467,6 @@ proc chewcommits {} {
1467
if {$viewcomplete($curview)} {
1468
global commitidx varctok
1469
global numcommits startmsecs
1470
- global mainheadid nullid
1470
1471
if {[info exists pending_select]} {
1472
set row [first_real_row]
@@ -1604,12 +1603,10 @@ proc readrefs {} {
1603
set mainhead {}
1604
set mainheadid {}
1605
catch {
1606
+ set mainheadid [exec git rev-parse HEAD]
1607
set thehead [exec git symbolic-ref HEAD]
1608
if {[string match "refs/heads/*" $thehead]} {
1609
set mainhead [string range $thehead 11 end]
1610
- if {[info exists headids($mainhead)]} {
1611
- set mainheadid $headids($mainhead)
1612
- }
1610
}
1611
}
1612
}
@@ -4022,6 +4019,7 @@ proc layoutmore {} {
4019
proc doshowlocalchanges {} {
4020
global curview mainheadid
4021
4022
+ if {$mainheadid eq {}} return
4023
if {[commitinview $mainheadid $curview]} {
4024
dodiffindex
4025
} else {
@@ -4841,7 +4839,8 @@ proc drawcmittext {id row col} {
4839
global cmitlisted commitinfo rowidlist parentlist
4840
global rowtextx idpos idtags idheads idotherrefs
4841
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
4844
4845
# listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
4846
set listed $cmitlisted($curview,$id)
@@ -4849,8 +4848,10 @@ proc drawcmittext {id row col} {
4848
set ofill red
4849
} elseif {$id eq $nullid2} {
4850
set ofill green
4851
+ } elseif {$id eq $mainheadid} {
4852
+ set ofill yellow
4853
} else {
4853
- set ofill [expr {$listed != 0 ? $listed == 2 ? "gray" : "blue" : "white"}]
4854
+ set ofill [lindex $circlecolors $listed]
4855
}
4856
set x [xc $row $col]
4857
set y [yc $row]
@@ -4874,6 +4875,7 @@ proc drawcmittext {id row col} {
4875
[expr {$x - $orad}] [expr {$y + $orad - 1}] \
4876
-fill $ofill -outline $fgcolor -width 1 -tags circle]
4877
}
4878
+ set circleitem($row) $t
4879
$canv raise $t
4880
$canv bind $t <1> {selcanvline {} %x %y}
4881
set rmx [llength [lindex $rowidlist $row]]
@@ -7399,12 +7401,18 @@ proc domktag {} {
7401
}
7402
7403
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
7406
7407
if {![commitinview $id $curview]} return
7408
if {![info exists iddrawn($id)]} return
7409
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
7416
$canv delete tag.$id
7417
set xt [eval drawtags $id $idpos($id)]
7418
$canv coords $linehtag($row) $xt [lindex $idpos($id) 2]
@@ -7574,8 +7582,8 @@ proc cherrypick {} {
7582
if {$mainhead ne {}} {
7583
movehead $newhead $mainhead
7584
movedhead $newhead $mainhead
7577
- set mainheadid $newhead
7585
}
7586
+ set mainheadid $newhead
7587
redrawtags $oldhead
7588
redrawtags $newhead
7589
selbyid $newhead
@@ -7675,7 +7683,7 @@ proc headmenu {x y id head} {
7683
}
7684
7685
proc cobranch {} {
7678
- global headmenuid headmenuhead mainhead headids
7686
+ global headmenuid headmenuhead headids
7687
global showlocalchanges mainheadid
7688
7689
# check the tree is clean first??
@@ -7711,12 +7719,10 @@ proc readcheckoutstat {fd newhead newheadid} {
7719
if {[catch {close $fd} err]} {
7720
error_popup $err
7721
}
7714
- set oldmainhead $mainhead
7722
+ set oldmainid $mainheadid
7723
set mainhead $newhead
7724
set mainheadid $newheadid
7717
- if {[info exists headids($oldmainhead)]} {
7718
- redrawtags $headids($oldmainhead)
7719
- }
7725
+ redrawtags $oldmainid
7726
redrawtags $newheadid
7727
selbyid $newheadid
7728
if {$showlocalchanges} {
@@ -9016,12 +9022,14 @@ proc rereadrefs {} {
9022
[array names idheads] [array names idotherrefs]]]
9023
foreach id $refids {
9024
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} {
9026
redrawtags $id
9027
}
9028
}
9029
+ if {$oldmainhead ne $mainheadid} {
9030
+ redrawtags $oldmainhead
9031
+ redrawtags $mainheadid
9032
+ }
9033
run refill_reflist
9034
}
9035
@@ -9761,6 +9769,8 @@ set diffcontext 3
9769
set ignorespace 0
9770
set selectbgcolor gray85
9771
9772
+set circlecolors {white blue gray blue blue}
9773
+
9774
## For msgcat loading, first locate the installation location.
9775
if { [info exists ::env(GITK_MSGSDIR)] } {
9776
## Msgsdir was manually set in the environment.