@matheusbsbs / matheus-bagliano / commits / 89b11d3ba5
Fork 0

gitk: Fix file list display when files are renamed

The conversion of the file list to use a text widget assumed incorrectly that the list of files from git-diff-tree -r would correspond 1-1 with the diff sections in the output of git-diff-tree -r -p -C, which is not true when renames are detected. This fixes it by keeping the elements in the difffilestart list in the order they appear in the file list window. Since this means that the elements of difffilestart are no longer necessarily in ascending order, it's somewhat hard to do the dynamic highlighting in the file list as the diff window is scrolled, so I have taken that out for now. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed May 2, 2006 at 19:55 UTC 89b11d3ba5132e44cc04826c297a34e31788d0ab
1 file changed +29 -62
gitk
+29 -62
@@ -512,7 +512,7 @@ proc makewindow {} {
512 set ctext .ctop.cdet.left.ctext
513 text $ctext -bg white -state disabled -font $textfont \
514 -width $geometry(ctextw) -height $geometry(ctexth) \
515 - -yscrollcommand scrolltext -wrap none
515 + -yscrollcommand {.ctop.cdet.left.sb set} -wrap none
516 scrollbar .ctop.cdet.left.sb -command "$ctext yview"
517 pack .ctop.cdet.left.sb -side right -fill y
518 pack $ctext -side left -fill both -expand 1
@@ -562,7 +562,8 @@ proc makewindow {} {
562 scrollbar .ctop.cdet.right.sb -command "$cflist yview"
563 pack .ctop.cdet.right.sb -side right -fill y
564 pack $cflist -side left -fill both -expand 1
565 - $cflist tag configure highlight -background yellow
565 + $cflist tag configure highlight \
566 + -background [$cflist cget -selectbackground]
567 .ctop.cdet add .ctop.cdet.right
568 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
569
@@ -1092,14 +1093,13 @@ image create bitmap tri-dn -background black -foreground blue -data {
1093 }
1094
1095 proc init_flist {first} {
1095 - global cflist cflist_top cflist_bot selectedline difffilestart
1096 + global cflist cflist_top selectedline difffilestart
1097
1098 $cflist conf -state normal
1099 $cflist delete 0.0 end
1100 if {$first ne {}} {
1101 $cflist insert end $first
1102 set cflist_top 1
1102 - set cflist_bot 1
1103 $cflist tag add highlight 1.0 "1.0 lineend"
1104 } else {
1105 catch {unset cflist_top}
@@ -1126,61 +1126,14 @@ proc sel_flist {w x y} {
1126 if {$cmitmode eq "tree"} return
1127 if {![info exists cflist_top]} return
1128 set l [lindex [split [$w index "@$x,$y"] "."] 0]
1129 + $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
1130 + $cflist tag add highlight $l.0 "$l.0 lineend"
1131 + set cflist_top $l
1132 if {$l == 1} {
1133 $ctext yview 1.0
1134 } else {
1135 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
1136 }
1134 - highlight_flist $l
1135 -}
1136 -
1137 -proc scrolltext {f0 f1} {
1138 - global cflist_top
1139 -
1140 - .ctop.cdet.left.sb set $f0 $f1
1141 - if {[info exists cflist_top]} {
1142 - highlight_flist $cflist_top
1143 - }
1144 -}
1145 -
1146 -# Given an index $tl in the $ctext window, this works out which line
1147 -# of the $cflist window displays the filename whose patch is shown
1148 -# at the given point in the $ctext window. $ll is a hint about which
1149 -# line it might be, and is used as the starting point of the search.
1150 -proc ctext_index {tl ll} {
1151 - global ctext difffilestart
1152 -
1153 - while {$ll >= 2 && [$ctext compare $tl < \
1154 - [lindex $difffilestart [expr {$ll - 2}]]]} {
1155 - incr ll -1
1156 - }
1157 - set nfiles [llength $difffilestart]
1158 - while {$ll - 1 < $nfiles && [$ctext compare $tl >= \
1159 - [lindex $difffilestart [expr {$ll - 1}]]]} {
1160 - incr ll
1161 - }
1162 - return $ll
1163 -}
1164 -
1165 -proc highlight_flist {ll} {
1166 - global ctext cflist cflist_top cflist_bot difffilestart
1167 -
1168 - if {![info exists difffilestart] || [llength $difffilestart] == 0} return
1169 - set ll [ctext_index [$ctext index @0,1] $ll]
1170 - set lb $cflist_bot
1171 - if {$lb < $ll} {
1172 - set lb $ll
1173 - }
1174 - set y [expr {[winfo height $ctext] - 2}]
1175 - set lb [ctext_index [$ctext index @0,$y] $lb]
1176 - if {$ll != $cflist_top || $lb != $cflist_bot} {
1177 - $cflist tag remove highlight $cflist_top.0 "$cflist_bot.0 lineend"
1178 - for {set l $ll} {$l <= $lb} {incr l} {
1179 - $cflist tag add highlight $l.0 "$l.0 lineend"
1180 - }
1181 - set cflist_top $ll
1182 - set cflist_bot $lb
1183 - }
1137 }
1138
1139 # Code to implement multiple views
@@ -3561,8 +3514,6 @@ proc getmergediffline {mdf id np} {
3514 # start of a new file
3515 $ctext insert end "\n"
3516 set here [$ctext index "end - 1c"]
3564 - $ctext mark set f:$fname $here
3565 - $ctext mark gravity f:$fname left
3517 lappend difffilestart $here
3518 add_flist [list $fname]
3519 set l [expr {(78 - [string length $fname]) / 2}]
@@ -3693,6 +3644,19 @@ proc getblobdiffs {ids} {
3644 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
3645 }
3646
3647 +proc setinlist {var i val} {
3648 + global $var
3649 +
3650 + while {[llength [set $var]] < $i} {
3651 + lappend $var {}
3652 + }
3653 + if {[llength [set $var]] == $i} {
3654 + lappend $var $val
3655 + } else {
3656 + lset $var $i $val
3657 + }
3658 +}
3659 +
3660 proc getblobdiffline {bdf ids} {
3661 global diffids blobdifffd ctext curdifftag curtagstart
3662 global diffnexthead diffnextnote difffilestart
@@ -3719,12 +3683,15 @@ proc getblobdiffline {bdf ids} {
3683 set here [$ctext index "end - 1c"]
3684 set curtagstart $here
3685 set header $newname
3722 - lappend difffilestart $here
3723 - $ctext mark set f:$fname $here
3724 - $ctext mark gravity f:$fname left
3725 - if {$newname != $fname} {
3726 - $ctext mark set f:$newfname $here
3727 - $ctext mark gravity f:$newfname left
3686 + set i [lsearch -exact $treediffs($ids) $fname]
3687 + if {$i >= 0} {
3688 + setinlist difffilestart $i $here
3689 + }
3690 + if {$newname ne $fname} {
3691 + set i [lsearch -exact $treediffs($ids) $newname]
3692 + if {$i >= 0} {
3693 + setinlist difffilestart $i $here
3694 + }
3695 }
3696 set curdifftag "f:$fname"
3697 $ctext tag delete $curdifftag