Eskil

Check-in [4888bbb2c2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Reordered procs
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4888bbb2c2c55d9f021ded8635abdc3051d97aac
User & Date: peter 2007-09-17 22:29:03.000
Context
2007-09-22
16:47
Adapted to new source organization check-in: fdb04ad7a2 user: peter tags: trunk
2007-09-17
22:29
Reordered procs check-in: 4888bbb2c2 user: peter tags: trunk
22:21
Moved revision system specific commands into namespaces check-in: e62a20dbd5 user: peter tags: trunk
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to src/rev.tcl.
18
19
20
21
22
23
24




25
26
27
28
29
30
31
32
33
34

35
36
37

38
39
40
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
106
107
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40

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







+
+
+
+









-
+


-
+






-
+


-
+









-
+



-
+









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







#  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.
#
#----------------------------------------------------------------------
# $Revision$
#----------------------------------------------------------------------

##############################################################################
# Revision Control System specific procedures
##############################################################################

namespace eval eskil::rev::CVS {}
namespace eval eskil::rev::RCS {}
namespace eval eskil::rev::CT {}
namespace eval eskil::rev::GIT {}

proc eskil::rev::CVS::detect {file} {
    set dir [file dirname $file]
    if {[file isdirectory [file join $dir CVS]]} {
        if {[auto_execok cvs] ne ""} {
            return "CVS"
            return 1
        }
    }
    return
    return 0
}

proc eskil::rev::RCS::detect {file} {
    set dir [file dirname $file]
    if {[file isdirectory [file join $dir RCS]] || [file exists $file,v]} {
        if {[auto_execok rcs] ne ""} {
            return "RCS"
            return 1
        }
    }
    return
    return 0
}

proc eskil::rev::CT::detect {file} {
    set dir [file dirname $file]
    if {[auto_execok cleartool] != ""} {
        set old [pwd]
        cd $dir
        if {![catch {exec cleartool pwv -s} view] && $view != "** NONE **"} {
            cd $old
            return "CT"
            return 1
        }
        cd $old
    }
    return
    return 0
}

proc eskil::rev::GIT::detect {file} {
    set dir [file dirname $file]
    # Git, detect two steps down. Could be improved. FIXA
    if {[file isdirectory [file join $dir .git]] ||
        [file isdirectory [file join $dir .. .git]] ||
        [file isdirectory [file join $dir .. .. .git]]} {
        if {[auto_execok git] ne ""} {
            return "GIT"
        }
    }
    return
}

            return 1
        }
    }
# Figure out what revision control system a file is under
# Returns "CVS", "RCS", "CT", "GIT" if detected, or "" if none.
proc detectRevSystem {file} {
    # The search order is manually set to ensure GIT priority over CVS.
    foreach rev {GIT CVS RCS CT} {
        set result [eskil::rev::${rev}::detect $file]
        if {$result ne ""} {return $result}
    }
    return
    return 0
}

# Initialise revision control mode
# The file name should be an absolute normalized path.
proc startRevMode {top rev file} {
    set ::diff($top,mode) "rev"
    set ::diff($top,modetype) $rev
    set ::diff($top,rightDir) [file dirname $file]
    set ::diff($top,RevFile) $file
    set ::diff($top,rightLabel) $file
    set ::diff($top,rightFile) $file
    set ::diff($top,rightOK) 1
    set ::diff($top,leftLabel) $rev
    set ::diff($top,leftOK) 0
    set ::Pref(toolbar) 1
}

