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>
This commit is contained in:
Paul Mackerras
2007-12-26 23:03:43 +11:00
parent 00abadb9dd
commit fc2a256f4a

49
gitk
View File

@ -174,6 +174,7 @@ proc updatecommits {} {
if {$showlocalchanges && [commitinview $mainheadid $curview]} { if {$showlocalchanges && [commitinview $mainheadid $curview]} {
dodiffindex dodiffindex
} }
rereadrefs
set view $curview set view $curview
set commits [exec git rev-parse --default HEAD --revs-only \ set commits [exec git rev-parse --default HEAD --revs-only \
$viewargs($view)] $viewargs($view)]
@ -218,8 +219,6 @@ proc updatecommits {} {
incr viewactive($view) incr viewactive($view)
set viewcomplete($view) 0 set viewcomplete($view) 0
nowbusy $view "Reading" nowbusy $view "Reading"
readrefs
changedrefs
if {$showneartags} { if {$showneartags} {
getallcommits getallcommits
} }
@ -579,7 +578,7 @@ proc insertrow {id p v} {
proc removerow {id v} { proc removerow {id v} {
global varcid varccommits parents children commitidx global varcid varccommits parents children commitidx
global varctok vtokmod cmitlisted global varctok vtokmod cmitlisted currentid selectedline
if {[llength $parents($v,$id)] != 1} { if {[llength $parents($v,$id)] != 1} {
puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents" puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents"
@ -605,6 +604,10 @@ proc removerow {id v} {
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} { if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
modify_arc $v $a $i modify_arc $v $a $i
} }
if {[info exist currentid] && $id eq $currentid} {
unset currentid
unset selectedline
}
drawvisible drawvisible
} }
@ -733,7 +736,7 @@ proc rowofcommit {id} {
return {} return {}
} }
set a $varcid($v,$id) set a $varcid($v,$id)
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] > 0} { if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
update_arcrows $v update_arcrows $v
} }
set i [lsearch -exact $varccommits($v,$a) $id] set i [lsearch -exact $varccommits($v,$a) $id]
@ -3515,7 +3518,7 @@ proc dodiffindex {} {
} }
proc readdiffindex {fd serial} { proc readdiffindex {fd serial} {
global mainheadid nullid2 curview commitinfo commitdata lserial global mainheadid nullid nullid2 curview commitinfo commitdata lserial
set isdiff 1 set isdiff 1
if {[gets $fd line] < 0} { if {[gets $fd line] < 0} {
@ -3541,6 +3544,9 @@ proc readdiffindex {fd serial} {
set hl [mc "Local changes checked in to index but not committed"] set hl [mc "Local changes checked in to index but not committed"]
set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"] set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
set commitdata($nullid2) "\n $hl\n" set commitdata($nullid2) "\n $hl\n"
if {[commitinview $nullid $curview]} {
removerow $nullid $curview
}
insertrow $nullid2 $mainheadid $curview insertrow $nullid2 $mainheadid $curview
} elseif {!$isdiff && [commitinview $nullid2 $curview]} { } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
removerow $nullid2 $curview removerow $nullid2 $curview
@ -5058,7 +5064,9 @@ proc selcanvline {w x y} {
set l 0 set l 0
} }
if {$w eq $canv} { if {$w eq $canv} {
if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return set xmax [lindex [$canv cget -scrollregion] 2]
set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
} }
unmarkmatches unmarkmatches
selectline $l 1 selectline $l 1
@ -5305,13 +5313,12 @@ proc selectline {l isnew} {
make_secsel $l make_secsel $l
set id [commitonrow $l]
if {$isnew} { if {$isnew} {
addtohistory [list selectline $l 0] addtohistory [list selbyid $id]
} }
set selectedline $l set selectedline $l
set id [commitonrow $l]
set currentid $id set currentid $id
$sha1entry delete 0 end $sha1entry delete 0 end
$sha1entry insert 0 $id $sha1entry insert 0 $id
@ -6765,24 +6772,24 @@ proc domktag {} {
} }
proc redrawtags {id} { proc redrawtags {id} {
global canv linehtag idpos selectedline curview global canv linehtag idpos currentid curview
global canvxmax iddrawn global canvxmax iddrawn
if {![commitinview $id $curview]} return if {![commitinview $id $curview]} return
if {![info exists iddrawn($id)]} return if {![info exists iddrawn($id)]} return
drawcommits [rowofcommit $id] set row [rowofcommit $id]
$canv delete tag.$id $canv delete tag.$id
set xt [eval drawtags $id $idpos($id)] set xt [eval drawtags $id $idpos($id)]
$canv coords $linehtag([rowofcommit $id]) $xt [lindex $idpos($id) 2] $canv coords $linehtag($row) $xt [lindex $idpos($id) 2]
set text [$canv itemcget $linehtag([rowofcommit $id]) -text] set text [$canv itemcget $linehtag($row) -text]
set xr [expr {$xt + [font measure mainfont $text]}] set font [$canv itemcget $linehtag($row) -font]
set xr [expr {$xt + [font measure $font $text]}]
if {$xr > $canvxmax} { if {$xr > $canvxmax} {
set canvxmax $xr set canvxmax $xr
setcanvscroll setcanvscroll
} }
if {[info exists selectedline] if {[info exists currentid] && $currentid == $id} {
&& $selectedline == [rowofcommit $id]} { make_secsel $row
selectline $selectedline 0
} }
} }
@ -8342,7 +8349,7 @@ proc changedrefs {} {
} }
proc rereadrefs {} { proc rereadrefs {} {
global idtags idheads idotherrefs mainhead global idtags idheads idotherrefs mainheadid
set refids [concat [array names idtags] \ set refids [concat [array names idtags] \
[array names idheads] [array names idotherrefs]] [array names idheads] [array names idotherrefs]]
@ -8351,7 +8358,7 @@ proc rereadrefs {} {
set ref($id) [listrefs $id] set ref($id) [listrefs $id]
} }
} }
set oldmainhead $mainhead set oldmainhead $mainheadid
readrefs readrefs
changedrefs changedrefs
set refids [lsort -unique [concat $refids [array names idtags] \ set refids [lsort -unique [concat $refids [array names idtags] \
@ -8359,8 +8366,8 @@ proc rereadrefs {} {
foreach id $refids { foreach id $refids {
set v [listrefs $id] set v [listrefs $id]
if {![info exists ref($id)] || $ref($id) != $v || if {![info exists ref($id)] || $ref($id) != $v ||
($id eq $oldmainhead && $id ne $mainhead) || ($id eq $oldmainhead && $id ne $mainheadid) ||
($id eq $mainhead && $id ne $oldmainhead)} { ($id eq $mainheadid && $id ne $oldmainhead)} {
redrawtags $id redrawtags $id
} }
} }