Fossil SCM

Continued work on pass 3, added code to determine the type of symbols based on the tag-, branch-, and commit-counts. Hook for handling data coming from the option processoris present (UserConfig), but only as a placeholder.

aku 2007-11-02 06:06 trunk
Commit f888f06fe35bc379d20ea71303e88d205a5106e9
--- tools/cvs2fossil/lib/c2f_pcollrev.tcl
+++ tools/cvs2fossil/lib/c2f_pcollrev.tcl
@@ -14,18 +14,19 @@
1414
## all the information they contain (revisions, and symbols).
1515
1616
# # ## ### ##### ######## ############# #####################
1717
## Requirements
1818
19
-package require Tcl 8.4 ; # Required runtime.
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::pass ; # Pass management.
24
-package require vc::fossil::import::cvs::repository ; # Repository management.
25
-package require vc::fossil::import::cvs::state ; # State storage.
26
-package require vc::rcs::parser ; # Rcs archive data extraction.
19
+package require Tcl 8.4 ; # Required runtime.
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::pass ; # Pass management.
24
+package require vc::fossil::import::cvs::repository ; # Repository management.
25
+package require vc::fossil::import::cvs::state ; # State storage.
26
+package require vc::fossil::import::cvs::project::sym ; # Project level symbols
27
+package require vc::rcs::parser ; # Rcs archive data extraction.
2728
2829
# # ## ### ##### ######## ############# #####################
2930
## Register the pass with the management
3031
3132
vc::fossil::import::cvs::pass define \
@@ -203,13 +204,15 @@
203204
n INTEGER NOT NULL, -- How often pid can act as parent.
204205
UNIQUE (sid, pid)
205206
}
206207
207208
state writing symtype {
208
- tid INTEGER NOT NULL PRIMARY KEY,
209
- name TEXT NOT NULL,
209
+ tid INTEGER NOT NULL PRIMARY KEY,
210
+ name TEXT NOT NULL,
211
+ plural TEXT NOT NULL,
210212
UNIQUE (name)
213
+ UNIQUE (plural)
211214
}
212215
state run {
213216
INSERT INTO symtype VALUES (0,'excluded');
214217
INSERT INTO symtype VALUES (1,'tag');
215218
INSERT INTO symtype VALUES (2,'branch');
@@ -255,17 +258,20 @@
255258
state writing cmessage {
256259
cid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
257260
text TEXT NOT NULL UNIQUE
258261
}
259262
263
+ project::sym getsymtypes
260264
return
261265
}
262266
263267
typemethod load {} {
264268
state reading symbol
269
+ state reading symtype
265270
266
- repository loadsymbols
271
+ project::sym getsymtypes
272
+ repository loadsymbols
267273
return
268274
}
269275
270276
typemethod run {} {
271277
# Pass manager interface. Executed to perform the
@@ -589,10 +595,13 @@
589595
namespace export collrev
590596
namespace eval collrev {
591597
namespace import ::vc::rcs::parser
592598
namespace import ::vc::fossil::import::cvs::repository
593599
namespace import ::vc::fossil::import::cvs::state
600
+ namespace eval project {
601
+ namespace import ::vc::fossil::import::cvs::project::sym
602
+ }
594603
namespace import ::vc::tools::trouble
595604
namespace import ::vc::tools::log
596605
log register collrev
597606
}
598607
}
599608
--- tools/cvs2fossil/lib/c2f_pcollrev.tcl
+++ tools/cvs2fossil/lib/c2f_pcollrev.tcl
@@ -14,18 +14,19 @@
14 ## all the information they contain (revisions, and symbols).
15
16 # # ## ### ##### ######## ############# #####################
17 ## Requirements
18
19 package require Tcl 8.4 ; # Required runtime.
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::pass ; # Pass management.
24 package require vc::fossil::import::cvs::repository ; # Repository management.
25 package require vc::fossil::import::cvs::state ; # State storage.
26 package require vc::rcs::parser ; # Rcs archive data extraction.
 
