Fossil SCM

Extended state handling with methods to declare usage and structure of state, started integration of state with pass I, collection of projects and files.

aku 2007-10-05 06:50 trunk
Commit fb1e36d29079d0277625d26dc936071b80687370
--- tools/cvs2fossil/lib/c2f_pcollar.tcl
+++ tools/cvs2fossil/lib/c2f_pcollar.tcl
@@ -24,10 +24,11 @@
2424
package require fileutil ; # File & path utilities.
2525
package require vc::tools::trouble ; # Error reporting.
2626
package require vc::tools::log ; # User feedback.
2727
package require vc::fossil::import::cvs::pass ; # Pass management.
2828
package require vc::fossil::import::cvs::repository ; # Repository management.
29
+package require vc::fossil::import::cvs::state ; # State storage
2930
3031
# # ## ### ##### ######## ############# #####################
3132
## Register the pass with the management
3233
3334
vc::fossil::import::cvs::pass define \
@@ -41,11 +42,24 @@
4142
snit::type ::vc::fossil::import::cvs::pass::collar {
4243
# # ## ### ##### ######## #############
4344
## Public API
4445
4546
typemethod setup {} {
46
- # TODO ... artifact/cache - drop projects/files, create projects/files
47
+ # Define names and structure of the persistent state of this
48
+ # pass.
49
+
50
+ state writing project {
51
+ pid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
52
+ name TEXT NOT NULL UNIQUE
53
+ }
54
+ state writing files {
55
+ fid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
56
+ pid INTEGER NOT NULL REFERENCES project,
57
+ name TEXT NOT NULL UNIQUE,
58
+ visible TEXT NOT NULL UNIQUE
59
+ }
60
+ return
4761
}
4862
4963
typemethod run {} {
5064
set rbase [repository base?]
5165
foreach project [repository projects] {
@@ -164,10 +178,11 @@
164178
165179
namespace eval ::vc::fossil::import::cvs::pass {
166180
namespace export collar
167181
namespace eval collar {
168182
namespace import ::vc::fossil::import::cvs::repository
183
+ namespace import ::vc::fossil::import::cvs::state
169184
namespace import ::vc::tools::trouble
170185
namespace import ::vc::tools::log
171186
log register collar
172187
}
173188
}
174189
--- tools/cvs2fossil/lib/c2f_pcollar.tcl
+++ tools/cvs2fossil/lib/c2f_pcollar.tcl
@@ -24,10 +24,11 @@
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
30 # # ## ### ##### ######## ############# #####################
31 ## Register the pass with the management
32
33 vc::fossil::import::cvs::pass define \
@@ -41,11 +42,24 @@
41 snit::type ::vc::fossil::import::cvs::pass::collar {
42 # # ## ### ##### ######## #############
43 ## Public API
44
45 typemethod setup {} {
46 # TODO ... artifact/cache - drop projects/files, create projects/files
 
 
 
 
 
 
 
 
 
 
 
 
 
47 }
48
49 typemethod run {} {
50 set rbase [repository base?]
51 foreach project [repository projects] {
@@ -164,10 +178,11 @@
164
165 namespace eval ::vc::fossil::import::cvs::pass {
166 namespace export collar
167 namespace eval collar {
168 namespace import ::vc::fossil::import::cvs::repository
 
169 namespace import ::vc::tools::trouble
170 namespace import ::vc::tools::log
171 log register collar
172 }
173 }
174
--- tools/cvs2fossil/lib/c2f_pcollar.tcl
+++ tools/cvs2fossil/lib/c2f_pcollar.tcl
@@ -24,10 +24,11 @@
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 \
@@ -41,11 +42,24 @@
42 snit::type ::vc::fossil::import::cvs::pass::collar {
43 # # ## ### ##### ######## #############
44 ## Public API
45
46 typemethod setup {} {
47 # Define names and structure of the persistent state of this
48 # pass.
49
50 state writing project {
51 pid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
52 name TEXT NOT NULL UNIQUE
53 }
54 state writing files {
55 fid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
56 pid INTEGER NOT NULL REFERENCES project,
57 name TEXT NOT NULL UNIQUE,
58 visible TEXT NOT NULL UNIQUE
59 }
60 return
61 }
62
63 typemethod run {} {
64 set rbase [repository base?]
65 foreach project [repository projects] {
@@ -164,10 +178,11 @@
178
179 namespace eval ::vc::fossil::import::cvs::pass {
180 namespace export collar
181 namespace eval collar {
182 namespace import ::vc::fossil::import::cvs::repository
183 namespace import ::vc::fossil::import::cvs::state
184 namespace import ::vc::tools::trouble
185 namespace import ::vc::tools::log
186 log register collar
187 }
188 }
189
--- tools/cvs2fossil/lib/c2f_state.tcl
+++ tools/cvs2fossil/lib/c2f_state.tcl
@@ -61,25 +61,29 @@
6161
# A previously defined state database is closed before
6262
# committing to the new definition. We do not store the path
6363
# itself, this ensures that the file is _not_ cleaned up after
6464
# a run.
6565
66
- catch { ${type}::STATE close }
67
- rename ${type}::TEMP ${type}::STATE
66
+ set mystate ${type}::STATE
67
+ set mypath {}
68
+
69
+ catch { $mystate close }
70
+ rename ${type}::TEMP $mystate
6871
69
- set mypath {}
72
+ log write 2 state "is $path"
7073
return
7174
}
7275
7376
typemethod setup {} {
7477
# If, and only if no state database was defined by the user
7578
# then it is now the time to create our own using a tempfile.
7679
77
- if {[llength [info commands ${type}::STATE]]} return
80
+ if {$mystate ne ""} return
7881
7982
set mypath [fileutil::tempfile cvs2fossil_state_]
80
- sqlite3 ${type}::STATE $mypath
83
+ set mystate ${type}::STATE
84
+ sqlite3 $mystate $mypath
8185
8286
log write 2 state "using $mypath"
8387
return
8488
}
8589
@@ -88,10 +92,46 @@
8892
${type}::STATE close
8993
if {$mypath eq ""} return
9094
file delete $mypath
9195
return
9296
}
97
+
98
+ typemethod writing {name definition} {
99
+ # Method for a user to declare a table its needs for storing
100
+ # persistent state, and the expected structure. A possibly
101
+ # previously existing definition is dropped.
102
+
103
+ $mystate transaction {
104
+ catch { $mystate eval "DROP TABLE $name" }
105
+ $mystate eval "CREATE TABLE $name ( $definition )"
106
+ }
107
+ return
108
+ }
109
+
110
+ typemethod reading {name} {
111
+ # Method for a user to declare a table it wishes to read
112
+ # from. A missing table is an internal error causing an
113
+ # immediate exit.
114
+
115
+ set found [llength [$mystate eval {
116
+ SELECT name
117
+ FROM sqlite_master
118
+ WHERE type = 'table'
119
+ AND name = $name
120
+ ;
121
+ }]]
122
+
123
+ if {$found} return
124
+
125
+ trouble internal "The required table \"$name\" is not defined."
126
+ # Not reached
127
+ return
128
+ }
129
+
130
+ typemethod run {args} {
131
+ return [uplevel 1 [linsert $args 0 $mystate eval]]
132
+ }
93133
94134
# # ## ### ##### ######## #############
95135
## State
96136
97137
typevariable mystate {} ; # Sqlite database (command) holding the converter state.
98138
--- tools/cvs2fossil/lib/c2f_state.tcl
+++ tools/cvs2fossil/lib/c2f_state.tcl
@@ -61,25 +61,29 @@
61 # A previously defined state database is closed before
62 # committing to the new definition. We do not store the path
63 # itself, this ensures that the file is _not_ cleaned up after
64 # a run.
65
66 catch { ${type}::STATE close }
67 rename ${type}::TEMP ${type}::STATE
 
 
 
68
69 set mypath {}
70 return
71 }
72
73 typemethod setup {} {
74 # If, and only if no state database was defined by the user
75 # then it is now the time to create our own using a tempfile.
76
77 if {[llength [info commands ${type}::STATE]]} return
78
79 set mypath [fileutil::tempfile cvs2fossil_state_]
80 sqlite3 ${type}::STATE $mypath
 
81
82 log write 2 state "using $mypath"
83 return
84 }
85
@@ -88,10 +92,46 @@
88 ${type}::STATE close
89 if {$mypath eq ""} return
90 file delete $mypath
91 return
92 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
94 # # ## ### ##### ######## #############
95 ## State
96
97 typevariable mystate {} ; # Sqlite database (command) holding the converter state.
98
--- tools/cvs2fossil/lib/c2f_state.tcl
+++ tools/cvs2fossil/lib/c2f_state.tcl
@@ -61,25 +61,29 @@
61 # A previously defined state database is closed before
62 # committing to the new definition. We do not store the path
63 # itself, this ensures that the file is _not_ cleaned up after
64 # a run.
65
66 set mystate ${type}::STATE
67 set mypath {}
68
69 catch { $mystate close }
70 rename ${type}::TEMP $mystate
71
72 log write 2 state "is $path"
73 return
74 }
75
76 typemethod setup {} {
77 # If, and only if no state database was defined by the user
78 # then it is now the time to create our own using a tempfile.
79
80 if {$mystate ne ""} return
81
82 set mypath [fileutil::tempfile cvs2fossil_state_]
83 set mystate ${type}::STATE
84 sqlite3 $mystate $mypath
85
86 log write 2 state "using $mypath"
87 return
88 }
89
@@ -88,10 +92,46 @@
92 ${type}::STATE close
93 if {$mypath eq ""} return
94 file delete $mypath
95 return
96 }
97
98 typemethod writing {name definition} {
99 # Method for a user to declare a table its needs for storing
100 # persistent state, and the expected structure. A possibly
101 # previously existing definition is dropped.
102
103 $mystate transaction {
104 catch { $mystate eval "DROP TABLE $name" }
105 $mystate eval "CREATE TABLE $name ( $definition )"
106 }
107 return
108 }
109
110 typemethod reading {name} {
111 # Method for a user to declare a table it wishes to read
112 # from. A missing table is an internal error causing an
113 # immediate exit.
114
115 set found [llength [$mystate eval {
116 SELECT name
117 FROM sqlite_master
118 WHERE type = 'table'
119 AND name = $name
120 ;
121 }]]
122
123 if {$found} return
124
125 trouble internal "The required table \"$name\" is not defined."
126 # Not reached
127 return
128 }
129
130 typemethod run {args} {
131 return [uplevel 1 [linsert $args 0 $mystate eval]]
132 }
133
134 # # ## ### ##### ######## #############
135 ## State
136
137 typevariable mystate {} ; # Sqlite database (command) holding the converter state.
138

Keyboard Shortcuts

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