@@ -2054,7 +2054,6 @@ proc processgroup {} {
2054
2054
set pnum 0
2055
2055
foreach p $parents($id) {
2056
2056
set startline [expr {$grouplinestart + $diffoffset($p) }]
2057
- set offset($p ) $diffoffset($p)
2058
2057
set ol $startline
2059
2058
set nl $grouplinestart
2060
2059
if {[info exists grouphunks($p )]} {
@@ -2098,9 +2097,8 @@ proc processgroup {} {
2098
2097
set events [lsort -integer -index 0 $events ]
2099
2098
set nevents [llength $events ]
2100
2099
set nmerge $nparents($diffmergeid)
2101
- set i 0
2102
2100
set l $grouplinestart
2103
- while { $i < $nevents } {
2101
+ for { set i 0} { $i < $nevents } { set i $j } {
2104
2102
set nl [lindex $events $i 0]
2105
2103
while {$l < $nl } {
2106
2104
$ctext insert end " $filelines($id,$f,$l) \n "
@@ -2129,7 +2127,9 @@ proc processgroup {} {
2129
2127
}
2130
2128
set nlc [expr {$enl - $l }]
2131
2129
set ncol mresult
2130
+ set bestpn -1
2132
2131
if {[llength $active ] == $nmerge - 1} {
2132
+ # no diff for one of the parents, i.e. it's identical
2133
2133
for {set pnum 0} {$pnum < $nmerge } {incr pnum} {
2134
2134
if {![info exists delta($pnum )]} {
2135
2135
if {$pnum < $mergemax } {
@@ -2140,11 +2140,25 @@ proc processgroup {} {
2140
2140
break
2141
2141
}
2142
2142
}
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
+ }
2143
2157
}
2144
2158
set pnum -1
2145
2159
foreach p $parents($id) {
2146
2160
incr pnum
2147
- if {![info exists delta($pnum )]} continue
2161
+ if {![info exists delta($pnum )] || $pnum == $bestpn } continue
2148
2162
set olc [expr {$nlc + $delta($pnum) }]
2149
2163
set ol [expr {$l + $diffoffset($p) }]
2150
2164
incr diffoffset($p ) $delta($pnum)
@@ -2154,11 +2168,35 @@ proc processgroup {} {
2154
2168
incr ol
2155
2169
}
2156
2170
}
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} {
2158
2198
$ctext insert end " +$filelines($id,$f,$l) \n " $ncol
2159
- incr l
2160
2199
}
2161
- set i $j
2162
2200
}
2163
2201
while {$l < $grouplineend } {
2164
2202
$ctext insert end " $filelines($id,$f,$l) \n "
@@ -2167,6 +2205,45 @@ proc processgroup {} {
2167
2205
$ctext conf -state disabled
2168
2206
}
2169
2207
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
+
2170
2247
proc startdiff {ids} {
2171
2248
global treediffs diffids treepending diffmergeid
2172
2249
0 commit comments