27
28 # # ## ### ##### ######## ############# #####################
29 ## Register the pass with the management
30
31 vc::fossil::import::cvs::pass define \
@@ -203,13 +204,15 @@
203 n INTEGER NOT NULL, -- How often pid can act as parent.
204 UNIQUE (sid, pid)
205 }
206
207 state writing symtype {
208 tid INTEGER NOT NULL PRIMARY KEY,
209 name TEXT NOT NULL,
 
210 UNIQUE (name)
 
211 }
212 state run {
213 INSERT INTO symtype VALUES (0,'excluded');
214 INSERT INTO symtype VALUES (1,'tag');
215 INSERT INTO symtype VALUES (2,'branch');
@@ -255,17 +258,20 @@
255 state writing cmessage {
256 cid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
257 text TEXT NOT NULL UNIQUE
258 }
259
 
260 return
261 }
262
263 typemethod load {} {
264 state reading symbol
 
265
266 repository loadsymbols
 
267 return
268 }
269
270 typemethod run {} {
271 # Pass manager interface. Executed to perform the
@@ -589,10 +595,13 @@
589 namespace export collrev
590 namespace eval collrev {
591 namespace import ::vc::rcs::parser
592 namespace import ::vc::fossil::import::cvs::repository
593 namespace import ::vc::fossil::import::cvs::state
 
 
 
594 namespace import ::vc::tools::trouble
595 namespace import ::vc::tools::log
596 log register collrev
597 }
598 }
599
--- tools/cvs2fossil/lib/c2f_pcollrev.tcl
+++ tools/cvs2fossil/lib/c2f_pcollrev.tcl
@@ -14,18 +14,19 @@
14 ## all the information they contain (revisions, and symbols).
15
16 # # ## ### ##### ######## ############# #####################
17 ## Requirements
18
19 package require Tcl 8.4 ; # Required runtime.
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::pass ; # Pass management.
24 package require vc::fossil::import::cvs::repository ; # Repository management.
25 package require vc::fossil::import::cvs::state ; # State storage.
26 package require vc::fossil::import::cvs::project::sym ; # Project level symbols
27 package require vc::rcs::parser ; # Rcs archive data extraction.
28
29 # # ## ### ##### ######## ############# #####################
30 ## Register the pass with the management
31
32 vc::fossil::import::cvs::pass define \
@@ -203,13 +204,15 @@
204 n INTEGER NOT NULL, -- How often pid can act as parent.
205 UNIQUE (sid, pid)
206 }
207
208 state writing symtype {
209 tid INTEGER NOT NULL PRIMARY KEY,
210 name TEXT NOT NULL,
211 plural TEXT NOT NULL,
212 UNIQUE (name)
213 UNIQUE (plural)
214 }
215 state run {
216 INSERT INTO symtype VALUES (0,'excluded');
217 INSERT INTO symtype VALUES (1,'tag');
218 INSERT INTO symtype VALUES (2,'branch');
@@ -255,17 +258,20 @@
258 state writing cmessage {
259 cid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
260 text TEXT NOT NULL UNIQUE
261 }
262
263 project::sym getsymtypes
264 return
265 }
266
267 typemethod load {} {
268 state reading symbol
269 state reading symtype
270
271 project::sym getsymtypes
272 repository loadsymbols
273 return
274 }
275
276 typemethod run {} {
277 # Pass manager interface. Executed to perform the
@@ -589,10 +595,13 @@
595 namespace export collrev
596 namespace eval collrev {
597 namespace import ::vc::rcs::parser
598 namespace import ::vc::fossil::import::cvs::repository
599 namespace import ::vc::fossil::import::cvs::state
600 namespace eval project {
601 namespace import ::vc::fossil::import::cvs::project::sym
602 }
603 namespace import ::vc::tools::trouble
604 namespace import ::vc::tools::log
605 log register collrev
606 }
607 }
608
--- tools/cvs2fossil/lib/c2f_pcollsym.tcl
+++ tools/cvs2fossil/lib/c2f_pcollsym.tcl
@@ -16,19 +16,20 @@
1616
## 'FilterSym', which performs the actual deletion.
1717
1818
# # ## ### ##### ######## ############# #####################
1919
## Requirements
2020
21
-package require Tcl 8.4 ; # Required runtime.
22
-package require snit ; # OO system.
23
-#package require fileutil::traverse ; # Directory traversal.
24
-#package require fileutil ; # File & path utilities.
25
-#package require vc::tools::trouble ; # Error reporting.
26
-package require vc::tools::log ; # User feedback.
27
-#package require vc::fossil::import::cvs::pass ; # Pass management.
28
-#package require vc::fossil::import::cvs::repository ; # Repository management.
29
-package require vc::fossil::import::cvs::state ; # State storage.
21
+package require Tcl 8.4 ; # Required runtime.
22
+package require snit ; # OO system.
23
+#package require fileutil::traverse ; # Directory traversal.
24
+#package require fileutil ; # File & path utilities.
25
+#package require vc::tools::trouble ; # Error reporting.
26
+package require vc::tools::log ; # User feedback.
27
+#package require vc::fossil::import::cvs::pass ; # Pass management.
28
+package require vc::fossil::import::cvs::repository ; # Repository management.
29
+package require vc::fossil::import::cvs::state ; # State storage.
30
+package require vc::fossil::import::cvs::project::sym ; # Project level symbols
3031
3132
# # ## ### ##### ######## ############# #####################
3233
## Register the pass with the management
3334
3435
vc::fossil::import::cvs::pass define \
@@ -60,10 +61,17 @@
6061
}
6162
6263
typemethod run {} {
6364
# Pass manager interface. Executed to perform the
6465
# functionality of the pass.
66
+
67
+ state transaction {
68
+ repository determinesymboltypes
69
+
70
+ project::sym printrulestatistics
71
+ project::sym printtypestatistics
72
+ }
6573
6674
log write 1 collsym "Collation completed"
6775
return
6876
}
6977
@@ -89,12 +97,15 @@
8997
}
9098
9199
namespace eval ::vc::fossil::import::cvs::pass {
92100
namespace export collsym
93101
namespace eval collsym {
94
- #namespace import ::vc::fossil::import::cvs::repository
102
+ namespace import ::vc::fossil::import::cvs::repository
95103
namespace import ::vc::fossil::import::cvs::state
104
+ namespace eval project {
105
+ namespace import ::vc::fossil::import::cvs::project::sym
106
+ }
96107
#namespace import ::vc::tools::trouble
97108
namespace import ::vc::tools::log
98109
log register collsym
99110
}
100111
}
101112
--- tools/cvs2fossil/lib/c2f_pcollsym.tcl
+++ tools/cvs2fossil/lib/c2f_pcollsym.tcl
@@ -16,19 +16,20 @@
16 ## 'FilterSym', which performs the actual deletion.
17
18 # # ## ### ##### ######## ############# #####################
19 ## Requirements
20
21 package require Tcl 8.4 ; # Required runtime.
22 package require snit ; # OO system.
23 #package require fileutil::traverse ; # Directory traversal.
24 #package require fileutil ; # File & path utilities.
25 #package require vc::tools::trouble ; # Error reporting.
26 package require vc::tools::log ; # User feedback.
27 #package require vc::fossil::import::cvs::pass ; # Pass management.
28 #package require vc::fossil::import::cvs::repository ; # Repository management.
29 package require vc::fossil::import::cvs::state ; # State storage.
 
