Skip to content

Commit fc2a256

Browse files
committed
gitk: Fix another collection of bugs
* Fixed a bug that occasionally resulted in Tcl "can't use empty string as argument to incr" errors - rowofcommit was sometimes not calling update_arcrows when it needed to. * Fixed a "no such element in array" error when removing a fake row, by unsetting currentid and selectedline in removerow if the row we are removing is the currently selected row. * Made the "update commits" function always do "reread references". * Made dodiffindex et al. remove the fake row(s) if necessary. * Fixed a bug where clicking on a row in the graph display pane didn't account for horizontal scrolling of the pane. * Started changing things that cached information based on row numbers to use commit IDs instead -- this converts the "select line" items that are put into the history list to use "select by ID" instead. * Simplified redrawtags a bit, and fixed a bug where it would use the mainfont for working out how far it extends to the right in the graph display pane rather than the actual font (which might be bold). * Fixed a bug where "reread references" wouldn't notice if the currently checked-out head had changed. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 00abadb commit fc2a256

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

gitk

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ proc updatecommits {} {
174174
if {$showlocalchanges && [commitinview $mainheadid $curview]} {
175175
dodiffindex
176176
}
177+
rereadrefs
177178
set view $curview
178179
set commits [exec git rev-parse --default HEAD --revs-only \
179180
$viewargs($view)]
@@ -218,8 +219,6 @@ proc updatecommits {} {
218219
incr viewactive($view)
219220
set viewcomplete($view) 0
220221
nowbusy $view "Reading"
221-
readrefs
222-
changedrefs
223222
if {$showneartags} {
224223
getallcommits
225224
}
@@ -579,7 +578,7 @@ proc insertrow {id p v} {
579578

580579
proc removerow {id v} {
581580
global varcid varccommits parents children commitidx
582-
global varctok vtokmod cmitlisted
581+
global varctok vtokmod cmitlisted currentid selectedline
583582

584583
if {[llength $parents($v,$id)] != 1} {
585584
puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents"
@@ -605,6 +604,10 @@ proc removerow {id v} {
605604
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
606605
modify_arc $v $a $i
607606
}
607+
if {[info exist currentid] && $id eq $currentid} {
608+
unset currentid
609+
unset selectedline
610+
}
608611
drawvisible
609612
}
610613

@@ -733,7 +736,7 @@ proc rowofcommit {id} {
733736
return {}
734737
}
735738
set a $varcid($v,$id)
736-
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] > 0} {
739+
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
737740
update_arcrows $v
738741
}
739742
set i [lsearch -exact $varccommits($v,$a) $id]
@@ -3515,7 +3518,7 @@ proc dodiffindex {} {
35153518
}
35163519

35173520
proc readdiffindex {fd serial} {
3518-
global mainheadid nullid2 curview commitinfo commitdata lserial
3521+
global mainheadid nullid nullid2 curview commitinfo commitdata lserial
35193522

35203523
set isdiff 1
35213524
if {[gets $fd line] < 0} {
@@ -3541,6 +3544,9 @@ proc readdiffindex {fd serial} {
35413544
set hl [mc "Local changes checked in to index but not committed"]
35423545
set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
35433546
set commitdata($nullid2) "\n $hl\n"
3547+
if {[commitinview $nullid $curview]} {
3548+
removerow $nullid $curview
3549+
}
35443550
insertrow $nullid2 $mainheadid $curview
35453551
} elseif {!$isdiff && [commitinview $nullid2 $curview]} {
35463552
removerow $nullid2 $curview
@@ -5058,7 +5064,9 @@ proc selcanvline {w x y} {
50585064
set l 0
50595065
}
50605066
if {$w eq $canv} {
5061-
if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
5067+
set xmax [lindex [$canv cget -scrollregion] 2]
5068+
set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
5069+
if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
50625070
}
50635071
unmarkmatches
50645072
selectline $l 1
@@ -5305,13 +5313,12 @@ proc selectline {l isnew} {
53055313

53065314
make_secsel $l
53075315

5316+
set id [commitonrow $l]
53085317
if {$isnew} {
5309-
addtohistory [list selectline $l 0]
5318+
addtohistory [list selbyid $id]
53105319
}
53115320

53125321
set selectedline $l
5313-
5314-
set id [commitonrow $l]
53155322
set currentid $id
53165323
$sha1entry delete 0 end
53175324
$sha1entry insert 0 $id
@@ -6765,24 +6772,24 @@ proc domktag {} {
67656772
}
67666773

67676774
proc redrawtags {id} {
6768-
global canv linehtag idpos selectedline curview
6775+
global canv linehtag idpos currentid curview
67696776
global canvxmax iddrawn
67706777

67716778
if {![commitinview $id $curview]} return
67726779
if {![info exists iddrawn($id)]} return
6773-
drawcommits [rowofcommit $id]
6780+
set row [rowofcommit $id]
67746781
$canv delete tag.$id
67756782
set xt [eval drawtags $id $idpos($id)]
6776-
$canv coords $linehtag([rowofcommit $id]) $xt [lindex $idpos($id) 2]
6777-
set text [$canv itemcget $linehtag([rowofcommit $id]) -text]
6778-
set xr [expr {$xt + [font measure mainfont $text]}]
6783+
$canv coords $linehtag($row) $xt [lindex $idpos($id) 2]
6784+
set text [$canv itemcget $linehtag($row) -text]
6785+
set font [$canv itemcget $linehtag($row) -font]
6786+
set xr [expr {$xt + [font measure $font $text]}]
67796787
if {$xr > $canvxmax} {
67806788
set canvxmax $xr
67816789
setcanvscroll
67826790
}
6783-
if {[info exists selectedline]
6784-
&& $selectedline == [rowofcommit $id]} {
6785-
selectline $selectedline 0
6791+
if {[info exists currentid] && $currentid == $id} {
6792+
make_secsel $row
67866793
}
67876794
}
67886795

@@ -8342,7 +8349,7 @@ proc changedrefs {} {
83428349
}
83438350

83448351
proc rereadrefs {} {
8345-
global idtags idheads idotherrefs mainhead
8352+
global idtags idheads idotherrefs mainheadid
83468353

83478354
set refids [concat [array names idtags] \
83488355
[array names idheads] [array names idotherrefs]]
@@ -8351,16 +8358,16 @@ proc rereadrefs {} {
83518358
set ref($id) [listrefs $id]
83528359
}
83538360
}
8354-
set oldmainhead $mainhead
8361+
set oldmainhead $mainheadid
83558362
readrefs
83568363
changedrefs
83578364
set refids [lsort -unique [concat $refids [array names idtags] \
83588365
[array names idheads] [array names idotherrefs]]]
83598366
foreach id $refids {
83608367
set v [listrefs $id]
83618368
if {![info exists ref($id)] || $ref($id) != $v ||
8362-
($id eq $oldmainhead && $id ne $mainhead) ||
8363-
($id eq $mainhead && $id ne $oldmainhead)} {
8369+
($id eq $oldmainhead && $id ne $mainheadid) ||
8370+
($id eq $mainheadid && $id ne $oldmainhead)} {
83648371
redrawtags $id
83658372
}
83668373
}

0 commit comments

Comments
 (0)