Skip to content

Commit b8a938c

Browse files
committed
gitk: Fix cherry-picking to insert a real row not a fake row
The insertrow/removerow functions were really only suitable for inserting/removing a fake row such as the ones used for showing the local changes. When used to insert a real new row from a cherry-pick, they left things in an inconsistent state which then caused various strange layout errors. This renames insertrow/removerow to insertfakerow/removefakerow and adds a new insertrow that does actually go to all the trouble of creating a new arc and setting it up. This is more work but keeps things consistent. This also fixes a bug where cherrypick was not setting mainheadid, and one where selectline wasn't always resulting in targetrow/id being set to the selected row/id. Also insert/removefakerow now adjust numcommits and call setcanvscroll. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 5a7f577 commit b8a938c

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

gitk

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -568,21 +568,56 @@ proc fix_reversal {p a v} {
568568
}
569569

570570
proc insertrow {id p v} {
571+
global cmitlisted children parents varcid varctok vtokmod
572+
global varccommits ordertok commitidx numcommits curview
573+
global targetid targetrow
574+
575+
readcommit $id
576+
set vid $v,$id
577+
set cmitlisted($vid) 1
578+
set children($vid) {}
579+
set parents($vid) [list $p]
580+
set a [newvarc $v $id]
581+
set varcid($vid) $a
582+
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
583+
modify_arc $v $a
584+
}
585+
lappend varccommits($v,$a) $id
586+
set vp $v,$p
587+
if {[llength [lappend children($vp) $id]] > 1} {
588+
set children($vp) [lsort -command [list vtokcmp $v] $children($vp)]
589+
catch {unset ordertok}
590+
}
591+
fix_reversal $p $a $v
592+
incr commitidx($v)
593+
if {$v == $curview} {
594+
set numcommits $commitidx($v)
595+
setcanvscroll
596+
if {[info exists targetid]} {
597+
if {![comes_before $targetid $p]} {
598+
incr targetrow
599+
}
600+
}
601+
}
602+
}
603+
604+
proc insertfakerow {id p} {
571605
global varcid varccommits parents children cmitlisted
572-
global commitidx varctok vtokmod targetid targetrow
606+
global commitidx varctok vtokmod targetid targetrow curview numcommits
573607

608+
set v $curview
574609
set a $varcid($v,$p)
575610
set i [lsearch -exact $varccommits($v,$a) $p]
576611
if {$i < 0} {
577-
puts "oops: insertrow can't find [shortids $p] on arc $a"
612+
puts "oops: insertfakerow can't find [shortids $p] on arc $a"
578613
return
579614
}
580615
set children($v,$id) {}
581616
set parents($v,$id) [list $p]
582617
set varcid($v,$id) $a
583618
lappend children($v,$p) $id
584619
set cmitlisted($v,$id) 1
585-
incr commitidx($v)
620+
set numcommits [incr commitidx($v)]
586621
# note we deliberately don't update varcstart($v) even if $i == 0
587622
set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id]
588623
if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
@@ -593,31 +628,33 @@ proc insertrow {id p v} {
593628
incr targetrow
594629
}
595630
}
631+
setcanvscroll
596632
drawvisible
597633
}
598634

