Eskil

Diff
Login

Differences From Artifact [83859129c4]:

To Artifact [b3e19d970b]:


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
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







-
-
+
+








-
-
-
+
+
+





-
+
+



-
-
+
+







        # Four files, with optional revision
        set fields {base1 change1 base2 change2}
    
        ttk::label $win.l1 -text "Base 1"
        ttk::label $win.l2 -text "Changed 1"
        ttk::label $win.l3 -text "Base 2"
        ttk::label $win.l4 -text "Changed 2"
        set txt1 "First diff is made from Base 1 to Changed 1.\n If a file is empty\
                  and have a revision, the other file name is used."
        set txt1 "First diff is made from Base 1 to Changed 1.\n If a file is\
                  empty and have a revision, the other file name is used."
        addBalloon $win.l1 $txt1
        addBalloon $win.l2 $txt1
        set txt2 [string map {1 2 First Second} $txt1]
        addBalloon $win.l3 $txt2
        addBalloon $win.l4 $txt2

        ttk::label $win.el -text "File path"
        ttk::label $win.rl -text "Rev"
        addBalloon $win.rl "If you want to use a revisioned controlled file instead\n of\
                            the one on disk, add a revision here. E.g. 0 can be used\n for\
                            latest commited revision."
        addBalloon $win.rl "If you want to use a revisioned controlled file\
                            instead\n of the one on disk, add a revision here.\
                            E.g. 0 can be used\n for latest commited revision."

        set n 0
        foreach field $fields {
            incr n
            ttk::entryX $win.e$n -width 60 -textvariable [myvar files($field)]
            ttk::button $win.b$n -text "Browse" -command [mymethod browseFile $field]
            ttk::button $win.b$n -text "Browse" \
                    -command [mymethod browseFile $field]
            ttk::entryX $win.r$n -width 6 -textvariable  [myvar revs($field)]
        }

        ttk::button $win.bd -text "Diff" -command [mymethod doFourWayDiff] -underline 0 \
                -width 8
        ttk::button $win.bd -text "Diff" -command [mymethod doFourWayDiff] \
                -underline 0 -width 8
        bind $win <Alt-d> [list $win.bd invoke]

        grid x       $win.el x       $win.rl -sticky w  -padx 3 -pady 3
        grid $win.l1 $win.e1 $win.b1 $win.r1 -sticky we -padx 3 -pady 3
        grid $win.l2 $win.e2 $win.b2 $win.r2 -sticky we -padx 3 -pady 3
        grid $win.l3 $win.e3 $win.b3 $win.r3 -sticky we -padx 3 -pady {10 3}
        grid $win.l4 $win.e4 $win.b4 $win.r4 -sticky we -padx 3 -pady 3
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+







            set todo [list $field]
        }
        foreach fn $files field $todo {
            # Loop until any list ends
            if {$fn eq "" || $field eq ""} break
            # Sanity check
            if {[file exists $fn]} {
                set fields($field) $fn
                set files($field) $fn
            }
        }
    }

    # Browse for file
    method browseFile {field} {
        set initDir [pwd]
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
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







-
+

-
+

-
+


-
+














+
+
+
+
-
+







+
+
+
+
-
+







        }
    }

    method doFourWayDiff {} {
        # Copy to local vars to be able to replace with defaults and parsed
        foreach field $fields {
            set filename($field) $files($field)
            set rev($field) $revs($field)
            set rev($field) [string trim $revs($field)]
        }
        # Fill in defaults, if revisions are given for empty files
        # Fill in defaults, if only one file is given
        foreach {from to} $fields {
            if {$filename($to) eq "" && $revs($to) ne ""} {
            if {$filename($to) eq ""} {
                set filename($to) $files($from)
            }
            if {$filename($from) eq "" && $revs($from) ne ""} {
            if {$filename($from) eq ""} {
                set filename($from) $files($to)
            }
        }
        # Remember originals for display, they might be replaced below
        foreach field $fields {
            set origfile($field) $filename($field)
            set origrev($field)  $rev($field)
        }
        # Figure out any revisions
        foreach field $fields {
            # TODO: Move this to helper function in rev.tcl
            if {$rev($field) ne ""} {
                set revtype($field) [detectRevSystem $filename($field)]
                if {$revtype($field) eq ""} {
                    tk_messageBox -icon error -title "Eskil Error" \
                            -parent $win -message \
                            "Could not detect version system for file $filename($field)"
                    return
                    # TODO error
                    # TBD continue
                    set rev($field) ""
                    continue
                }
                set revList [list $rev($field)]
                set revList [eskil::rev::$revtype($field)::ParseRevs \
                                     $filename($field) $revList]
                if {[llength $revList] == 0} {
                    tk_messageBox -icon error -title "Eskil Error" \
                            -parent $win -message \
                            "Could not parse revision for file $filename($field)"
                    return
                    # TODO error
                    # TBD continue
                    set rev($field) ""
                } else {
                    set rev($field) [lindex $revList 0]
                }
            }
            # Still a revision?
            if {$rev($field) ne ""} {
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231







-
+







        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 \
                                        $filename(base$side) $filename(change$side)} diffres]
                    $filename(base$side) $filename(change$side)} diffres]
            if {$differr != 0} {
                # TODO error
                return
            }
            set outfile($side) [tmpFile]
            set ch [open $outfile($side) w]
            foreach str {From To} field "base$side change$side" {
289
290
291
292
293
294
295
296

297
298
299
300
301

302
303
304
305
306
307
308
309
310
311
312
313
298
299
300
301
302
303
304

305
306
307
308
309

310
311
312
313
314
315
316
317
318
319
320
321
322







-
+




-
+












        }
 
        # Output diff
        for {set t 0} {$t < $n1} {incr t} {
            gets $ch1 apa
            puts $ch "- $apa"
            incr doingLine1
         }
        }
        for {set t 0} {$t < $n2} {incr t} {
            gets $ch2 apa
            puts $ch "+ $apa"
            incr doingLine2
         }
        }
    }
}

proc makeFourWayWin {} {
    set t 1
    set top .fourway$t
    while {[winfo exists $top]} {
        incr t
        set top .fourway$t
    }
    FourWay $top
}