# Get a CVS revision
proc eskil::rev::CVS::get {filename outfile {rev {}}} {
    set old ""
    set dir [file dirname $filename]
    if {$dir != "."} {
135
136
137
138
139
140
141









142
143
144
145
146
147
148
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135







+
+
+
+
+
+
+
+
+








# Get a GIT revision
# No support for revisions yet
proc eskil::rev::GIT::get {filename outfile {rev {}}} {
    # Dummy copy for now FIXA
    file copy $filename $outfile
}

# Get a ClearCase revision
proc eskil::rev::CT::get {filename outfile rev} {
    set filerev [file nativename $filename@@$rev]
    if {[catch {exec cleartool get -to $outfile $filerev} msg]} {
        tk_messageBox -icon error -title "Cleartool error" -message $msg
        return
    }
}

# Return current revision of a CVS file
proc eskil::rev::CVS::GetCurrent {filename} {
    set old ""
    set dir [file dirname $filename]
    if {$dir != "."} {
        set old [pwd]
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
163
164
165
166
167
168
169









170
171
172
173
174
175
176







-
-
-
-
-
-
-
-
-







        if {$tail < 1} {set tail 1}
        set rev $head$tail
    }
    
    return $rev
}

# Get a ClearCase revision
proc eskil::rev::CT::get {filename outfile rev} {
    set filerev [file nativename $filename@@$rev]
    if {[catch {exec cleartool get -to $outfile $filerev} msg]} {
        tk_messageBox -icon error -title "Cleartool error" -message $msg
        return
    }
}

# Figure out ClearCase revision from arguments
proc eskil::rev::CT::ParseRevs {filename stream rev} {
    # A negative version number is offset from latest.
    set offset 0
    set tail [file tail $rev]
    if {[string is integer -strict $tail] && $tail < 0} {
        set offset $tail
236
237
238
239
240
241
242







243
244
245
246
247
248














249
250
251















252
253
254
255
256
257
258
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







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







        if {$tail < 0} {set tail 0}
        set rev [file join $path $tail]
    }
        
    return $rev
}

# Check in CVS controlled file
proc eskil::rev::CVS::commitFile {top filename} {
    set logmsg [LogDialog $top $filename]
    if {$logmsg ne ""} {
        catch {exec cvs -q commit -m $logmsg $filename}
    }
}
# Get the last two elements in a file path
proc GetLastTwoPath {path} {
    set last [file tail $path]
    set penultimate [file tail [file dirname $path]]
    if {$penultimate eq "."} {
        return $last

##############################################################################
# Exported procedures
##############################################################################

# Figure out what revision control system a file is under
# Returns "CVS", "RCS", "CT", "GIT" if detected, or "" if none.
proc detectRevSystem {file} {
    # The search order is manually set to ensure GIT priority over CVS.
    foreach rev {GIT CVS RCS CT} {
        set result [eskil::rev::${rev}::detect $file]
        if {$result} {return $rev}
    }
    return
    } else {
        return [file join $penultimate $last]
    }
}

# Initialise revision control mode
# The file name should be an absolute normalized path.
proc startRevMode {top rev file} {
    set ::diff($top,mode) "rev"
    set ::diff($top,modetype) $rev
    set ::diff($top,rightDir) [file dirname $file]
    set ::diff($top,RevFile) $file
    set ::diff($top,rightLabel) $file
    set ::diff($top,rightFile) $file
    set ::diff($top,rightOK) 1
    set ::diff($top,leftLabel) $rev
    set ::diff($top,leftOK) 0
    set ::Pref(toolbar) 1
}

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

    $::widgets($top,commit) configure -state disabled
356
357
358
359
360
361
362



363
364
365
366
367









368
369
370
371
372
373
374
361
362
363
364
365
366
367
368
369
370





371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386







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







}

proc revCommit {top} {
    if {[$::widgets($top,commit) cget -state] eq "disabled"} return
    eskil::rev::CVS::commitFile $top $::diff($top,RevFile)
}

##############################################################################
# Utilities
##############################################################################
# Check in CVS controlled file
proc eskil::rev::CVS::commitFile {top filename} {
    set logmsg [LogDialog $top $filename]
    if {$logmsg ne ""} {
        catch {exec cvs -q commit -m $logmsg $filename}

# Get the last two elements in a file path
proc GetLastTwoPath {path} {
    set last [file tail $path]
    set penultimate [file tail [file dirname $path]]
    if {$penultimate eq "."} {
        return $last
    } else {
        return [file join $penultimate $last]
    }
}

# Dialog for log message
proc LogDialog {top filename {clean 0}} {
    set w $top.logmsg
    destroy  $w