30
31 # # ## ### ##### ######## ############# #####################
32 ## Register the pass with the management
33
34 vc::fossil::import::cvs::pass define \
@@ -60,10 +61,17 @@
60 }
61
62 typemethod run {} {
63 # Pass manager interface. Executed to perform the
64 # functionality of the pass.
 
 
 
 
 
 
 
65
66 log write 1 collsym "Collation completed"
67 return
68 }
69
@@ -89,12 +97,15 @@
89 }
90
91 namespace eval ::vc::fossil::import::cvs::pass {
92 namespace export collsym
93 namespace eval collsym {
94 #namespace import ::vc::fossil::import::cvs::repository
95 namespace import ::vc::fossil::import::cvs::state
 
 
 
96 #namespace import ::vc::tools::trouble
97 namespace import ::vc::tools::log
98 log register collsym
99 }
100 }
101
--- tools/cvs2fossil/lib/c2f_pcollsym.tcl
+++ tools/cvs2fossil/lib/c2f_pcollsym.tcl
@@ -16,19 +16,20 @@
16 ## 'FilterSym', which performs the actual deletion.
17
18 # # ## ### ##### ######## ############# #####################
19 ## Requirements
20
21 package require Tcl 8.4 ; # Required runtime.
22 package require snit ; # OO system.
23 #package require fileutil::traverse ; # Directory traversal.
24 #package require fileutil ; # File & path utilities.
25 #package require vc::tools::trouble ; # Error reporting.
26 package require vc::tools::log ; # User feedback.
27 #package require vc::fossil::import::cvs::pass ; # Pass management.
28 package require vc::fossil::import::cvs::repository ; # Repository management.
29 package require vc::fossil::import::cvs::state ; # State storage.
30 package require vc::fossil::import::cvs::project::sym ; # Project level symbols
31
32 # # ## ### ##### ######## ############# #####################
33 ## Register the pass with the management
34
35 vc::fossil::import::cvs::pass define \
@@ -60,10 +61,17 @@
61 }
62
63 typemethod run {} {
64 # Pass manager interface. Executed to perform the
65 # functionality of the pass.
66
67 state transaction {
68 repository determinesymboltypes
69
70 project::sym printrulestatistics
71 project::sym printtypestatistics
72 }
73
74 log write 1 collsym "Collation completed"
75 return
76 }
77
@@ -89,12 +97,15 @@
97 }
98
99 namespace eval ::vc::fossil::import::cvs::pass {
100 namespace export collsym
101 namespace eval collsym {
102 namespace import ::vc::fossil::import::cvs::repository
103 namespace import ::vc::fossil::import::cvs::state
104 namespace eval project {
105 namespace import ::vc::fossil::import::cvs::project::sym
106 }
107 #namespace import ::vc::tools::trouble
108 namespace import ::vc::tools::log
109 log register collsym
110 }
111 }
112
--- tools/cvs2fossil/lib/c2f_project.tcl
+++ tools/cvs2fossil/lib/c2f_project.tcl
@@ -94,10 +94,17 @@
9494
$symbol destroy
9595
unset mysymbol($name)
9696
set changes 1
9797
}
9898
}
99
+ return
100
+ }
101
+
102
+ method determinesymboltypes {} {
103
+ foreach {name symbol} [array get mysymbol] {
104
+ $symbol determinetype
105
+ }
99106
return
100107
}
101108
102109
# pass I persistence
103110
method persist {} {
104111
--- tools/cvs2fossil/lib/c2f_project.tcl
+++ tools/cvs2fossil/lib/c2f_project.tcl
@@ -94,10 +94,17 @@
94 $symbol destroy
95 unset mysymbol($name)
96 set changes 1
97 }
98 }
 
 
 
 
 
 
 
