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.
Commit
fb1e36d29079d0277625d26dc936071b80687370
Parent
eb656de7d9a95af…
2 files changed
+16
-1
+45
-5
+16
-1
| --- tools/cvs2fossil/lib/c2f_pcollar.tcl | ||
| +++ tools/cvs2fossil/lib/c2f_pcollar.tcl | ||
| @@ -24,10 +24,11 @@ | ||
| 24 | 24 | package require fileutil ; # File & path utilities. |
| 25 | 25 | package require vc::tools::trouble ; # Error reporting. |
| 26 | 26 | package require vc::tools::log ; # User feedback. |
| 27 | 27 | package require vc::fossil::import::cvs::pass ; # Pass management. |
| 28 | 28 | package require vc::fossil::import::cvs::repository ; # Repository management. |
| 29 | +package require vc::fossil::import::cvs::state ; # State storage | |
| 29 | 30 | |
| 30 | 31 | # # ## ### ##### ######## ############# ##################### |
| 31 | 32 | ## Register the pass with the management |
| 32 | 33 | |
| 33 | 34 | vc::fossil::import::cvs::pass define \ |
| @@ -41,11 +42,24 @@ | ||
| 41 | 42 | snit::type ::vc::fossil::import::cvs::pass::collar { |
| 42 | 43 | # # ## ### ##### ######## ############# |
| 43 | 44 | ## Public API |
| 44 | 45 | |
| 45 | 46 | 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 | |
| 47 | 61 | } |
| 48 | 62 | |
| 49 | 63 | typemethod run {} { |
| 50 | 64 | set rbase [repository base?] |
| 51 | 65 | foreach project [repository projects] { |
| @@ -164,10 +178,11 @@ | ||
| 164 | 178 | |
| 165 | 179 | namespace eval ::vc::fossil::import::cvs::pass { |
| 166 | 180 | namespace export collar |
| 167 | 181 | namespace eval collar { |
| 168 | 182 | namespace import ::vc::fossil::import::cvs::repository |
| 183 | + namespace import ::vc::fossil::import::cvs::state | |
| 169 | 184 | namespace import ::vc::tools::trouble |
| 170 | 185 | namespace import ::vc::tools::log |
| 171 | 186 | log register collar |
| 172 | 187 | } |
| 173 | 188 | } |
| 174 | 189 |
| --- 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 |
+45
-5
| --- tools/cvs2fossil/lib/c2f_state.tcl | ||
| +++ tools/cvs2fossil/lib/c2f_state.tcl | ||
| @@ -61,25 +61,29 @@ | ||
| 61 | 61 | # A previously defined state database is closed before |
| 62 | 62 | # committing to the new definition. We do not store the path |
| 63 | 63 | # itself, this ensures that the file is _not_ cleaned up after |
| 64 | 64 | # a run. |
| 65 | 65 | |
| 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 | |
| 68 | 71 | |
| 69 | - set mypath {} | |
| 72 | + log write 2 state "is $path" | |
| 70 | 73 | return |
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | typemethod setup {} { |
| 74 | 77 | # If, and only if no state database was defined by the user |
| 75 | 78 | # then it is now the time to create our own using a tempfile. |
| 76 | 79 | |
| 77 | - if {[llength [info commands ${type}::STATE]]} return | |
| 80 | + if {$mystate ne ""} return | |
| 78 | 81 | |
| 79 | 82 | set mypath [fileutil::tempfile cvs2fossil_state_] |
| 80 | - sqlite3 ${type}::STATE $mypath | |
| 83 | + set mystate ${type}::STATE | |
| 84 | + sqlite3 $mystate $mypath | |
| 81 | 85 | |
| 82 | 86 | log write 2 state "using $mypath" |
| 83 | 87 | return |
| 84 | 88 | } |
| 85 | 89 | |
| @@ -88,10 +92,46 @@ | ||
| 88 | 92 | ${type}::STATE close |
| 89 | 93 | if {$mypath eq ""} return |
| 90 | 94 | file delete $mypath |
| 91 | 95 | return |
| 92 | 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 | + } | |
| 93 | 133 | |
| 94 | 134 | # # ## ### ##### ######## ############# |
| 95 | 135 | ## State |
| 96 | 136 | |
| 97 | 137 | typevariable mystate {} ; # Sqlite database (command) holding the converter state. |
| 98 | 138 |
| --- 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 |