Fossil SCM

Created a separate common class for the id databases used by the repository, and updated the repository code to use it.

aku 2007-10-21 04:42 trunk
Commit 99e165d5c40732458560dfc0522b4c301621b0ca
--- tools/cvs2fossil/lib/c2f_repository.tcl
+++ tools/cvs2fossil/lib/c2f_repository.tcl
@@ -20,10 +20,11 @@
2020
package require Tcl 8.4 ; # Required runtime.
2121
package require snit ; # OO system.
2222
package require vc::tools::trouble ; # Error reporting.
2323
package require vc::tools::log ; # User feedback.
2424
package require vc::tools::misc ; # Text formatting.
25
+package require vc::tools::id ; # Indexing and id generation.
2526
package require vc::fossil::import::cvs::project ; # CVS projects.
2627
package require vc::fossil::import::cvs::state ; # State storage.
2728
package require struct::list ; # List operations.
2829
package require fileutil ; # File operations.
2930
@@ -73,49 +74,18 @@
7374
}
7475
}
7576
return
7677
}
7778
78
- typemethod defauthor {a} {
79
- if {![info exists myauthor($a)]} {
80
- set myauthor($a) [incr myauthorcnt]
81
- log write 7 repository "author '$a' = $myauthor($a)"
82
- }
83
- return $myauthor($a)
84
- }
85
-
86
- typemethod defcmessage {cm} {
87
- if {![info exists mycmsg($cm)]} {
88
- set mycmsg($cm) [set cid [incr mycmsgcnt]]
89
- set mycmsginv($cid) $cm
90
- log write 7 repository "cmessage '$cm' = $cid"
91
- }
92
- return $mycmsg($cm)
93
- }
94
-
95
- typemethod defsymbol {pid name} {
96
- set key [list $pid $name]
97
- if {![info exists mysymbol($key)]} {
98
- set mysymbol($key) [incr mysymbolcnt]
99
- log write 7 repository "symbol ($key) = $mysymbol($key)"
100
- }
101
- return $mysymbol($key)
102
- }
103
-
104
- typemethod defmeta {pid bid aid cid} {
105
- set key [list $pid $bid $aid $cid]
106
- if {![info exists mymeta($key)]} {
107
- set mymeta($key) [set mid [incr mymetacnt]]
108
- set mymetainv($mid) $key
109
- log write 7 repository "meta ($key) = $mymeta($key)"
110
- }
111
- return $mymeta($key)
112
- }
113
-
114
- typemethod commitmessageof {metaid} {
115
- struct::list assign $mymetainv($metaid) pid bid aid cid
116
- return $mycmsginv($cid)
79
+ typemethod defauthor {a} { $myauthor put $a }
80
+ typemethod defcmessage {cm} { $mycmsg put $cm }
81
+ typemethod defsymbol {pid name} { $mysymbol put [list $pid $name] }
82
+ typemethod defmeta {pid bid aid cid} { $mymeta put [list $pid $bid $aid $cid] }
83
+
84
+ typemethod commitmessageof {mid} {
85
+ struct::list assign [$mymeta keyof $mid] pid bid aid cid
86
+ return [$mycmsg keyof $cid]
11787
}
11888
11989
# pass I results
12090
typemethod printstatistics {} {
12191
set prlist [TheProjects]
@@ -215,33 +185,35 @@
215185
typevariable mybase {} ; # Base path to CVS repository.
216186
typevariable myprojpaths {} ; # List of paths to all declared
217187
# projects, relative to mybase.
218188
typevariable myprojects {} ; # List of objects for all
219189
# declared projects.
220
- typevariable myauthor -array {} ; # Names of all authors found,
221
- # maps to their ids.
222
- typevariable myauthorcnt 0 ; # Counter for author ids.
223
- typevariable mycmsg -array {} ; # All commit messages found,
224
- # maps to their ids.
225
- typevariable mycmsginv -array {} ; # Inverted index, keyed by id.
226
- typevariable mycmsgcnt 0 ; # Counter for message ids.
227
- typevariable mymeta -array {} ; # Maps all meta data tuples
190
+ typevariable myauthor {} ; # Names of all authors found,
191
+ # maps to their ids.
192
+ typevariable mycmsg {} ; # All commit messages found,
193
+ # maps to their ids.
194
+ typevariable mymeta {} ; # Maps all meta data tuples
228195
# (project, branch, author,
229196
# cmessage) to their ids.
230
- typevariable mymetainv -array {} ; # Inverted index, keyed by id.
231
- typevariable mymetacnt 0 ; # Counter for meta ids.
232
- typevariable mysymbol -array {} ; # Map symbols identified by
197
+ typevariable mysymbol {} ; # Map symbols identified by
233198
# project and name to their
234199
# id. This information is not
235200
# saved directly.
236
- typevariable mysymbolcnt 0 ; # Counter for symbol ids.
237201
typevariable mytrunkonly 0 ; # Boolean flag. Set by option
238202
# processing when the user
239203
# requested a trunk-only import
240204
241205
# # ## ### ##### ######## #############
242206
## Internal methods
207
+
208
+ typeconstructor {
209
+ set myauthor [vc::tools::id %AUTO%]
210
+ set mycmsg [vc::tools::id %AUTO%]
211
+ set mymeta [vc::tools::id %AUTO%]
212
+ set mysymbol [vc::tools::id %AUTO%]
213
+ return
214
+ }
243215
244216
proc .BaseLength {p} {
245217
return [string length [$p printbase]]
246218
}
247219
@@ -352,10 +324,11 @@
352324
namespace export repository
353325
namespace eval repository {
354326
namespace import ::vc::fossil::import::cvs::project
355327
namespace import ::vc::fossil::import::cvs::state
356328
namespace import ::vc::tools::misc::*
329
+ namespace import ::vc::tools::id
357330
namespace import ::vc::tools::trouble
358331
namespace import ::vc::tools::log
359332
log register repository
360333
}
361334
}
362335
363336
ADDED tools/cvs2fossil/lib/id.tcl
--- tools/cvs2fossil/lib/c2f_repository.tcl
+++ tools/cvs2fossil/lib/c2f_repository.tcl
@@ -20,10 +20,11 @@
20 package require Tcl 8.4 ; # Required runtime.
21 package require snit ; # OO system.
22 package require vc::tools::trouble ; # Error reporting.
23 package require vc::tools::log ; # User feedback.
24 package require vc::tools::misc ; # Text formatting.
 
25 package require vc::fossil::import::cvs::project ; # CVS projects.
26 package require vc::fossil::import::cvs::state ; # State storage.
27 package require struct::list ; # List operations.
28 package require fileutil ; # File operations.
29
@@ -73,49 +74,18 @@
73 }
74 }
75 return
76 }
77
78 typemethod defauthor {a} {
79 if {![info exists myauthor($a)]} {
80 set myauthor($a) [incr myauthorcnt]
81 log write 7 repository "author '$a' = $myauthor($a)"
82 }
83 return $myauthor($a)
84 }
85
86 typemethod defcmessage {cm} {
87 if {![info exists mycmsg($cm)]} {
88 set mycmsg($cm) [set cid [incr mycmsgcnt]]
89 set mycmsginv($cid) $cm
90 log write 7 repository "cmessage '$cm' = $cid"
91 }
92 return $mycmsg($cm)
93 }
94
95 typemethod defsymbol {pid name} {
96 set key [list $pid $name]
97 if {![info exists mysymbol($key)]} {
98 set mysymbol($key) [incr mysymbolcnt]
99 log write 7 repository "symbol ($key) = $mysymbol($key)"
100 }
101 return $mysymbol($key)
102 }
103
104 typemethod defmeta {pid bid aid cid} {
105 set key [list $pid $bid $aid $cid]
106 if {![info exists mymeta($key)]} {
107 set mymeta($key) [set mid [incr mymetacnt]]
108 set mymetainv($mid) $key
109 log write 7 repository "meta ($key) = $mymeta($key)"
110 }
111 return $mymeta($key)
112 }
113
114 typemethod commitmessageof {metaid} {
115 struct::list assign $mymetainv($metaid) pid bid aid cid
116 return $mycmsginv($cid)
117 }
118
119 # pass I results
120 typemethod printstatistics {} {
121 set prlist [TheProjects]
@@ -215,33 +185,35 @@
215 typevariable mybase {} ; # Base path to CVS repository.
216 typevariable myprojpaths {} ; # List of paths to all declared
217 # projects, relative to mybase.
218 typevariable myprojects {} ; # List of objects for all
219 # declared projects.
220 typevariable myauthor -array {} ; # Names of all authors found,
221 # maps to their ids.
222 typevariable myauthorcnt 0 ; # Counter for author ids.
223 typevariable mycmsg -array {} ; # All commit messages found,
224 # maps to their ids.
225 typevariable mycmsginv -array {} ; # Inverted index, keyed by id.
226 typevariable mycmsgcnt 0 ; # Counter for message ids.
227 typevariable mymeta -array {} ; # Maps all meta data tuples
228 # (project, branch, author,
229 # cmessage) to their ids.
230 typevariable mymetainv -array {} ; # Inverted index, keyed by id.
231 typevariable mymetacnt 0 ; # Counter for meta ids.
232 typevariable mysymbol -array {} ; # Map symbols identified by
233 # project and name to their
234 # id. This information is not
235 # saved directly.
236 typevariable mysymbolcnt 0 ; # Counter for symbol ids.
237 typevariable mytrunkonly 0 ; # Boolean flag. Set by option
238 # processing when the user
239 # requested a trunk-only import
240
241 # # ## ### ##### ######## #############
242 ## Internal methods
 
 
 
 
 
 
 
 
243
244 proc .BaseLength {p} {
245 return [string length [$p printbase]]
246 }
247
@@ -352,10 +324,11 @@
352 namespace export repository
353 namespace eval repository {
354 namespace import ::vc::fossil::import::cvs::project
355 namespace import ::vc::fossil::import::cvs::state
356 namespace import ::vc::tools::misc::*
 
357 namespace import ::vc::tools::trouble
358 namespace import ::vc::tools::log
359 log register repository
360 }
361 }
362
363 DDED tools/cvs2fossil/lib/id.tcl
--- tools/cvs2fossil/lib/c2f_repository.tcl
+++ tools/cvs2fossil/lib/c2f_repository.tcl
@@ -20,10 +20,11 @@
20 package require Tcl 8.4 ; # Required runtime.
21 package require snit ; # OO system.
22 package require vc::tools::trouble ; # Error reporting.
23 package require vc::tools::log ; # User feedback.
24 package require vc::tools::misc ; # Text formatting.
25 package require vc::tools::id ; # Indexing and id generation.
26 package require vc::fossil::import::cvs::project ; # CVS projects.
27 package require vc::fossil::import::cvs::state ; # State storage.
28 package require struct::list ; # List operations.
29 package require fileutil ; # File operations.
30
@@ -73,49 +74,18 @@
74 }
75 }
76 return
77 }
78
79 typemethod defauthor {a} { $myauthor put $a }
80 typemethod defcmessage {cm} { $mycmsg put $cm }
81 typemethod defsymbol {pid name} { $mysymbol put [list $pid $name] }
82 typemethod defmeta {pid bid aid cid} { $mymeta put [list $pid $bid $aid $cid] }
83
84 typemethod commitmessageof {mid} {
85 struct::list assign [$mymeta keyof $mid] pid bid aid cid
86 return [$mycmsg keyof $cid]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87 }
88
89 # pass I results
90 typemethod printstatistics {} {
91 set prlist [TheProjects]
@@ -215,33 +185,35 @@
185 typevariable mybase {} ; # Base path to CVS repository.
186 typevariable myprojpaths {} ; # List of paths to all declared
187 # projects, relative to mybase.
188 typevariable myprojects {} ; # List of objects for all
189 # declared projects.
190 typevariable myauthor {} ; # Names of all authors found,
191 # maps to their ids.
192 typevariable mycmsg {} ; # All commit messages found,
193 # maps to their ids.
194 typevariable mymeta {} ; # Maps all meta data tuples
 
 
 
195 # (project, branch, author,
196 # cmessage) to their ids.
197 typevariable mysymbol {} ; # Map symbols identified by
 
 
198 # project and name to their
199 # id. This information is not
200 # saved directly.
 
201 typevariable mytrunkonly 0 ; # Boolean flag. Set by option
202 # processing when the user
203 # requested a trunk-only import
204
205 # # ## ### ##### ######## #############
206 ## Internal methods
207
208 typeconstructor {
209 set myauthor [vc::tools::id %AUTO%]
210 set mycmsg [vc::tools::id %AUTO%]
211 set mymeta [vc::tools::id %AUTO%]
212 set mysymbol [vc::tools::id %AUTO%]
213 return
214 }
215
216 proc .BaseLength {p} {
217 return [string length [$p printbase]]
218 }
219
@@ -352,10 +324,11 @@
324 namespace export repository
325 namespace eval repository {
326 namespace import ::vc::fossil::import::cvs::project
327 namespace import ::vc::fossil::import::cvs::state
328 namespace import ::vc::tools::misc::*
329 namespace import ::vc::tools::id
330 namespace import ::vc::tools::trouble
331 namespace import ::vc::tools::log
332 log register repository
333 }
334 }
335
336 DDED tools/cvs2fossil/lib/id.tcl
--- a/tools/cvs2fossil/lib/id.tcl
+++ b/tools/cvs2fossil/lib/id.tcl
@@ -0,0 +1,54 @@
1
+# # ## ### ##### ######## #############
2
+
3
+## A simple class for handling an in-memory index mapping from
4
+## arbitrary strings to a small numeric id. Can be queried in reverse
5
+## too, returning the string for the id.
6
+
7
+## Id's are starting from 1.
8
+
9
+# # ## ### ##### ######## #############
10
+## Requirements.
11
+
12
+package require Tcl ; # Runtime.
13
+package require snit ; # OO runtime.
14
+
15
+# # ## ### ##### ######## #############
16
+## Implementation.
17
+
18
+snit::type ::vc::tools::id {
19
+ # # ## ### ##### ######## #############
20
+
21
+ constructor {} {}
22
+
23
+ # # ## ### ##### ######## #############
24
+ ## Public API.
25
+ ## - Put data into the index, incl. query for id of key.
26
+ ## - Lookup data for id.
27
+
28
+ method put {key} {
29
+ if {[info exists mydata($key)]} { return $mydata($key) }
30
+ incr mycounter
31
+
32
+ set mydata($key) $mycounter
33
+ set myinvert($mycounter) $key
34
+
35
+ renvert($id) $key
36
+ }
37
+
38
+ method keyof {id} { return $myinvert($id) }
39
+
40
+ # # ## ### ##### ######## #############
41
+ ## Internal. State.
42
+
43
+ variable mydata -array {} ; # Map data -> id
44
+ variable myinvert -array {} ; # Map id -> data
45
+ variable mycounter 0 ; # Counter for id generation.
46
+
47
+ # # ## ### ##### ######## #############
48
+}
49
+
50
+namespace eval ::vc::tools {
51
+ namespace export id
52
+}
53
+
54
+# # ## ### ##### ######## #####
--- a/tools/cvs2fossil/lib/id.tcl
+++ b/tools/cvs2fossil/lib/id.tcl
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/tools/cvs2fossil/lib/id.tcl
+++ b/tools/cvs2fossil/lib/id.tcl
@@ -0,0 +1,54 @@
1 # # ## ### ##### ######## #############
2
3 ## A simple class for handling an in-memory index mapping from
4 ## arbitrary strings to a small numeric id. Can be queried in reverse
5 ## too, returning the string for the id.
6
7 ## Id's are starting from 1.
8
9 # # ## ### ##### ######## #############
10 ## Requirements.
11
12 package require Tcl ; # Runtime.
13 package require snit ; # OO runtime.
14
15 # # ## ### ##### ######## #############
16 ## Implementation.
17
18 snit::type ::vc::tools::id {
19 # # ## ### ##### ######## #############
20
21 constructor {} {}
22
23 # # ## ### ##### ######## #############
24 ## Public API.
25 ## - Put data into the index, incl. query for id of key.
26 ## - Lookup data for id.
27
28 method put {key} {
29 if {[info exists mydata($key)]} { return $mydata($key) }
30 incr mycounter
31
32 set mydata($key) $mycounter
33 set myinvert($mycounter) $key
34
35 renvert($id) $key
36 }
37
38 method keyof {id} { return $myinvert($id) }
39
40 # # ## ### ##### ######## #############
41 ## Internal. State.
42
43 variable mydata -array {} ; # Map data -> id
44 variable myinvert -array {} ; # Map id -> data
45 variable mycounter 0 ; # Counter for id generation.
46
47 # # ## ### ##### ######## #############
48 }
49
50 namespace eval ::vc::tools {
51 namespace export id
52 }
53
54 # # ## ### ##### ######## #####
--- tools/cvs2fossil/lib/pkgIndex.tcl
+++ tools/cvs2fossil/lib/pkgIndex.tcl
@@ -22,6 +22,6 @@
2222
package ifneeded vc::fossil::import::cvs::state 1.0 [list source [file join $dir c2f_state.tcl]]
2323
package ifneeded vc::rcs::parser 1.0 [list source [file join $dir rcsparser.tcl]]
2424
package ifneeded vc::tools::log 1.0 [list source [file join $dir log.tcl]]
2525
package ifneeded vc::tools::misc 1.0 [list source [file join $dir misc.tcl]]
2626
package ifneeded vc::tools::trouble 1.0 [list source [file join $dir trouble.tcl]]
27
-
27
+package ifneeded vc::tools::id 1.0 [list source [file join $dir id.tcl]]
2828
--- tools/cvs2fossil/lib/pkgIndex.tcl
+++ tools/cvs2fossil/lib/pkgIndex.tcl
@@ -22,6 +22,6 @@
22 package ifneeded vc::fossil::import::cvs::state 1.0 [list source [file join $dir c2f_state.tcl]]
23 package ifneeded vc::rcs::parser 1.0 [list source [file join $dir rcsparser.tcl]]
24 package ifneeded vc::tools::log 1.0 [list source [file join $dir log.tcl]]
25 package ifneeded vc::tools::misc 1.0 [list source [file join $dir misc.tcl]]
26 package ifneeded vc::tools::trouble 1.0 [list source [file join $dir trouble.tcl]]
27
28
--- tools/cvs2fossil/lib/pkgIndex.tcl
+++ tools/cvs2fossil/lib/pkgIndex.tcl
@@ -22,6 +22,6 @@
22 package ifneeded vc::fossil::import::cvs::state 1.0 [list source [file join $dir c2f_state.tcl]]
23 package ifneeded vc::rcs::parser 1.0 [list source [file join $dir rcsparser.tcl]]
24 package ifneeded vc::tools::log 1.0 [list source [file join $dir log.tcl]]
25 package ifneeded vc::tools::misc 1.0 [list source [file join $dir misc.tcl]]
26 package ifneeded vc::tools::trouble 1.0 [list source [file join $dir trouble.tcl]]
27 package ifneeded vc::tools::id 1.0 [list source [file join $dir id.tcl]]
28

Keyboard Shortcuts

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