599-
proc removerow {id v} {
635+
proc removefakerow {id} {
600636
global varcid varccommits parents children commitidx
601637
global varctok vtokmod cmitlisted currentid selectedline
602-
global targetid
638+
global targetid curview numcommits
603639

640+
set v $curview
604641
if {[llength $parents($v,$id)] != 1} {
605-
puts "oops: removerow [shortids $id] has [llength $parents($v,$id)] parents"
642+
puts "oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
606643
return
607644
}
608645
set p [lindex $parents($v,$id) 0]
609646
set a $varcid($v,$id)
610647
set i [lsearch -exact $varccommits($v,$a) $id]
611648
if {$i < 0} {
612-
puts "oops: removerow can't find [shortids $id] on arc $a"
649+
puts "oops: removefakerow can't find [shortids $id] on arc $a"
613650
return
614651
}
615652
unset varcid($v,$id)
616653
set varccommits($v,$a) [lreplace $varccommits($v,$a) $i $i]
617654
unset parents($v,$id)
618655
unset children($v,$id)
619656
unset cmitlisted($v,$id)
620-
incr commitidx($v) -1
657+
set numcommits [incr commitidx($v) -1]
621658
set j [lsearch -exact $children($v,$p) $id]
622659
if {$j >= 0} {
623660
set children($v,$p) [lreplace $children($v,$p) $j $j]
@@ -632,6 +669,7 @@ proc removerow {id v} {
632669
if {[info exists targetid] && $targetid eq $id} {
633670
set targetid $p
634671
}
672+
setcanvscroll
635673
drawvisible
636674
}
637675

@@ -3534,10 +3572,10 @@ proc dohidelocalchanges {} {
35343572
global nullid nullid2 lserial curview
35353573

35363574
if {[commitinview $nullid $curview]} {
3537-
removerow $nullid $curview
3575+
removefakerow $nullid
35383576
}
35393577
if {[commitinview $nullid2 $curview]} {
3540-
removerow $nullid2 $curview
3578+
removefakerow $nullid2
35413579
}
35423580
incr lserial
35433581
}
@@ -3581,11 +3619,11 @@ proc readdiffindex {fd serial} {
35813619
set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
35823620
set commitdata($nullid2) "\n $hl\n"
35833621
if {[commitinview $nullid $curview]} {
3584-
removerow $nullid $curview
3622+
removefakerow $nullid
35853623
}
3586-
insertrow $nullid2 $mainheadid $curview
3624+
insertfakerow $nullid2 $mainheadid
35873625
} elseif {!$isdiff && [commitinview $nullid2 $curview]} {
3588-
removerow $nullid2 $curview
3626+
removefakerow $nullid2
35893627
}
35903628
return 0
35913629
}
@@ -3618,9 +3656,9 @@ proc readdifffiles {fd serial} {
36183656
} else {
36193657
set p $mainheadid
36203658
}
3621-
insertrow $nullid $p $curview
3659+
insertfakerow $nullid $p
36223660
} elseif {!$isdiff && [commitinview $nullid $curview]} {
3623-
removerow $nullid $curview
3661+
removefakerow $nullid
36243662
}
36253663
return 0
36263664
}
@@ -5347,6 +5385,7 @@ proc selectline {l isnew} {
53475385
global commentend idtags linknum
53485386
global mergemax numcommits pending_select
53495387
global cmitmode showneartags allcommits
5388+
global targetrow targetid
53505389

53515390
catch {unset pending_select}
53525391
$canv delete hover
@@ -5399,6 +5438,8 @@ proc selectline {l isnew} {
53995438

54005439
set selectedline $l
54015440
set currentid $id
5441+
set targetid $id
5442+
set targetrow $l
54025443
$sha1entry delete 0 end
54035444
$sha1entry insert 0 $id
54045445
$sha1entry selection from 0
@@ -6995,7 +7036,7 @@ proc mkbrgo {top} {
69957036

69967037
proc cherrypick {} {
69977038
global rowmenuid curview
6998-
global mainhead
7039+
global mainhead mainheadid
69997040

70007041
set oldhead [exec git rev-parse HEAD]
70017042
set dheads [descheads $rowmenuid]
@@ -7026,6 +7067,7 @@ proc cherrypick {} {
70267067
if {$mainhead ne {}} {
70277068
movehead $newhead $mainhead
70287069
movedhead $newhead $mainhead
7070+
set mainheadid $newhead
70297071
}
70307072
redrawtags $oldhead
70317073
redrawtags $newhead
@@ -7035,7 +7077,7 @@ proc cherrypick {} {
70357077
}
70367078

70377079
proc resethead {} {
7038-
global mainheadid mainhead rowmenuid confirm_ok resettype
7080+
global mainhead rowmenuid confirm_ok resettype
70397081

70407082
set confirm_ok 0
70417083
set w ".confirmreset"

0 commit comments

Comments
 (0)