Skip to content

Commit 7eab293

Browse files
Paul Mackerraspaulusmack
authored andcommitted
Handle the rename cases reported by git-diff-tree -C correctly.
1 parent 3c461ff commit 7eab293

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

gitk

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ proc gettreediffline {gdtf ids} {
18611861

18621862
proc getblobdiffs {ids} {
18631863
global diffopts blobdifffd diffids env curdifftag curtagstart
1864-
global diffindex difffilestart nextupdate diffinhdr
1864+
global difffilestart nextupdate diffinhdr treediffs
18651865

18661866
set id [lindex $ids 0]
18671867
set p [lindex $ids 1]
@@ -1876,16 +1876,15 @@ proc getblobdiffs {ids} {
18761876
set blobdifffd($ids) $bdf
18771877
set curdifftag Comments
18781878
set curtagstart 0.0
1879-
set diffindex 0
18801879
catch {unset difffilestart}
18811880
fileevent $bdf readable [list getblobdiffline $bdf $diffids]
18821881
set nextupdate [expr {[clock clicks -milliseconds] + 100}]
18831882
}
18841883

18851884
proc getblobdiffline {bdf ids} {
18861885
global diffids blobdifffd ctext curdifftag curtagstart
1887-
global diffnexthead diffnextnote diffindex difffilestart
1888-
global nextupdate diffinhdr
1886+
global diffnexthead diffnextnote difffilestart
1887+
global nextupdate diffinhdr treediffs
18891888
global gaudydiff
18901889

18911890
set n [gets $bdf line]
@@ -1902,18 +1901,29 @@ proc getblobdiffline {bdf ids} {
19021901
return
19031902
}
19041903
$ctext conf -state normal
1905-
if {[regexp {^diff --git a/(.*) b/} $line match fname]} {
1904+
if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
19061905
# start of a new file
19071906
$ctext insert end "\n"
19081907
$ctext tag add $curdifftag $curtagstart end
19091908
set curtagstart [$ctext index "end - 1c"]
1910-
set header $fname
1909+
set header $newname
19111910
set here [$ctext index "end - 1c"]
1912-
set difffilestart($diffindex) $here
1913-
incr diffindex
1914-
# start mark names at fmark.1 for first file
1915-
$ctext mark set fmark.$diffindex $here
1916-
$ctext mark gravity fmark.$diffindex left
1911+
set i [lsearch -exact $treediffs($diffids) $fname]
1912+
if {$i >= 0} {
1913+
set difffilestart($i) $here
1914+
incr i
1915+
$ctext mark set fmark.$i $here
1916+
$ctext mark gravity fmark.$i left
1917+
}
1918+
if {$newname != $fname} {
1919+
set i [lsearch -exact $treediffs($diffids) $newname]
1920+
if {$i >= 0} {
1921+
set difffilestart($i) $here
1922+
incr i
1923+
$ctext mark set fmark.$i $here
1924+
$ctext mark gravity fmark.$i left
1925+
}
1926+
}
19171927
set curdifftag "f:$fname"
19181928
$ctext tag delete $curdifftag
19191929
set l [expr {(78 - [string length $header]) / 2}]
@@ -1973,14 +1983,19 @@ proc nextfile {} {
19731983
set here [$ctext index @0,0]
19741984
for {set i 0} {[info exists difffilestart($i)]} {incr i} {
19751985
if {[$ctext compare $difffilestart($i) > $here]} {
1976-
$ctext yview $difffilestart($i)
1977-
break
1986+
if {![info exists pos]
1987+
|| [$ctext compare $difffilestart($i) < $pos]} {
1988+
set pos $difffilestart($i)
1989+
}
19781990
}
19791991
}
1992+
if {[info exists pos]} {
1993+
$ctext yview $pos
1994+
}
19801995
}
19811996

19821997
proc listboxsel {} {
1983-
global ctext cflist currentid treediffs
1998+
global ctext cflist currentid
19841999
if {![info exists currentid]} return
19852000
set sel [lsort [$cflist curselection]]
19862001
if {$sel eq {}} return

0 commit comments

Comments
 (0)