99 return
100 }
101
102 # pass I persistence
103 method persist {} {
104
--- tools/cvs2fossil/lib/c2f_project.tcl
+++ tools/cvs2fossil/lib/c2f_project.tcl
@@ -94,10 +94,17 @@
94 $symbol destroy
95 unset mysymbol($name)
96 set changes 1
97 }
98 }
99 return
100 }
101
102 method determinesymboltypes {} {
103 foreach {name symbol} [array get mysymbol] {
104 $symbol determinetype
105 }
106 return
107 }
108
109 # pass I persistence
110 method persist {} {
111
--- tools/cvs2fossil/lib/c2f_psym.tcl
+++ tools/cvs2fossil/lib/c2f_psym.tcl
@@ -13,14 +13,17 @@
1313
## Symbols (Tags, Branches) per project.
1414
1515
# # ## ### ##### ######## ############# #####################
1616
## Requirements
1717
18
-package require Tcl 8.4 ; # Required runtime.
19
-package require snit ; # OO system.
20
-package require struct::set ; # Set handling.
21
-package require vc::fossil::import::cvs::state ; # State storage.
18
+package require Tcl 8.4 ; # Required runtime.
19
+package require snit ; # OO system.
20
+package require vc::tools::trouble ; # Error reporting.
21
+package require vc::tools::log ; # User feedback.
22
+package require vc::tools::misc ; # Text formatting.
23
+package require vc::fossil::import::cvs::state ; # State storage.
24
+package require struct::set ; # Set handling.
2225
2326
# # ## ### ##### ######## ############# #####################
2427
##
2528
2629
snit::type ::vc::fossil::import::cvs::project::sym {
@@ -29,16 +32,59 @@
2932
3033
constructor {name id project} {
3134
set myname $name
3235
set myid $id
3336
set myproject $project
37
+
38
+ # Count total number of symbols.
39
+ incr mynum
3440
return
3541
}
3642
3743
method name {} { return $myname }
3844
method id {} { return $myid }
3945
46
+ # # ## ### ##### ######## #############
47
+ ## Symbol type
48
+
49
+ method determinetype {} {
50
+ # This is done by a fixed heuristics, with guidance by the
51
+ # user in edge-cases. Contrary to cvs2svn which uses a big
52
+ # honking streagy class and rule objects. Keep it simple, we
53
+ # can expand later when we actually need all the complexity
54
+ # for configurability.
55
+
56
+ # The following guidelines are applied:
57
+ # - Is usage unambigous ?
58
+ # - Was there ever a commit on the symbol ?
59
+ # - More used as tag, or more used as branch ?
60
+ # - At last, what has the user told us about it ?
61
+ # - Fail
62
+
63
+ foreach rule {
64
+ UserConfig
65
+ Unambigous
66
+ HasCommits
67
+ VoteCounts
68
+ } {
69
+ set chosen [$self $rule]
70
+ if {$chosen eq $myundef} continue
71
+ $self MarkAs $rule $chosen
72
+ return
73
+ }
74
+
75
+ # None of the above was able to decide which type to assign to
76
+ # the symbol. This is a fatal error preventing the execution
77
+ # of the passes after 'CollateSymbols'.
78
+
79
+ incr myrulecount(Undecided_)
80
+ trouble fatal "Unable to decide how to convert symbol '$myname'"
81
+ return
82
+ }
83
+
84
+ method markthetrunk {} { $self MarkAs IsTheTrunk $mybranch ; return }
85
+
4086
# # ## ### ##### ######## #############
4187
## Symbol statistics
4288
4389
method defcounts {tc bc cc} {
4490
set mybranchcount $tc
@@ -126,38 +172,158 @@
126172
# the exclusion of this symbol.
127173
128174
variable mypparent -array {} ; # Maps from symbols to the number
129175
# of files in which it could have
130176
# been a parent of this symbol.
177
+
178
+ variable mytype {} ; # The type chosen for the symbol to use in
179
+ # the conversion.
180
+
181
+ # # ## ### ##### ######## #############
182
+
183
+ typemethod getsymtypes {} {
184
+ foreach {tid name} [state run {
185
+ SELECT tid, name FROM symtype;
186
+ }] { set mysymtype($tid) $name }
187
+ return
188
+ }
131189
132190
# Keep the codes below in sync with 'pass::collrev/setup('symtype').
133
- typevariable myexcluded 0 ; # Code for symbols which are excluded.
134
- typevariable mytag 1 ; # Code for symbols which are tags.
135
- typevariable mybranch 2 ; # Code for symbols which are branches.
136
- typevariable myundef 3 ; # Code for symbols of unknown type.
191
+ typevariable myexcluded 0 ; # Code for symbols which are excluded.
192
+ typevariable mytag 1 ; # Code for symbols which are tags.
193
+ typevariable mybranch 2 ; # Code for symbols which are branches.
194
+ typevariable myundef 3 ; # Code for symbols of unknown type.
195
+ typevariable mysymtype -array {} ; # Map from type code to label for the log.
196
+
197
+ typemethod printrulestatistics {} {
198
+ log write 2 symbol "Rule usage statistics:"
199
+
200
+ set fmt %[string length $mynum]s
201
+ set all 0
202
+
203
+ foreach key [lsort [array names myrulecount]] {
204
+ log write 2 symbol "* [format $fmt $myrulecount($key)] $key"
205
+ incr all $myrulecount($key)
206
+ }
207
+
208
+ log write 2 symbol "= [format $fmt $all] total"
209
+ return
210
+ }
211
+
212
+ # Statistics on how often each 'rule' was used to decide on the
213
+ # type of a symbol.
214
+ typevariable myrulecount -array {
215
+ HasCommits 0
216
+ IsTheTrunk 0
217
+ Unambigous 0
218
+ Undecided_ 0
219
+ UserConfig 0
220
+ VoteCounts 0
221
+ }
222
+
223
+ typemethod printtypestatistics {} {
224
+ log write 2 symbol "Symbol type statistics:"
225
+
226
+ set fmt %[string length $mynum]s
227
+ set all 0
228
+
229
+ foreach {stype splural n} [state run {
230
+ SELECT T.name, T.plural, COUNT (s.sid)
231
+ FROM symbol S, symtype T
232
+ WHERE S.type = T.tid
233
+ GROUP BY T.name
234
+ ORDER BY T.name
235
+ ;
236
+ }] {
237
+ log write 2 symbol "* [format $fmt $n] [sp $n $stype $splural]"
238
+ incr all $n
239
+ }
240
+
241
+ log write 2 symbol "= [format $fmt $all] total"
242
+ return
243
+ }
244
+
245
+ typevariable mynum 0
137246
138247
# # ## ### ##### ######## #############
139248
## Internal methods
249
+
250
+ method UserConfig {} {
251
+ # No user based guidance yet.
252
+ return $myundef
253
+ }
254
+
255
+ method Unambigous {} {
256
+ # If a symbol is used unambiguously as a tag/branch, convert
257
+ # it as such.
258
+
259
+ set istag [expr {$mytagcount > 0}]
260
+ set isbranch [expr {$mybranchcount > 0 || $mycommitcount > 0}]
261
+
262
+ if {$istag && $isbranch} { return $myundef }
263
+ if {$istag} { return $mytag }
264
+ if {$isbranch} { return $mybranch }
265
+
266
+ # Symbol was not used at all.
267
+ return $myundef
268
+ }
269
+
270
+ method HasCommits {} {
271
+ # If there was ever a commit on the symbol, convert it as a
272
+ # branch.
273
+
274
+ if {$mycommitcount > 0} { return $mybranch }
275
+ return $myundef
276
+ }
277
+
278
+ method VoteCounts {} {
279
+ # Convert the symbol based on how often it was used as a
280
+ # branch/tag. Whichever happened more often determines how the
281
+ # symbol is converted.
282
+
283
+ if {$mytagcount > $mybranchcount} { return $mytag }
284
+ if {$mytagcount < $mybranchcount} { return $mybranch }
285
+ return $myundef
286
+ }
287
+
288
+ method MarkAs {label chosen} {
289
+ log write 3 symbol "\[$label\] Converting symbol '$myname' as $mysymtype($chosen)"
290
+
291
+ set mytype $chosen
292
+ incr myrulecount($label)
293
+
294
+ # This is stored directly into the database.
295
+ state run {
296
+ UPDATE symbol
297
+ SET type = $chosen
298
+ WHERE sid = $myid
299
+ ;
300
+ }
301
+ return
302
+ }
140303
141304
# # ## ### ##### ######## #############
142305
## Configuration
143306
144307
pragma -hastypeinfo no ; # no type introspection
145308
pragma -hasinfo no ; # no object introspection
146
- pragma -hastypemethods no ; # type is not relevant.
147309
pragma -simpledispatch yes ; # simple fast dispatch
148310
149311
# # ## ### ##### ######## #############
150312
}
151313
152314
namespace eval ::vc::fossil::import::cvs::project {
153315
namespace export sym
154316
namespace eval sym {
155317
namespace import ::vc::fossil::import::cvs::state
318
+ namespace import ::vc::tools::misc::*
319
+ namespace import ::vc::tools::trouble
320
+ namespace import ::vc::tools::log
321
+ log register symbol
156322
}
157323
}
158324
159325
# # ## ### ##### ######## ############# #####################
160326
## Ready
161327
162328
package provide vc::fossil::import::cvs::project::sym 1.0
163329
return
164330
--- tools/cvs2fossil/lib/c2f_psym.tcl
+++ tools/cvs2fossil/lib/c2f_psym.tcl
@@ -13,14 +13,17 @@
13 ## Symbols (Tags, Branches) per project.
14
15 # # ## ### ##### ######## ############# #####################
16 ## Requirements
17
18 package require Tcl 8.4 ; # Required runtime.
19 package require snit ; # OO system.
20 package require struct::set ; # Set handling.
21 package require vc::fossil::import::cvs::state ; # State storage.
 
 
 
22
23 # # ## ### ##### ######## ############# #####################
24 ##
25
26 snit::type ::vc::fossil::import::cvs::project::sym {
@@ -29,16 +32,59 @@
29
30 constructor {name id project} {
31 set myname $name
32 set myid $id
33 set myproject $project
 
 
 
34 return
35 }
36
37 method name {} { return $myname }
38 method id {} { return $myid }
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40 # # ## ### ##### ######## #############
41 ## Symbol statistics
42
43 method defcounts {tc bc cc} {
44 set mybranchcount $tc
@@ -126,38 +172,158 @@
126 # the exclusion of this symbol.
127
128 variable mypparent -array {} ; # Maps from symbols to the number
129 # of files in which it could have
130 # been a parent of this symbol.
 
 
 
 
 
 
 
 
 
 
 
 
131
132 # Keep the codes below in sync with 'pass::collrev/setup('symtype').
133 typevariable myexcluded 0 ; # Code for symbols which are excluded.
134 typevariable mytag 1 ; # Code for symbols which are tags.
135 typevariable mybranch 2 ; # Code for symbols which are branches.
136 typevariable myundef 3 ; # Code for symbols of unknown type.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
138 # # ## ### ##### ######## #############
139 ## Internal methods
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
141 # # ## ### ##### ######## #############
142 ## Configuration
143
144 pragma -hastypeinfo no ; # no type introspection
145 pragma -hasinfo no ; # no object introspection
146 pragma -hastypemethods no ; # type is not relevant.
147 pragma -simpledispatch yes ; # simple fast dispatch
148
149 # # ## ### ##### ######## #############
150 }
151
152 namespace eval ::vc::fossil::import::cvs::project {
153 namespace export sym
154 namespace eval sym {
155 namespace import ::vc::fossil::import::cvs::state
 
 
 
 
156 }
157 }
158
159 # # ## ### ##### ######## ############# #####################
160 ## Ready
161
162 package provide vc::fossil::import::cvs::project::sym 1.0
163 return
164
--- tools/cvs2fossil/lib/c2f_psym.tcl
+++ tools/cvs2fossil/lib/c2f_psym.tcl
@@ -13,14 +13,17 @@
13 ## Symbols (Tags, Branches) per project.
14
15 # # ## ### ##### ######## ############# #####################
16 ## Requirements
17
18 package require Tcl 8.4 ; # Required runtime.
19 package require snit ; # OO system.
20 package require vc::tools::trouble ; # Error reporting.
21 package require vc::tools::log ; # User feedback.
22 package require vc::tools::misc ; # Text formatting.
23 package require vc::fossil::import::cvs::state ; # State storage.
24 package require struct::set ; # Set handling.
25
26 # # ## ### ##### ######## ############# #####################
27 ##
28
29 snit::type ::vc::fossil::import::cvs::project::sym {
@@ -29,16 +32,59 @@
32
33 constructor {name id project} {
34 set myname $name
35 set myid $id
36 set myproject $project
37
38 # Count total number of symbols.
39 incr mynum
40 return
41 }
42
43 method name {} { return $myname }
44 method id {} { return $myid }
45
46 # # ## ### ##### ######## #############
47 ## Symbol type
48
49 method determinetype {} {
50 # This is done by a fixed heuristics, with guidance by the
51 # user in edge-cases. Contrary to cvs2svn which uses a big
52 # honking streagy class and rule objects. Keep it simple, we
53 # can expand later when we actually need all the complexity
54 # for configurability.
55
56 # The following guidelines are applied:
57 # - Is usage unambigous ?
58 # - Was there ever a commit on the symbol ?
59 # - More used as tag, or more used as branch ?
60 # - At last, what has the user told us about it ?
61 # - Fail
62
63 foreach rule {
64 UserConfig
65 Unambigous
66 HasCommits
67 VoteCounts
68 } {
69 set chosen [$self $rule]
70 if {$chosen eq $myundef} continue
71 $self MarkAs $rule $chosen
72 return
73 }
74
75 # None of the above was able to decide which type to assign to
76 # the symbol. This is a fatal error preventing the execution
77 # of the passes after 'CollateSymbols'.
78
79 incr myrulecount(Undecided_)
80 trouble fatal "Unable to decide how to convert symbol '$myname'"
81 return
82 }
83
84 method markthetrunk {} { $self MarkAs IsTheTrunk $mybranch ; return }
85
86 # # ## ### ##### ######## #############
87 ## Symbol statistics
88
89 method defcounts {tc bc cc} {
90 set mybranchcount $tc
@@ -126,38 +172,158 @@
172 # the exclusion of this symbol.
173
174 variable mypparent -array {} ; # Maps from symbols to the number
175 # of files in which it could have
176 # been a parent of this symbol.
177
178 variable mytype {} ; # The type chosen for the symbol to use in
179 # the conversion.
180
181 # # ## ### ##### ######## #############
182
183 typemethod getsymtypes {} {
184 foreach {tid name} [state run {
185 SELECT tid, name FROM symtype;
186 }] { set mysymtype($tid) $name }
187 return
188 }
189
190 # Keep the codes below in sync with 'pass::collrev/setup('symtype').
191 typevariable myexcluded 0 ; # Code for symbols which are excluded.
192 typevariable mytag 1 ; # Code for symbols which are tags.
193 typevariable mybranch 2 ; # Code for symbols which are branches.
194 typevariable myundef 3 ; # Code for symbols of unknown type.
195 typevariable mysymtype -array {} ; # Map from type code to label for the log.
196
197 typemethod printrulestatistics {} {
198 log write 2 symbol "Rule usage statistics:"
199
200 set fmt %[string length $mynum]s
201 set all 0
202
203 foreach key [lsort [array names myrulecount]] {
204 log write 2 symbol "* [format $fmt $myrulecount($key)] $key"
205 incr all $myrulecount($key)
206 }
207
208 log write 2 symbol "= [format $fmt $all] total"
209 return
210 }
211
212 # Statistics on how often each 'rule' was used to decide on the
213 # type of a symbol.
214 typevariable myrulecount -array {
215 HasCommits 0
216 IsTheTrunk 0
217 Unambigous 0
218 Undecided_ 0
219 UserConfig 0
220 VoteCounts 0
221 }
222
223 typemethod printtypestatistics {} {
224 log write 2 symbol "Symbol type statistics:"
225
226 set fmt %[string length $mynum]s
227 set all 0
228
229 foreach {stype splural n} [state run {
230 SELECT T.name, T.plural, COUNT (s.sid)
231 FROM symbol S, symtype T
232 WHERE S.type = T.tid
233 GROUP BY T.name
234 ORDER BY T.name
235 ;
236 }] {
237 log write 2 symbol "* [format $fmt $n] [sp $n $stype $splural]"
238 incr all $n
239 }
240
241 log write 2 symbol "= [format $fmt $all] total"
242 return
243 }
244
245 typevariable mynum 0
246
247 # # ## ### ##### ######## #############
248 ## Internal methods
249
250 method UserConfig {} {
251 # No user based guidance yet.
252 return $myundef
253 }
254
255 method Unambigous {} {
256 # If a symbol is used unambiguously as a tag/branch, convert
257 # it as such.
258
259 set istag [expr {$mytagcount > 0}]
260 set isbranch [expr {$mybranchcount > 0 || $mycommitcount > 0}]
261
262 if {$istag && $isbranch} { return $myundef }
263 if {$istag} { return $mytag }
264 if {$isbranch} { return $mybranch }
265
266 # Symbol was not used at all.
267 return $myundef
268 }
269
270 method HasCommits {} {
271 # If there was ever a commit on the symbol, convert it as a
272 # branch.
273
274 if {$mycommitcount > 0} { return $mybranch }
275 return $myundef
276 }
277
278 method VoteCounts {} {
279 # Convert the symbol based on how often it was used as a
280 # branch/tag. Whichever happened more often determines how the
281 # symbol is converted.
282
283 if {$mytagcount > $mybranchcount} { return $mytag }
284 if {$mytagcount < $mybranchcount} { return $mybranch }
285 return $myundef
286 }
287
288 method MarkAs {label chosen} {
289 log write 3 symbol "\[$label\] Converting symbol '$myname' as $mysymtype($chosen)"
290
291 set mytype $chosen
292 incr myrulecount($label)
293
294 # This is stored directly into the database.
295 state run {
296 UPDATE symbol
297 SET type = $chosen
298 WHERE sid = $myid
299 ;
300 }
301 return
302 }
303
304 # # ## ### ##### ######## #############
305 ## Configuration
306
307 pragma -hastypeinfo no ; # no type introspection
308 pragma -hasinfo no ; # no object introspection
 
309 pragma -simpledispatch yes ; # simple fast dispatch
310
311 # # ## ### ##### ######## #############
312 }
313
314 namespace eval ::vc::fossil::import::cvs::project {
315 namespace export sym
316 namespace eval sym {
317 namespace import ::vc::fossil::import::cvs::state
318 namespace import ::vc::tools::misc::*
319 namespace import ::vc::tools::trouble
320 namespace import ::vc::tools::log
321 log register symbol
322 }
323 }
324
325 # # ## ### ##### ######## ############# #####################
326 ## Ready
327
328 package provide vc::fossil::import::cvs::project::sym 1.0
329 return
330
--- tools/cvs2fossil/lib/c2f_ptrunk.tcl
+++ tools/cvs2fossil/lib/c2f_ptrunk.tcl
@@ -52,10 +52,12 @@
5252
method possibleparent {symbol} {}
5353
5454
method isghost {} { return 0 }
5555
5656
delegate method persistrev to mysymbol
57
+
58
+ method determinetype {} { $mysymbol markthetrunk }
5759
5860
# # ## ### ##### ######## #############
5961
## State
6062
6163
typevariable myname :trunk: ; # Name shared by all trunk symbols.
6264
--- tools/cvs2fossil/lib/c2f_ptrunk.tcl
+++ tools/cvs2fossil/lib/c2f_ptrunk.tcl
@@ -52,10 +52,12 @@
52 method possibleparent {symbol} {}
53
54 method isghost {} { return 0 }
55
56 delegate method persistrev to mysymbol
 
 
57
58 # # ## ### ##### ######## #############
59 ## State
60
61 typevariable myname :trunk: ; # Name shared by all trunk symbols.
62
--- tools/cvs2fossil/lib/c2f_ptrunk.tcl
+++ tools/cvs2fossil/lib/c2f_ptrunk.tcl
@@ -52,10 +52,12 @@
52 method possibleparent {symbol} {}
53
54 method isghost {} { return 0 }
55
56 delegate method persistrev to mysymbol
57
58 method determinetype {} { $mysymbol markthetrunk }
59
60 # # ## ### ##### ######## #############
61 ## State
62
63 typevariable myname :trunk: ; # Name shared by all trunk symbols.
64
--- tools/cvs2fossil/lib/c2f_repository.tcl
+++ tools/cvs2fossil/lib/c2f_repository.tcl
@@ -208,10 +208,17 @@
208208
# that everything is 'undefined' at this point anyway.
209209
210210
# future: $symbol load (blockers, and parents)
211211
}
212212
}
213
+ return
214
+ }
215
+
216
+ typemethod determinesymboltypes {} {
217
+ foreach project [TheProjects] {
218
+ $project determinesymboltypes
219
+ }
213220
return
214221
}
215222
216223
# # ## ### ##### ######## #############
217224
## State
218225
--- tools/cvs2fossil/lib/c2f_repository.tcl
+++ tools/cvs2fossil/lib/c2f_repository.tcl
@@ -208,10 +208,17 @@
208 # that everything is 'undefined' at this point anyway.
209
210 # future: $symbol load (blockers, and parents)
211 }
212 }
 
 
 
 
 
 
 
213 return
214 }
215
216 # # ## ### ##### ######## #############
217 ## State
218
--- tools/cvs2fossil/lib/c2f_repository.tcl
+++ tools/cvs2fossil/lib/c2f_repository.tcl
@@ -208,10 +208,17 @@
208 # that everything is 'undefined' at this point anyway.
209
210 # future: $symbol load (blockers, and parents)
211 }
212 }
213 return
214 }
215
216 typemethod determinesymboltypes {} {
217 foreach project [TheProjects] {
218 $project determinesymboltypes
219 }
220 return
221 }
222
223 # # ## ### ##### ######## #############
224 ## State
225

Keyboard Shortcuts

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