Eskil

Diff
Login

Differences From Artifact [bdd66f182d]:

To Artifact [e934b59c77]:


41
42
43
44
45
46
47





48
49
50
51


52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68


69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93

94
95
96
97
98

99
100
101
102
103
104
105
41
42
43
44
45
46
47
48
49
50
51
52
53
54


55
56
57
58

59
60
61








62
63


64
65
66
67
68
69

70
71
72
73
74
75
76
77
78




79
80

81
82
83
84
85

86
87
88
89
90

91
92
93
94
95
96
97
98







+
+
+
+
+


-
-
+
+


-
+


-
-
-
-
-
-
-
-


-
-
+
+




-
+








-
-
-
-


-
+




-
+




-
+







    
    if {[lindex [lsort -dictionary [list $s1 $s2]] 0] eq $s1} {
        return -1
    }
    return 1
}

# Sort file names
proc Fsort {l} {
    lsort -dictionary $l
}

# Compare two files or dirs
# Return true if equal
proc CompareFiles {fileD1 fileD2} {
    if {[dict size $fileD1] == 0} {
proc CompareFiles {file1 file2} {
    if {[catch {file lstat $file1 stat1}]} {
        return 0
    }
    if {[dict size $fileD2] == 0} {
    if {[catch {file lstat $file2 stat2}]} {
        return 0
    }
    set file1 [dict get $fileD1 full]
    set file2 [dict get $fileD2 full]
    set type1 [dict get $fileD1 type]
    set type2 [dict get $fileD2 type]
    set size1 [dict get $fileD1 size]
    set size2 [dict get $fileD2 size]
    set mtime1 [dict get $fileD1 mtime]
    set mtime2 [dict get $fileD2 mtime]

    # Same type?
    set isdir1 [dict get $fileD1 dir]
    set isdir2 [dict get $fileD2 dir]
    set isdir1 [FileIsDirectory $file1]
    set isdir2 [FileIsDirectory $file2]
    if {$isdir1 != $isdir2} {
	return 0
    }
    # Handle links
    if {$type1 eq "link" && $type2 eq "link"} {
    if {$stat1(type) eq "link" && $stat2(type) eq "link"} {
        set l1 [file link $file1]
        set l2 [file link $file2]
        # Equal links are considered equal, otherwise check contents
        if {$l1 eq $l2} {
            return 1
        }
        file stat $file1 stat1
        file stat $file2 stat2
        set size1 $stat1(size)
        set size2 $stat2(size)
        set mtime1 $stat1(mtime)
        set mtime2 $stat2(mtime)
    }
    # If contents is not checked, same size is enough to be equal
    if {$size1 == $size2 && $::Pref(dir,comparelevel) == 0} {
    if {$stat1(size) == $stat2(size) && $::Pref(dir,comparelevel) == 0} {
        return 1
    }
    set ignorekey $::Pref(dir,ignorekey)
    # Different size is enough when doing binary compare
    if {$size1 != $size2 && $::Pref(dir,comparelevel) == 2 \
    if {$stat1(size) != $stat2(size) && $::Pref(dir,comparelevel) == 2 \
        && !$ignorekey} {
        return 0
    }
    # Same size and time is always considered equal
    if {$size1 == $size2 && $mtime1 == $mtime2} {
    if {$stat1(size) == $stat2(size) && $stat1(mtime) == $stat2(mtime)} {
	return 1
    }
    # Don't check further if contents should not be checked
    if {$::Pref(dir,comparelevel) == 0} {
        return 0
    }
    # Don't check further if any is a directory
149
150
151
152
153
154
155
156

157
158
159

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205








206
207
208
209
210





211
212
213



214
215
216
217
218
219
220







221
222
223
224


225
226
227
228

229
230
231
232
233
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
142
143
144
145
146
147
148

149



150
151
152
153
154
155
156




























157
158
159









160
161
162
163
164
165
166
167





168
169
170
171
172



173
174
175







176
177
178
179
180
181
182

183


184
185
186
187
188

189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205

206
207
208
209

210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226

227
228
229

230
231
232
233
234
235
236
237







-
+
-
-
-
+






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



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

-
-
+
+



-
+







-
+








-
+



-
+







-
+








-
+


-
+







            close $ch1
            close $ch2
        }
    }
    return $eq
}

# Returns the contents of a directory as a sorted list of file dicts
# Returns the contents of a directory as a sorted list of full file paths.
# By collecting as much as possible in one place, this prepares for a
# future expansion into revision control support in dirdiff.
proc DirContentsDRaw {dir prefsD} {
proc DirContents {dir} {
    if {$::tcl_platform(platform) eq "windows"} {
        # .-files are not treated specially on windows. * is enough to get all
        set files [glob -directory $dir -nocomplain *]
    } else {
        set files [glob -directory $dir -nocomplain * {.[a-zA-Z]*}]
    }
    set result {}
    foreach file [lsort -dictionary $files] {
        set fD [dict create "full" $file]
        dict set fD tail [file tail $file]
        dict set fD "dir" [FileIsDirectory $file]
        if {[catch {file stat $file stat}]} {
            dict set fD size ""
            dict set fD mtime ""
            dict set fD type ""
        } else {
            dict set fD size $stat(size)
            dict set fD mtime $stat(mtime)
            dict set fD type $stat(type)
        }
        lappend result $fD
    }
    return $result
}

# Returns the contents of a directory as a sorted list of dicts, after applying
# filter preferences.
proc DirContentsD {dir prefsD} {
    set pIncDirs [dict get $prefsD incdirs]
    set pExDirs [dict get $prefsD exdirs]
    set pIncFiles [dict get $prefsD incfiles]
    set pExFiles [dict get $prefsD exfiles]

    set filesD [DirContentsDRaw $dir $prefsD]

    if {$::Pref(dir,onlyrev)} {
        # FIXA: move to rev and make general for other systems
        # FIXA: obsolete, not updated since before dictinaries were used
        #set entries [file join $dir CVS Entries]
        #if {[file exists $entries]} {
        #    set ch [open $entries r]
        #    set data [read $ch]
        #    close $ch
        #    foreach line [split $data \n] {
        #        set name [lindex [split $line /] 1]
        #        set controlled($name) 1
        set entries [file join $dir CVS Entries]
        if {[file exists $entries]} {
            set ch [open $entries r]
            set data [read $ch]
            close $ch
            foreach line [split $data \n] {
                set name [lindex [split $line /] 1]
                set controlled($name) 1
        #    }
        #    set files2 {}
        #    foreach file $files {
        #        if {[info exists controlled($file)]} {
        #            lappend files2 $file
            }
            set files2 {}
            foreach file $files {
                if {[info exists controlled($file)]} {
                    lappend files2 $file
        #        }
        #    }
        #    set files $files2
                }
            }
            set files $files2
        #}
    }

    set filesD2 {}
    foreach fileD $filesD {
        set full [dict get $fileD full]
        set tail [dict get $fileD tail]
        }
    }

    set files2 {}
    foreach file $files {
        set full $file
        set tail [file tail $file]
        set isDir [dict get $fileD "dir"]
        # Apply filters
        if {$isDir} {
            if {[llength $pIncDirs] == 0} {
        if {[FileIsDirectory $full]} {
            if {[llength $::Pref(dir,incdirs)] == 0} {
                set allowed 1
            } else {
                set allowed 0
                foreach pat $pIncDirs {
                foreach pat $::Pref(dir,incdirs) {
                    if {[string match $pat $tail]} {
                        set allowed 1
                        break
                    }
                }
            }
            if {$allowed} {
                foreach pat $pExDirs {
                foreach pat $::Pref(dir,exdirs) {
                    if {[string match $pat $tail]} {
                        set allowed 0
                        break
                    }
                }
            }
            if {!$allowed} continue
        } else {
            if {[llength $pIncFiles] == 0} {
            if {[llength $::Pref(dir,incfiles)] == 0} {
                set allowed 1
            } else {
                set allowed 0
                foreach pat $pIncFiles {
                foreach pat $::Pref(dir,incfiles) {
                    if {[string match $pat $tail]} {
                        set allowed 1
                        break
                    }
                }
            }
            if {$allowed} {
                foreach pat $pExFiles {
                foreach pat $::Pref(dir,exfiles) {
                    if {[string match $pat $tail]} {
                        set allowed 0
                        break
                    }
                }
            }
            if {!$allowed} continue
        }
        lappend filesD2 $fileD
        lappend files2 $full
    }

    return $filesD2
    return [Fsort $files2]
}

# Bring up an editor to display a file.
proc EditFile {file} {
    locateEditor ::util(editor)
    exec $::util(editor) $file &
}
432
433
434
435
436
437
438
439

440
441

442
443
444
445
446
447
448
449
393
394
395
396
397
398
399

400


401

402
403
404
405
406
407
408







-
+
-
-
+
-







            $tree cellconfigure $topIndex,structure -text $d1
        } else {
            $tree cellconfigure $topIndex,structure -text "$d1 vs $d2"
        }
        $tree cellconfigure $topIndex,structure -image $::img(open)
        $tree rowattrib $topIndex type directory
        $self SetNodeStatus $topIndex empty
        $tree rowattrib $topIndex leftfull $leftDir
        $tree rowattrib $topIndex leftfull $leftDir             
        $tree rowattrib $topIndex leftdict [dict create full $leftDir dir 1]
        $tree rowattrib $topIndex rightfull $rightDir
        $tree rowattrib $topIndex rightfull $rightDir            
        $tree rowattrib $topIndex rightdict [dict create full $rightDir dir 1]

        $self UpdateDirNode $topIndex
    }

    method expandCmd {tbl row} {
        if {[$tree childcount $row] != 0} {
            $tree cellconfigure $row,0 -image $::img(open)
778
779
780
781
782
783
784
785
786
787



788
789
790
791
792
793
794
795
796
797

798
799

800
801
802
803
804
805
806
807



808
809
810

811
812
813
814
815
816
817
818



819
820
821
822
823
824
825
737
738
739
740
741
742
743



744
745
746
747
748
749
750
751
752
753
754
755

756


757
758
759
760
761




762
763
764
765


766
767
768
769
770




771
772
773
774
775
776
777
778
779
780







-
-
-
+
+
+









-
+
-
-
+




-
-
-
-
+
+
+

-
-
+




-
-
-
-
+
+
+








        set leftfull [$tree rowattrib $node leftfull]
        set rightfull [$tree rowattrib $node rightfull]
        $self CompareDirs $leftfull $rightfull $node
    }

    method UpdateFileNode {node} {
        set leftdict [$tree rowattrib $node leftdict]
        set rightdict [$tree rowattrib $node rightdict]
        set equal [CompareFiles $leftdict $rightdict]
        set leftfull [$tree rowattrib $node leftfull]
        set rightfull [$tree rowattrib $node rightfull]
        set equal [CompareFiles $leftfull $rightfull]
        if {$equal} {
            $self SetNodeStatus $node equal
        } else {
            $self SetNodeStatus $node change
        }
    }

    # List files under a directory node
    # Returns status for the new node
    method ListFiles {fD1 fD2 node} {
    method ListFiles {df1 df2 node} {
        if {[dict size $fD1] == 0} {
            set df1 ""
        if {[catch {file stat $df1 stat1}]} {
            set size1 ""
            set time1 ""
            set type1 ""
        } else {
            set df1   [dict get $fD1 full]
            set size1 [dict get $fD1 size]
            set time1 [FormatDate [dict get $fD1 mtime]]
            set type1 [dict get $fD1 type]
            set size1 $stat1(size)
            set time1 [FormatDate $stat1(mtime)]
            set type1 $stat1(type)
        }
        if {[dict size $fD2] == 0} {
            set df2 ""
        if {[catch {file stat $df2 stat2}]} {
            set size2 ""
            set time2 ""
            set type2 ""
        } else {
            set df2   [dict get $fD2 full]
            set size2 [dict get $fD2 size]
            set time2 [FormatDate [dict get $fD2 mtime]]
            set type2 [dict get $fD2 type]
            set size2 $stat2(size)
            set time2 [FormatDate $stat2(mtime)]
            set type2 $stat2(type)
        }
        if {$df1 ne ""} {
            set type $type1
            set name [file tail $df1]
        } else {
            set type $type2
            set name [file tail $df2]
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
790
791
792
793
794
795
796

797

798
799
800
801
802
803
804







-

-







                    "" \
                    $size2 $time2]
        }
        set id [$tree insertchild $node end $values]
        $tree rowattrib $id type $type
        $tree rowattrib $id status unknown
        $tree rowattrib $id leftfull $df1
        $tree rowattrib $id leftdict $fD1
        $tree rowattrib $id rightfull $df2
        $tree rowattrib $id rightdict $fD2
        if {$type ne "directory"} {
            if {$type eq "link"} {
                $tree cellconfigure $id,structure -image $::img(link)
            } else {
                $tree cellconfigure $id,structure -image $::img(file)
                $tree cellconfigure $id,command -window [mymethod addCmdCol]
            }
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909

910
911

912
913
914

915
916

917
918
919
920


921
922
923
924
925
926
927
928
929
930





931
932
933
934


935
936
937
938
939

940
941
942
943
944
945
946
947

948
949
950
951
952

953
954
955
956
957
958
959


960
961
962
963
964


965
966
967
968
969
970
971
847
848
849
850
851
852
853







854

855
856

857
858
859

860
861

862
863
864


865
866
867
868
869
870
871
872
873



874
875
876
877
878
879
880


881
882
883
884
885
886

887
888
889
890
891
892
893
894

895
896
897
898
899

900
901
902
903
904
905


906
907
908
909
910


911
912
913
914
915
916
917
918
919







-
-
-
-
-
-
-

-
+

-
+


-
+

-
+


-
-
+
+







-
-
-
+
+
+
+
+


-
-
+
+




-
+







-
+




-
+





-
-
+
+



-
-
+
+







        if {$rf eq ""} {
            $w.bl configure -state disabled
        }
    }

    # Compare two directories.
    method CompareDirs {dir1 dir2 node} {
        # Collect preferences to a dict.
        # FIXA: Maybe move this to a more central place
        dict set prefsD incdirs $::Pref(dir,incdirs)
        dict set prefsD exdirs $::Pref(dir,exdirs)
        dict set prefsD incfiles $::Pref(dir,incfiles)
        dict set prefsD exfiles $::Pref(dir,exfiles)

        if {$dir1 eq ""} {
            set filesD1 {}
            set files1 {}
        } else {
            set filesD1 [DirContentsD $dir1 $prefsD]
            set files1 [DirContents $dir1]
        }
        if {$dir2 eq ""} {
            set filesD2 {}
            set files2 {}
        } else {
            set filesD2 [DirContentsD $dir2 $prefsD]
            set files2 [DirContents $dir2]
        }

        set len1 [llength $filesD1]
        set len2 [llength $filesD2]
        set len1 [llength $files1]
        set len2 [llength $files2]

        set p1 0
        set p2 0
        set status_change 0
        set status_unknown 0
        while 1 {
            if {$p1 < $len1 && $p2 < $len2} {
                set fD1 [lindex $filesD1 $p1]
                set fD2 [lindex $filesD2 $p2]
                set apa [FStrCmp [dict get $fD1 tail] [dict get $fD2 tail]]
                set df1 [lindex $files1 $p1]
                set f1 [file tail $df1]
                set df2 [lindex $files2 $p2]
                set f2 [file tail $df2]
                set apa [FStrCmp $f1 $f2]
                if {$apa == 0} {
                    # Equal names, separate them if not the same type
                    set apa [expr {- [dict get $fD1 dir] \
                                   + [dict get $fD2 dir]}]
                    set apa [expr {- [FileIsDirectory $df1] \
                                   + [FileIsDirectory $df2]}]
                }

                switch -- $apa {
                    0 {
                        set sts [$self ListFiles $fD1 $fD2 $node]
                        set sts [$self ListFiles $df1 $df2 $node]
                        incr p1
                        incr p2
                        if {$sts eq "unknown"} {
                            set status_unknown 1
                        }
                    }
                    -1 {
                        $self ListFiles $fD1 "" $node
                        $self ListFiles $df1 "" $node
                        incr p1
                        set status_change 1
                    }
                    1 {
                        $self ListFiles "" $fD2 $node
                        $self ListFiles "" $df2 $node
                        incr p2
                        set status_change 1
                    }
                }
            } elseif {$p1 < $len1 && $p2 >= $len2} {
                set fD1 [lindex $filesD1 $p1]
                $self ListFiles $fD1 "" $node
                set df1 [lindex $files1 $p1]
                $self ListFiles $df1 "" $node
                incr p1
                set status_change 1
            } elseif {$p1 >= $len1 && $p2 < $len2} {
                set fD2 [lindex $filesD2 $p2]
                $self ListFiles "" $fD2 $node
                set df2 [lindex $files2 $p2]
                $self ListFiles "" $df2 $node
                incr p2
                set status_change 1
            } else {
                break
            }
        }
        if {$dir1 eq ""} {
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1177
1178
1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190







-







    ttk::entryX $filter.e1 -width 20 -textvariable ::TmpPref(dir,incfiles)
    ttk::label $filter.l2 -text "Exclude Files" -anchor w
    ttk::entryX $filter.e2 -width 20 -textvariable ::TmpPref(dir,exfiles)
    ttk::label $filter.l3 -text "Include Dirs" -anchor w
    ttk::entryX $filter.e3 -width 20 -textvariable ::TmpPref(dir,incdirs)
    ttk::label $filter.l4 -text "Exclude Dirs" -anchor w
    ttk::entryX $filter.e4 -width 20 -textvariable ::TmpPref(dir,exdirs)
    # FIXA: onlyrev currently does nothing
    ttk::checkbutton $filter.cb1 -text "Only revision controlled" \
            -variable ::TmpPref(dir,onlyrev)
    grid $filter.l1 $filter.e1 -sticky we -padx 3 -pady 3
    grid $filter.l2 $filter.e2 -sticky we -padx 3 -pady 3
    grid $filter.l3 $filter.e3 -sticky we -padx 3 -pady 3
    grid $filter.l4 $filter.e4 -sticky we -padx 3 -pady 3
    grid $filter.cb1 - -sticky w -padx 3 -pady 3