Fossil SCM

fossil-scm / tools / cvs2fossil / lib / c2f_fossil.tcl
Blame History Raw 274 lines
1
## -*- tcl -*-
2
# # ## ### ##### ######## ############# #####################
3
## Copyright (c) 2007-2008 Andreas Kupries.
4
#
5
# This software is licensed as described in the file LICENSE, which
6
# you should have received as part of this distribution.
7
#
8
# This software consists of voluntary contributions made by many
9
# individuals. For exact contribution history, see the revision
10
# history and logs, available at http://fossil-scm.hwaci.com/fossil
11
# # ## ### ##### ######## ############# #####################
12
13
## Fossil, a helper class managing the access to fossil repositories.
14
15
# # ## ### ##### ######## ############# #####################
16
## Requirements
17
18
package require Tcl 8.4 ; # Required runtime.
19
package require fileutil ; # Temp.dir/file
20
package require snit ; # OO system.
21
package require vc::tools::trouble ; # Error reporting.
22
package require vc::tools::log ; # User feedback
23
package require vc::fossil::import::cvs::integrity ; # State integrity checks.
24
25
# # ## ### ##### ######## ############# #####################
26
##
27
28
snit::type ::vc::fossil::import::cvs::fossil {
29
# # ## ### ##### ######## #############
30
## Public API
31
32
constructor {} {
33
return
34
}
35
36
method initialize {} {
37
set myrepository [fileutil::tempfile cvs2fossil_repo_]
38
set myworkspace [fileutil::tempfile cvs2fossil_wspc_]
39
::file delete $myworkspace
40
::file mkdir $myworkspace
41
42
Do new [::file nativename $myrepository]
43
$self InWorkspace ; Do open [::file nativename $myrepository]
44
$self RestorePwd
45
46
log write 8 fossil {Scratch repository created @ $myrepository}
47
log write 8 fossil {Scratch workspace created @ $myworkspace }
48
return
49
}
50
51
method load {r w} {
52
set myrepository $r
53
set myworkspace $w
54
55
log write 8 fossil {Scratch repository found @ $myrepository}
56
log write 8 fossil {Scratch workspace found @ $myworkspace}
57
return
58
}
59
60
method space {} {
61
return [list $myrepository $myworkspace]
62
}
63
64
# # ## ### ##### ######## #############
65
##
66
67
method root {} {
68
# The id of the root manifest is hardwired into fossil. This
69
# manifest is created when a new repository is made (See
70
# 'new', in the constructor).
71
return 1
72
}
73
74
method workspace {} { return $myworkspace }
75
76
method importfiles {map} {
77
# map = list (instruction), instruction = add|delta
78
# add = list ('A', path)
79
# delta = list ('D', path, src)
80
81
log write 3 fossil {Importing revisions...}
82
83
array set id {}
84
$self InWorkspace
85
86
set n 0
87
set max [llength $map]
88
89
foreach insn $map {
90
log progress 3 fossil $n $max ; incr n
91
92
struct::list assign $insn cmd pa pb
93
switch -exact -- $cmd {
94
A {
95
log write 8 fossil {Importing <$pa>,}
96
97
# Result = 'inserted as record :FOO:'
98
# 0 1 2 3
99
set res [Do test-content-put $pa]
100
integrity assert {
101
[regexp {^inserted as record \d+$} $res]
102
} {Unable to process unexpected fossil output '$res'}
103
set id($pa) [lindex $res 3]
104
}
105
D {
106
log write 8 fossil {Compressing <$pa>, as delta of <$pb>}
107
108
Do test-content-deltify $id($pa) $id($pb) 1
109
}
110
}
111
}
112
$self RestorePwd
113
114
log write 3 fossil Done.
115
return [array get id]
116
}
117
118
method importrevision {label user message date parent revisions} {
119
# Massage the commit message to remember the old user name
120
# which did the commit in CVS.
121
122
set message "By $user:\n$message"
123
124
log write 2 fossil {== $user @ [clock format $date]}
125
log write 2 fossil {-> $parent}
126
log write 9 fossil {%% [join [split $message \n] "\n%% "]}
127
128
lappend cmd Do test-import-manifest $date $message
129
if {$parent ne ""} { lappend cmd -p $parent }
130
foreach {frid fpath flabel} $revisions {
131
lappend cmd -f $frid $fpath
132
log write 12 fossil {** <[format %5d $frid]> = <$flabel>}
133
}
134
135
# run fossil test-command performing the import.
136
log write 12 fossil { [lreplace $cmd 3 3 @@]}
137
138
$self InWorkspace
139
set res [eval $cmd]
140
$self RestorePwd
141
142
integrity assert {
143
[regexp {^inserted as record \d+, [0-9a-fA-F]+$} $res]
144
} {Unable to process unexpected fossil output '$res'}
145
set rid [string trim [lindex $res 3] ,]
146
set uuid [lindex $res 4]
147
148
log write 2 fossil {== $rid ($uuid)}
149
150
return [list $rid $uuid]
151
}
152
153
method tag {uuid name} {
154
log write 2 fossil {Tag '$name' @ $uuid}
155
156
$self InWorkspace
157
Do tag add sym-$name $uuid
158
$self RestorePwd
159
return
160
}
161
162
method branchmark {uuid name} {
163
# We do not mark the trunk
164
if {$name eq ":trunk:"} return
165
166
log write 2 fossil {Begin branch '$name' @ $uuid}
167
168
$self InWorkspace
169
Do tag branch sym-$name $uuid
170
$self RestorePwd
171
return
172
}
173
174
method branchcancel {uuid name} {
175
# The trunk is unmarked, thus cancellation is not needed
176
# either.
177
if {$name eq ":trunk:"} return
178
179
log write 2 fossil {Cancel branch '$name' @ $uuid}
180
181
$self InWorkspace
182
Do tag delete sym-$name $uuid
183
$self RestorePwd
184
return
185
}
186
187
method finalize {destination} {
188
log write 2 fossil {Finalize, rebuilding repository}
189
Do rebuild [::file nativename $myrepository]
190
191
::file rename -force $myrepository $destination
192
::file delete -force $myworkspace
193
$self destroy
194
195
log write 2 fossil {destination $destination}
196
return
197
}
198
199
# # ## ### ##### ######## #############
200
##
201
202
typemethod setlocation {path} {
203
set myfossilcmd $path
204
set myneedlocation 0
205
return
206
}
207
208
typemethod validate {} {
209
if {!$myneedlocation} {
210
if {![fileutil::test $myfossilcmd efrx msg]} {
211
trouble fatal "Bad path for fossil executable: $msg"
212
}
213
} else {
214
trouble fatal "Don't know where to find the 'fossil' executable"
215
}
216
return
217
}
218
219
typeconstructor {
220
set location [auto_execok fossil]
221
set myneedlocation [expr {$location eq ""}]
222
if {$myneedlocation} return
223
$type setlocation $location
224
return
225
}
226
227
# # ## ### ##### ######## #############
228
## State
229
230
variable mypwd {} ; # Path to last CWD
231
variable myrepository {} ; # Path to our fossil database.
232
variable myworkspace {} ; # Path to the workspace for our fossil
233
# database.
234
235
typevariable myfossilcmd ; # Path to fossil executable.
236
typevariable myneedlocation ; # Boolean, indicates if user has to
237
# tell us where fossil lives or not.
238
239
# # ## ### ##### ######## #############
240
## Internal methods
241
242
proc Do {args} {
243
# 8.5: exec $myfossilcmd {*}$args
244
log write 14 fossil {Doing '$args'}
245
return [eval [linsert $args 0 exec $myfossilcmd]]
246
}
247
248
method InWorkspace {} { set mypwd [pwd] ; cd $myworkspace ; return }
249
method RestorePwd {} { cd $mypwd ; set mypwd {} ; return }
250
251
# # ## ### ##### ######## #############
252
## Configuration
253
254
pragma -hastypeinfo no ; # no type introspection
255
pragma -hasinfo no ; # no object introspection
256
257
# # ## ### ##### ######## #############
258
}
259
260
namespace eval ::vc::fossil::import::cvs {
261
namespace export fossil
262
namespace eval fossil {
263
namespace import ::vc::tools::trouble
264
namespace import ::vc::tools::log
265
namespace import ::vc::fossil::import::cvs::integrity
266
}
267
}
268
269
# # ## ### ##### ######## ############# #####################
270
## Ready
271
272
package provide vc::fossil::import::cvs::fossil 1.0
273
return
274

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button