Skip to content

Commit c8a4acb

Browse files
committed
Improve the merge display when the result differs from all parents.
Now we see if the result is quite similar to one of the parents, and if it is, display the result as a diff from that parent. If the result is similar to more than one parent, pick the one that it's most similar to.
1 parent 73b6a6c commit c8a4acb

File tree

1 file changed

+84
-7
lines changed

1 file changed

+84
-7
lines changed

gitk

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,6 @@ proc processgroup {} {
20542054
set pnum 0
20552055
foreach p $parents($id) {
20562056
set startline [expr {$grouplinestart + $diffoffset($p)}]
2057-
set offset($p) $diffoffset($p)
20582057
set ol $startline
20592058
set nl $grouplinestart
20602059
if {[info exists grouphunks($p)]} {
@@ -2098,9 +2097,8 @@ proc processgroup {} {
20982097
set events [lsort -integer -index 0 $events]
20992098
set nevents [llength $events]
21002099
set nmerge $nparents($diffmergeid)
2101-
set i 0
21022100
set l $grouplinestart
2103-
while {$i < $nevents} {
2101+
for {set i 0} {$i < $nevents} {set i $j} {
21042102
set nl [lindex $events $i 0]
21052103
while {$l < $nl} {
21062104
$ctext insert end " $filelines($id,$f,$l)\n"
@@ -2129,7 +2127,9 @@ proc processgroup {} {
21292127
}
21302128
set nlc [expr {$enl - $l}]
21312129
set ncol mresult
2130+
set bestpn -1
21322131
if {[llength $active] == $nmerge - 1} {
2132+
# no diff for one of the parents, i.e. it's identical
21332133
for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
21342134
if {![info exists delta($pnum)]} {
21352135
if {$pnum < $mergemax} {
@@ -2140,11 +2140,25 @@ proc processgroup {} {
21402140
break
21412141
}
21422142
}
2143+
} elseif {[llength $active] == $nmerge} {
2144+
# all parents are different, see if one is very similar
2145+
set bestsim 30
2146+
for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
2147+
set sim [similarity $pnum $l $nlc $f \
2148+
[lrange $events $i [expr {$j-1}]]]
2149+
if {$sim > $bestsim} {
2150+
set bestsim $sim
2151+
set bestpn $pnum
2152+
}
2153+
}
2154+
if {$bestpn >= 0} {
2155+
lappend ncol m$bestpn
2156+
}
21432157
}
21442158
set pnum -1
21452159
foreach p $parents($id) {
21462160
incr pnum
2147-
if {![info exists delta($pnum)]} continue
2161+
if {![info exists delta($pnum)] || $pnum == $bestpn} continue
21482162
set olc [expr {$nlc + $delta($pnum)}]
21492163
set ol [expr {$l + $diffoffset($p)}]
21502164
incr diffoffset($p) $delta($pnum)
@@ -2154,11 +2168,35 @@ proc processgroup {} {
21542168
incr ol
21552169
}
21562170
}
2157-
for {} {$nlc > 0} {incr nlc -1} {
2171+
set endl [expr {$l + $nlc}]
2172+
if {$bestpn >= 0} {
2173+
# show this pretty much as a normal diff
2174+
set p [lindex $parents($id) $bestpn]
2175+
set ol [expr {$l + $diffoffset($p)}]
2176+
incr diffoffset($p) $delta($bestpn)
2177+
unset delta($bestpn)
2178+
for {set k $i} {$k < $j} {incr k} {
2179+
set e [lindex $events $k]
2180+
if {[lindex $e 2] != $bestpn} continue
2181+
set nl [lindex $e 0]
2182+
set ol [expr {$ol + $nl - $l}]
2183+
for {} {$l < $nl} {incr l} {
2184+
$ctext insert end "+$filelines($id,$f,$l)\n" $ncol
2185+
}
2186+
set c [lindex $e 3]
2187+
for {} {$c > 0} {incr c -1} {
2188+
$ctext insert end "-$filelines($p,$f,$ol)\n" m$bestpn
2189+
incr ol
2190+
}
2191+
set nl [lindex $e 1]
2192+
for {} {$l < $nl} {incr l} {
2193+
$ctext insert end "+$filelines($id,$f,$l)\n" mresult
2194+
}
2195+
}
2196+
}
2197+
for {} {$l < $endl} {incr l} {
21582198
$ctext insert end "+$filelines($id,$f,$l)\n" $ncol
2159-
incr l
21602199
}
2161-
set i $j
21622200
}
21632201
while {$l < $grouplineend} {
21642202
$ctext insert end " $filelines($id,$f,$l)\n"
@@ -2167,6 +2205,45 @@ proc processgroup {} {
21672205
$ctext conf -state disabled
21682206
}
21692207

2208+
proc similarity {pnum l nlc f events} {
2209+
global diffmergeid parents diffoffset filelines
2210+
2211+
set id $diffmergeid
2212+
set p [lindex $parents($id) $pnum]
2213+
set ol [expr {$l + $diffoffset($p)}]
2214+
set endl [expr {$l + $nlc}]
2215+
set same 0
2216+
set diff 0
2217+
foreach e $events {
2218+
if {[lindex $e 2] != $pnum} continue
2219+
set nl [lindex $e 0]
2220+
set ol [expr {$ol + $nl - $l}]
2221+
for {} {$l < $nl} {incr l} {
2222+
incr same [string length $filelines($id,$f,$l)]
2223+
incr same
2224+
}
2225+
set oc [lindex $e 3]
2226+
for {} {$oc > 0} {incr oc -1} {
2227+
incr diff [string length $filelines($p,$f,$ol)]
2228+
incr diff
2229+
incr ol
2230+
}
2231+
set nl [lindex $e 1]
2232+
for {} {$l < $nl} {incr l} {
2233+
incr diff [string length $filelines($id,$f,$l)]
2234+
incr diff
2235+
}
2236+
}
2237+
for {} {$l < $endl} {incr l} {
2238+
incr same [string length $filelines($id,$f,$l)]
2239+
incr same
2240+
}
2241+
if {$same == 0} {
2242+
return 0
2243+
}
2244+
return [expr {200 * $same / (2 * $same + $diff)}]
2245+
}
2246+
21702247
proc startdiff {ids} {
21712248
global treediffs diffids treepending diffmergeid
21722249

0 commit comments

Comments
 (0)