234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
|
# Replace with checkout copy
set files($field) [tmpFile]
eskil::rev::$revtype($field)::get $origfiles($field) \
$files($field) $revs($field)
}
}
# Handle at least base options
set opts $::Pref(ignore)
if {$::Pref(nocase)} {lappend opts -nocase}
if {$::Pref(noempty)} {lappend opts -noempty}
if {$::Pref(pivot) > 0} {lappend opts -pivot $::Pref(pivot)}
# Do compare of files, to generate patches
foreach side {1 2} {
set differr [catch {DiffUtil::diffFiles {*}$opts \
$files(base$side) $files(change$side)} diffres]
if {$differr != 0} {
# TODO error
return
set header ""
}
set outfile($side) [tmpFile]
set ch [open $outfile($side) w]
foreach str {From To} field "base$side change$side" {
set line "$str $origfiles($field)"
if {$revs($field) ne ""} {
append line " Revision $revs($field)"
if {$origrevs($field) ne $revs($field)} {
append line " ($origrevs($field))"
}
}
append header $line\n
}
set outfile($side) [tmpFile]
$self GenPatch $header $files(base$side) $files(change$side) \
$outfile($side)
}
# Now run a diff window with the patch files
set top [newDiff $outfile(1) $outfile(2)]
}
method GenPatch {header file1 file2 outfile} {
# Handle at least base options
set opts $::Pref(ignore)
if {$::Pref(nocase)} {lappend opts -nocase}
if {$::Pref(noempty)} {lappend opts -noempty}
if {$::Pref(pivot) > 0} {lappend opts -pivot $::Pref(pivot)}
set differr [catch {DiffUtil::diffFiles {*}$opts \
$file1 $file2} diffres]
set ch [open $outfile w]
if {$differr != 0} {
# TODO error
puts $ch $line
}
puts $ch [string repeat "-" 78]
puts $ch $diffres
close $ch
return
}
puts $ch [string trim $header]
puts $ch [string repeat "-" 78]
if {[llength $diffres] == 0} {
}
set doingLine1 1
set doingLine2 1
set ch1 [open $files(base$side)]
set ch2 [open $files(change$side)]
set doingLine1 1
set doingLine2 1
set ch1 [open $file1]
set ch2 [open $file2]
set t 0
foreach i $diffres {
lassign $i line1 n1 line2 n2
$self doText $ch $ch1 $ch2 $n1 $n2 $line1 $line2
}
$self doText $ch $ch1 $ch2 0 0 0 0
close $ch1
close $ch2
close $ch
foreach i $diffres {
lassign $i line1 n1 line2 n2
$self DoText $ch $ch1 $ch2 $n1 $n2 $line1 $line2
}
$self DoText $ch $ch1 $ch2 0 0 0 0
close $ch1
close $ch2
close $ch
}
# Now run a diff window with the patch files
set top [newDiff $outfile(1) $outfile(2)]
}
# See dotext in eskil.tcl for more info since this is similar
method doText {ch ch1 ch2 n1 n2 line1 line2} {
method DoText {ch ch1 ch2 n1 n2 line1 line2} {
if {$n1 == 0 && $n2 == 0} {
# All blocks have been processed. Continue until end of file.
# TBD context
return
}
set limit 3
if {($line1 - $doingLine1 < (2 * $limit + 2))} {
|