Eskil

Diff
Login

Differences From Artifact [6733d55f1e]:

To Artifact [a39eecbf2b]:


517
518
519
520
521
522
523
524
525




526
527
528
529
530
531
532
517
518
519
520
521
522
523


524
525
526
527
528
529
530
531
532
533
534







-
-
+
+
+
+







    if {$Pref(parse) != 0} {
        set opts $Pref(ignore)
        if {$Pref(nocase)} {lappend opts -nocase}
        if {$Pref(lineparsewords)} {lappend opts -words}
        set res [eval DiffUtil::diffStrings $opts \$line1 \$line2]
        set dotag 0
        set n [expr {[llength $res] / 2}]
        $::widgets($top,wLine1) insert end [myFormL $doingLine1] "hl$::HighLightCount change"
        $::widgets($top,wLine2) insert end [myFormL $doingLine2] "hl$::HighLightCount change"
        $::widgets($top,wLine1) insert end [myFormL $doingLine1] \
                "hl$::HighLightCount change"
        $::widgets($top,wLine2) insert end [myFormL $doingLine2] \
                "hl$::HighLightCount change"
        set new1 "new1"
        set new2 "new2"
        set change "change"
        foreach {i1 i2} $res {
            incr n -1
            if {$dotag} {
                if {$n == 1 && $Pref(marklast)} {
798
799
800
801
802
803
804




805
806
807
808
809
810
811
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817







+
+
+
+







    foreach item {wLine1 wDiff1 wLine2 wDiff2} {
        if {[info exists ::widgets($top,$item)]} {
            set w $::widgets($top,$item)
            $w config -cursor $oldcursor2
        }
    }
}

#####################################
# Special cases.  Conflict/patch
#####################################

# Read a conflict file and extract the two versions.
proc prepareConflict {top} {
    global Pref

    set ::diff($top,leftFile) [tmpFile]
    set ::diff($top,rightFile) [tmpFile]
829
830
831
832
833
834
835
836

837
838
839
840
841
842
843
835
836
837
838
839
840
841

842
843
844
845
846
847
848
849







-
+







            set state left
            set end2 [expr {$rightLine - 1}]
            set start1 $leftLine
        } elseif {[string match >>>>>>* $line] && $state eq "left"} {
            set state both
            regexp {>*\s*(.*)} $line -> leftName
            set end1 [expr {$leftLine - 1}]
            lappend diff($top,conflictDiff) [list \
            lappend ::diff($top,conflictDiff) [list \
                    $start1 [expr {$end1 - $start1 + 1}] \
                    $start2 [expr {$end2 - $start2 + 1}]]
        } elseif {$state eq "both"} {
            puts $ch1 $line
            puts $ch2 $line
            incr leftLine
            incr rightLine
1102
1103
1104
1105
1106
1107
1108




1109
1110
1111
1112
1113
1114
1115
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125







+
+
+
+







    if {$state != "none"} {
        displayOnePatch $top $leftLines $rightLines $leftLine $rightLine
    }

    close $ch
}

#####################################
# Revision control systems support
#####################################

# Get a CVS revision
proc getCvsRev {filename outfile {rev {}}} {
    set old ""
    set dir [file dirname $filename]
    if {$dir != "."} {
        set old [pwd]
        set outfile [file join [pwd] $outfile]
1144
1145
1146
1147
1148
1149
1150
1151
1152


1153
















1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164

1165

1166
1167
1168
1169
1170
1171





1172
1173
1174
1175
1176
1177
1178
1179
1180
1181












1182


1183
1184
1185




1186
1187
1188
1189
1190
1191
1192
1193
1194









1195
1196
1197
1198
1199
1200





1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211













1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230

1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296



1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1154
1155
1156
1157
1158
1159
1160


1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192






1193
1194
1195
1196
1197










1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212



1213
1214
1215
1216
1217








1218
1219
1220
1221
1222
1223
1224
1225
1226






1227
1228
1229
1230
1231
1232










1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260




1261












1262


















1263







1264




















1265
1266
1267
1268




1269
1270
1271




1272
1273
1274
1275
1276
1277
1278







-
-
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











+
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+















-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
+
+
+
-
-
-
-







    set filerev [file nativename $filename@@[file join $stream $rev]]
    if {[catch {exec cleartool get -to $outfile $filerev} msg]} {
        tk_messageBox -icon error -title "Cleartool error" -message $msg
        return
    }
}

# Prepare for RCS/CVS diff. Checkout copies of the versions needed.
proc prepareRCS {top} {
# Prepare for RCS/CVS/CT diff. Checkout copies of the versions needed.
proc prepareRev {top} {
    global Pref

    set type $::diff($top,modetype)

    if {$type eq "CT"} {
        # Figure out stream and current version
        if {[catch {exec cleartool ls $::diff($top,RevFile)} info]} {
            tk_messageBox -icon error -title "Cleartool error" -message $info
            return
        }
        set currV {}
        if {![regexp {@@(\S+)\s+from (\S+)\s+Rule} $info -> dummy currV]} {
            regexp {@@(\S+)} $info -> currV
        }
        set stream [file dirname $currV]
        set latest [file tail $currV]
    }

    set revs {}

    # Search for revision options
    if {$::diff($top,doptrev1) != ""} {
        lappend revs $::diff($top,doptrev1)
    }
    if {$::diff($top,doptrev2) != ""} {
        lappend revs $::diff($top,doptrev2)
    }

    if {$type eq "CT"} {
    switch [llength $revs] {
        foreach rev $revs {
        0 {
            # Compare local file with latest version.
            set ::diff($top,leftFile) [tmpFile]
            set ::diff($top,rightLabel) $::diff($top,RevFile)
            set ::diff($top,rightFile)  $::diff($top,RevFile)

            if {![string is digit -strict $rev] || $rev < 0 || $rev > $latest} {
                tk_messageBox -icon error -title "Cleartool error" \
                        -message "Bad revision '$rev'"
                return
            }
            set type $::diff($top,modetype)
            set ::diff($top,leftLabel) "$::diff($top,RevFile) ($type)"
            if {$type eq "CVS"} {
                getCvsRev $::diff($top,RevFile) $::diff($top,leftFile)
            } else {
                getRcsRev $::diff($top,RevFile) $::diff($top,leftFile)
            }
        }
        1 {
            # Compare local file with specified version.
        }
    }

    if {[llength $revs] < 2} {
        # Compare local file with specified version.
        if {[llength $revs] == 0} {
            set r ""
            if {$type eq "CT"} {
                set r $latest
            }
            set tag "($type)"
        } else {
            set r [lindex $revs 0]
            set tag "($type $r)"
        }
            set ::diff($top,leftFile) [tmpFile]
            set ::diff($top,rightLabel) $::diff($top,RevFile)
            set ::diff($top,rightFile) $::diff($top,RevFile)
        set ::diff($top,leftFile) [tmpFile]
        set ::diff($top,leftLabel) "$::diff($top,RevFile) $tag"
        set ::diff($top,rightLabel) $::diff($top,RevFile)
        set ::diff($top,rightFile) $::diff($top,RevFile)

            set type $::diff($top,modetype)
            set ::diff($top,leftLabel) "$::diff($top,RevFile) ($type $r)"
            if {$type eq "CVS"} {
                getCvsRev $::diff($top,RevFile) $::diff($top,leftFile) $r
            } else {
                getRcsRev $::diff($top,RevFile) $::diff($top,leftFile) $r
            }
        }
        if {$type eq "CVS"} {
            getCvsRev $::diff($top,RevFile) $::diff($top,leftFile) $r
        } elseif {$type eq "RCS"} {
            getRcsRev $::diff($top,RevFile) $::diff($top,leftFile) $r
        } else {
            getCtRev $::diff($top,RevFile) $::diff($top,leftFile) \
                    $stream $r
        }
    } else {
        default {
            # Compare the two specified versions.
            set r1 [lindex $revs 0]
            set r2 [lindex $revs 1]
            set ::diff($top,leftFile) [tmpFile]
            set ::diff($top,rightFile) [tmpFile]
        # Compare the two specified versions.
        set r1 [lindex $revs 0]
        set r2 [lindex $revs 1]
        set ::diff($top,leftFile) [tmpFile]
        set ::diff($top,rightFile) [tmpFile]

            set type $::diff($top,modetype)
            set ::diff($top,leftLabel) "$::diff($top,RevFile) ($type $r1)"
            set ::diff($top,rightLabel) "$::diff($top,RevFile) ($type $r2)"
            if {$type eq "CVS"} {
                getCvsRev $::diff($top,RevFile) $::diff($top,leftFile) $r1
                getCvsRev $::diff($top,RevFile) $::diff($top,rightFile) $r2
            } else {
                getRcsRev $::diff($top,RevFile) $::diff($top,leftFile) $r1
                getRcsRev $::diff($top,RevFile) $::diff($top,rightFile) $r2
            }
        set ::diff($top,leftLabel) "$::diff($top,RevFile) ($type $r1)"
        set ::diff($top,rightLabel) "$::diff($top,RevFile) ($type $r2)"
        if {$type eq "CVS"} {
            getCvsRev $::diff($top,RevFile) $::diff($top,leftFile) $r1
            getCvsRev $::diff($top,RevFile) $::diff($top,rightFile) $r2
        } elseif {$type eq "RCS"} {
            getRcsRev $::diff($top,RevFile) $::diff($top,leftFile) $r1
            getRcsRev $::diff($top,RevFile) $::diff($top,rightFile) $r2
        } else {
            getCtRev $::diff($top,RevFile) $::diff($top,leftFile) \
                    $stream $r1
            getCtRev $::diff($top,RevFile) $::diff($top,rightFile) \
                    $stream $r2
        }
    }
    # Make sure labels are updated before processing starts
    update idletasks
}

# Clean up after a RCS/CVS/CT diff.
proc cleanupRev {top} {
    global Pref

    clearTmp $::diff($top,rightFile) $::diff($top,leftFile)
    set ::diff($top,rightFile) $::diff($top,RevFile)
    set ::diff($top,leftFile) $::diff($top,RevFile)
}

# Prepare for ClearCase diff. Checkout copies of the versions needed.
proc prepareClearCase {top} {
    global Pref

#####################################
    # Figure out stream and current version
    if {[catch {exec cleartool ls $::diff($top,RevFile)} info]} {
        puts "Cleartool error: $info"
        return
    }
    set currV {}
    if {![regexp {@@(\S+)\s+from (\S+)\s+Rule} $info -> dummy currV]} {
        regexp {@@(\S+)} $info -> currV
    }
    set stream [file dirname $currV]
    set latest [file tail $currV]

# Main diff
    # Search for revision options
    set revs {}
    if {$::diff($top,doptrev1) != ""} {
        lappend revs $::diff($top,doptrev1)
    }
    if {$::diff($top,doptrev2) != ""} {
        lappend revs $::diff($top,doptrev2)
    }
    foreach rev $revs {
        if {![string is digit -strict $rev] || $rev < 0 || $rev > $latest} {
            puts "Bad revision '$rev'"
            return
        }
    }
    if {[llength $revs] == 0} {
        lappend revs $latest
    }

#####################################
    switch [llength $revs] {
        1 {
            # Compare local file with specified version.
            set r [lindex $revs 0]
            set ::diff($top,leftFile) [tmpFile]
            set ::diff($top,rightLabel) $::diff($top,RevFile)
            set ::diff($top,rightFile) $::diff($top,RevFile)

            set ::diff($top,leftLabel) "$::diff($top,RevFile) (CT $r)"

            getCtRev $::diff($top,RevFile) $::diff($top,leftFile) $stream $r
        }
        default {
            # Compare the two specified versions.
            set r1 [lindex $revs 0]
            set r2 [lindex $revs 1]
            set ::diff($top,leftFile) [tmpFile]
            set ::diff($top,rightFile) [tmpFile]

            set ::diff($top,leftLabel) "$::diff($top,RevFile) (CT $r1)"
            set ::diff($top,rightLabel) "$::diff($top,RevFile) (CT $r2)"

            getCtRev $::diff($top,RevFile) $::diff($top,leftFile) $stream $r1
            getCtRev $::diff($top,RevFile) $::diff($top,rightFile) $stream $r2
        }
    }
}

# Prepare for a diff by creating needed temporary files
proc prepareFiles {top} {
    set ::diff($top,cleanup) ""
    if {$::diff($top,mode) eq "rev"} {
        if {$::diff($top,modetype) eq "RCS" || $::diff($top,modetype) eq "CVS"} {
            prepareRCS $top
            set ::diff($top,cleanup) "rev"
        } elseif {$::diff($top,modetype) eq "CT"} {
        prepareRev $top
        set ::diff($top,cleanup) "rev"
    } elseif {$::diff($top,mode) eq "conflict"} {
            prepareClearCase $top
            set ::diff($top,cleanup) "rev"
        }
    } elseif {"conflict" eq $::diff($top,mode)} {
        prepareConflict $top
        set ::diff($top,cleanup) "conflict"
    }
}

# Clean up after a diff
proc cleanupFiles {top} {
1496
1497
1498
1499
1500
1501
1502
1503

1504
1505
1506
1507
1508
1509
1510
1467
1468
1469
1470
1471
1472
1473

1474
1475
1476
1477
1478
1479
1480
1481







-
+







    normalCursor $top
    showDiff $top 0
    if {$::widgets($top,eqLabel) eq "!"} {
        set ::widgets($top,eqLabel) " "
    }

    cleanupFiles $top
    if {"conflict" eq $::diff($top,mode)} {
    if {$::diff($top,mode) eq "conflict"} {
        if {$::widgets($top,eqLabel) != "="} {
            makeMergeWin $top
        }
    }
    if {$::diff($top,printFile) != ""} {
        after idle "doPrint $top 1 ; cleanupAndExit all"
    }
1604
1605
1606
1607
1608
1609
1610
1611

1612
1613

1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632

1633
1634

1635
1636
1637
1638
1639
1640
1641
1575
1576
1577
1578
1579
1580
1581

1582
1583

1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602

1603
1604

1605
1606
1607
1608
1609
1610
1611
1612







-
+

-
+


















-
+

-
+







            }
        }
    }
    return [eval tk_getOpenFile $args]
}

proc doOpenLeft {top {forget 0}} {
    if {!$forget && [info exists diff($top,leftDir)]} {
    if {!$forget && [info exists ::diff($top,leftDir)]} {
        set initDir $::diff($top,leftDir)
    } elseif {[info exists diff($top,rightDir)]} {
    } elseif {[info exists ::diff($top,rightDir)]} {
        set initDir $::diff($top,rightDir)
    } else {
        set initDir [pwd]
    }

    set apa [myOpenFile -title "Select left file" -initialdir $initDir \
            -parent $top]
    if {$apa != ""} {
        set ::diff($top,leftDir) [file dirname $apa]
        set ::diff($top,leftFile) $apa
        set ::diff($top,leftLabel) $apa
        set ::diff($top,leftOK) 1
        return 1
    }
    return 0
}

proc doOpenRight {top {forget 0}} {
    if {!$forget && [info exists diff($top,rightDir)]} {
    if {!$forget && [info exists ::diff($top,rightDir)]} {
        set initDir $::diff($top,rightDir)
    } elseif {[info exists diff($top,leftDir)]} {
    } elseif {[info exists ::diff($top,leftDir)]} {
        set initDir $::diff($top,leftDir)
    } else {
        set initDir [pwd]
    }

    set apa [myOpenFile -title "Select right file" -initialdir $initDir \
            -parent $top]
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791

1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1753
1754
1755
1756
1757
1758
1759



1760




1761
1762
1763
1764
1765
1766
1767







-
-
-
+
-
-
-
-







    set leftMergeData {}
    set rightMergeData {}

    if {![info exists ::diff($top,changes)]} {
        set ::diff($top,changes) {}
    }

    if {$::diff($top,mode) eq "rev"} {
        if {$::diff($top,modetype) eq "RCS" || $::diff($top,modetype) eq "CVS"} {
            prepareRCS $top
    prepareFiles $top
        }
    } elseif {"conflict" eq $::diff($top,mode)} {
        prepareConflict $top
    }

    set ch1 [open $::diff($top,leftFile) r]
    set ch2 [open $::diff($top,rightFile) r]
    set doingLine1 1
    set doingLine2 1
    set changeNo 0
    foreach change $::diff($top,changes) {
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854

1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1810
1811
1812
1813
1814
1815
1816



1817




1818
1819
1820
1821
1822
1823
1824







-
-
-
+
-
-
-
-







    }
    lappend leftMergeData $data1
    lappend rightMergeData $data2

    close $ch1
    close $ch2

    if {$::diff($top,mode) eq "rev"} {
        if {$::diff($top,modetype) eq "RCS" || $::diff($top,modetype) eq "CVS"} {
            cleanupRev $top
    cleanupFiles $top
        }
    } elseif {"conflict" eq $::diff($top,mode)} {
        cleanupConflict $top
    }
}

# Fill up the merge window with the initial version of merged files.
proc fillMergeWindow {top} {
    global mergeSelection leftMergeData rightMergeData curMergeSel curMerge

    set w $top.merge.t
1955
1956
1957
1958
1959
1960
1961
1962

1963
1964
1965
1966
1967
1968
1969
1970
1971

1972
1973

1974
1975
1976
1977
1978
1979
1980
1914
1915
1916
1917
1918
1919
1920

1921
1922
1923
1924
1925
1926
1927
1928
1929

1930
1931

1932
1933
1934
1935
1936
1937
1938
1939







-
+








-
+

-
+








# Save the merge result.
proc saveMerge {top} {
    set w $top.merge.t

    if {$::diff($top,mergeFile) eq ""} {
        set apa no
        if {"conflict" eq $::diff($top,mode)} {
        if {$::diff($top,mode) eq "conflict"} {
            set apa [tk_messageBox -parent $top.merge -icon question \
                    -title "Save merge file" -type yesno -message \
                    "Do you want to overwrite the original conflict file?"]
        }
        if {$apa == "yes"} {
            set ::diff($top,mergeFile) $::diff($top,conflictFile)
        } else {
            # Browse
            if {[info exists diff($top,rightDir)]} {
            if {[info exists ::diff($top,rightDir)]} {
                set initDir $::diff($top,rightDir)
            } elseif {[info exists diff($top,leftDir)]} {
            } elseif {[info exists ::diff($top,leftDir)]} {
                set initDir $::diff($top,leftDir)
            } else {
                set initDir [pwd]
            }

            set apa [tk_getSaveFile -title "Save merge file" -initialdir $initDir \
                    -parent $top.merge]
2039
2040
2041
2042
2043
2044
2045
2046

2047
2048
2049
2050
2051
2052
2053
1998
1999
2000
2001
2002
2003
2004

2005
2006
2007
2008
2009
2010
2011
2012







-
+







    wm protocol $w WM_DELETE_WINDOW "closeMerge $top"

    grid $w.f.rb1 $w.f.rb2 $w.f.rb3 $w.f.rb4 x $w.f.b1 $w.f.b2 x \
            $w.f.bl $w.f.br x x x $w.f.bs $w.f.bq
    grid columnconfigure $w.f {4 7 10 12} -minsize 10
    grid columnconfigure $w.f 10 -weight 1

    if {"conflict" eq $::diff($top,mode)} {
    if {$::diff($top,mode) eq "conflict"} {
        checkbutton $w.f.bm -text "Pure" -variable diff($top,modetype) \
                -onvalue "Pure" -offvalue "" -command {doDiff}
        grid $w.f.bm -row 0 -column 11
    }

    text $w.t -width 80 -height 20 -xscrollcommand "$w.sbx set" \
            -yscrollcommand "$w.sby set" -font myfont
4201
4202
4203
4204
4205
4206
4207
4208

4209
4210
4211
4212
4213
4214
4215
4160
4161
4162
4163
4164
4165
4166

4167
4168
4169
4170
4171
4172
4173
4174







-
+







    if {[winfo exists $top] && [winfo toplevel $top] eq $top} {
        raise $top
        focus -force $top
        return
    }
    destroy $top
    toplevel $top
    lappend diff(diffWindows) $top
    lappend ::diff(diffWindows) $top

    wm title $top "Clip Diff"
    wm protocol $top WM_DELETE_WINDOW "cleanupAndExit $top"
    set t1 [Scroll both \
            text $top.t1 -width 60 -height 35 -font myfont]
    set t2 [Scroll both \
            text $top.t2 -width 60 -height 35 -font myfont]