| | @@ -40,91 +40,42 @@ |
| 40 | 40 | |
| 41 | 41 | # ----------------------------------------------------------------------------- |
| 42 | 42 | # Requirements |
| 43 | 43 | |
| 44 | 44 | package require Tcl 8.4 |
| 45 | | -package require cvs ; # Frontend, reading from source repository |
| 46 | | -package require fossil ; # Backend, writing to destination repository. |
| 47 | | -package require tools::log |
| 48 | | - |
| 49 | | -::tools::log::system import |
| 45 | +package require tools::log ; # User Feedback |
| 46 | +package require import::cvs ; # Importer Control |
| 50 | 47 | |
| 51 | 48 | # ----------------------------------------------------------------------------- |
| 52 | 49 | |
| 53 | 50 | proc main {} { |
| 54 | | - global argv tot nto cvs fossil ntrunk stopat nmax ntfmt nmfmt |
| 55 | | - |
| 56 | | - commandline |
| 57 | | - |
| 58 | | - cvs::at $cvs ; # Define location of CVS repository |
| 59 | | - cvs::scan ; # Gather revision data from the archives |
| 60 | | - cvs::csets ; # Group changes into sets |
| 61 | | - cvs::rtree ; # Build revision tree (trunk only right now). |
| 62 | | - |
| 63 | | - set tot 0.0 |
| 64 | | - set nto 0 |
| 65 | | - |
| 66 | | - ::tools::log::write 0 import {Begin conversion} |
| 67 | | - ::tools::log::write 0 import {Setting up workspaces} |
| 68 | | - |
| 69 | | - cvs::workspace ; # cd's to workspace |
| 70 | | - fossil::new ; # Uses cwd as workspace to connect to. |
| 71 | | - |
| 72 | | - set ntrunk [cvs::ntrunk] ; set ntfmt %[string length $ntrunk]s |
| 73 | | - set nmax [cvs::ncsets] ; set nmfmt %[string length $nmax]s |
| 74 | | - |
| 75 | | - cvs::foreach_cset cset [cvs::root] { |
| 76 | | - import $cset |
| 77 | | - if {$stopat == $cset} exit |
| 78 | | - } |
| 79 | | - cvs::wsclear |
| 80 | | - |
| 81 | | - ::tools::log::write 0 import "========= [string repeat = 61]" |
| 82 | | - ::tools::log::write 0 import "Imported $nto [expr {($nto == 1) ? "changeset" : "changesets"}]" |
| 83 | | - ::tools::log::write 0 import "Within [format %.2f $tot] seconds (avg [format %.2f [expr {$tot/$nto}]] seconds/changeset)" |
| 84 | | - |
| 85 | | - fossil::destination $fossil |
| 86 | | - |
| 87 | | - ::tools::log::write 0 import Ok. |
| 51 | + commandline -> cvs fossil |
| 52 | + import::cvs::run $cvs $fossil |
| 88 | 53 | return |
| 89 | 54 | } |
| 90 | 55 | |
| 91 | | - |
| 92 | 56 | # ----------------------------------------------------------------------------- |
| 93 | 57 | |
| 94 | | -proc commandline {} { |
| 95 | | - global argv cvs fossil nosign debugcommit stopat |
| 58 | +proc commandline {__ cv fv} { |
| 59 | + global argv |
| 60 | + upvar 1 $cv cvs $fv fossil |
| 96 | 61 | |
| 97 | | - set nosign 0 |
| 98 | | - set debugcommit 0 |
| 99 | | - set stopat {} |
| 100 | 62 | set verbosity 0 |
| 101 | 63 | |
| 102 | | - while {[string match "-*" [set opt [lindex $argv 0]]]} { |
| 103 | | - if {$opt eq "--nosign"} { |
| 104 | | - set nosign 1 |
| 105 | | - set argv [lrange $argv 1 end] |
| 106 | | - continue |
| 107 | | - } |
| 108 | | - if {$opt eq "--debugcommit"} { |
| 109 | | - set debugcommit 1 |
| 110 | | - set argv [lrange $argv 1 end] |
| 111 | | - continue |
| 112 | | - } |
| 113 | | - if {$opt eq "--stopat"} { |
| 114 | | - set stopat [lindex $argv 1] |
| 115 | | - set argv [lrange $argv 2 end] |
| 116 | | - continue |
| 117 | | - } |
| 118 | | - if {$opt eq "-v"} { |
| 119 | | - incr verbosity |
| 120 | | - ::tools::log::verbosity $verbosity |
| 121 | | - set argv [lrange $argv 1 end] |
| 122 | | - continue |
| 123 | | - } |
| 124 | | - usage |
| 125 | | - } |
| 64 | + clinit |
| 65 | + while {[string match "-*" [set opt [this]]]} { |
| 66 | + switch -exact -- $opt { |
| 67 | + --nosign { import::cvs::configure -nosign 1 } |
| 68 | + --debugcommit { import::cvs::configure -debugcommit 1 } |
| 69 | + --stopat { next ; import::cvs::configure -stopat [this] } |
| 70 | + -v { incr verbosity ; ::tools::log::verbosity $verbosity } |
| 71 | + default usage |
| 72 | + } |
| 73 | + next |
| 74 | + } |
| 75 | + |
| 76 | + remainder |
| 126 | 77 | if {[llength $argv] != 2} usage |
| 127 | 78 | foreach {cvs fossil} $argv break |
| 128 | 79 | |
| 129 | 80 | if { |
| 130 | 81 | ![file exists $cvs] || |
| | @@ -134,58 +85,45 @@ |
| 134 | 85 | usage "CVS directory missing, not readable, or not a directory." |
| 135 | 86 | } elseif {[file exists $fossil]} { |
| 136 | 87 | usage "Fossil destination repository exists already." |
| 137 | 88 | } |
| 138 | 89 | |
| 139 | | - fossil::debugcommit $debugcommit |
| 90 | + return |
| 91 | +} |
| 92 | + |
| 93 | +proc this {} { |
| 94 | + global argv |
| 95 | + upvar 1 at at |
| 96 | + return [lindex $argv $at] |
| 97 | +} |
| 98 | + |
| 99 | +proc next {} { |
| 100 | + upvar 1 at at |
| 101 | + incr at |
| 102 | + return |
| 103 | +} |
| 104 | + |
| 105 | +proc remainder {} { |
| 106 | + upvar 1 at at |
| 107 | + global argv |
| 108 | + set argv [lrange $argv $at end] |
| 109 | + return |
| 110 | +} |
| 111 | + |
| 112 | +proc clinit {} { |
| 113 | + upvar 1 at at |
| 114 | + set at 0 |
| 140 | 115 | return |
| 141 | 116 | } |
| 142 | 117 | |
| 143 | 118 | proc usage {{text {}}} { |
| 144 | 119 | global argv0 |
| 145 | | - puts stderr "Usage: $argv0 ?--nosign? cvs-repository fossil-rpeository" |
| 120 | + puts stderr "Usage: $argv0 ?--nosign? ?-v? ?--stopat id? ?--debugcommit? cvs-repository fossil-repository" |
| 146 | 121 | if {$text eq ""} return |
| 147 | 122 | puts stderr " $text" |
| 148 | 123 | exit |
| 149 | 124 | } |
| 150 | 125 | |
| 151 | | -proc import {cset} { |
| 152 | | - global tot nto nosign ntrunk stopat ntfmt nmfmt |
| 153 | | - ::tools::log::write 0 import "ChangeSet [format $nmfmt $cset] @ [format $ntfmt $nto]/$ntrunk ([format %6.2f [expr {$nto*100.0/$ntrunk}]]%)" |
| 154 | | - |
| 155 | | - if {$stopat == $cset} { |
| 156 | | - fossil::commit 1 cvs2fossil $nosign \ |
| 157 | | - [cvs::wssetup $cset] \ |
| 158 | | - ::cvs::wsignore |
| 159 | | - ::tools::log::write 1 import {%% STOP} |
| 160 | | - return |
| 161 | | - } |
| 162 | | - |
| 163 | | - set usec [lindex [time { |
| 164 | | - foreach {uuid ad rm ch} [fossil::commit 0 cvs2fossil $nosign \ |
| 165 | | - [cvs::wssetup $cset] \ |
| 166 | | - ::cvs::wsignore] break |
| 167 | | - } 1] 0] |
| 168 | | - cvs::uuid $cset $uuid |
| 169 | | - |
| 170 | | - set sec [expr {$usec/1e6}] |
| 171 | | - set tot [expr {$tot + $sec}] |
| 172 | | - incr nto |
| 173 | | - |
| 174 | | - ::tools::log::write 2 import "== $uuid +${ad}-${rm}*${ch}" |
| 175 | | - ::tools::log::write 2 import "st in [format %.2f $sec] sec" |
| 176 | | - |
| 177 | | - set avg [expr {$tot/$nto}] |
| 178 | | - set max [expr {$ntrunk * $avg}] |
| 179 | | - set rem [expr {$max - $tot}] |
| 180 | | - |
| 181 | | - ::tools::log::write 3 import "st avg [format %.2f $avg] sec" |
| 182 | | - ::tools::log::write 3 import "st run [format %7.2f $tot] sec [format %6.2f [expr {$tot/60}]] min [format %5.2f [expr {$tot/3600}]] hr" |
| 183 | | - ::tools::log::write 3 import "st end [format %7.2f $max] sec [format %6.2f [expr {$max/60}]] min [format %5.2f [expr {$max/3600}]] hr" |
| 184 | | - ::tools::log::write 3 import "st rem [format %7.2f $rem] sec [format %6.2f [expr {$rem/60}]] min [format %5.2f [expr {$rem/3600}]] hr" |
| 185 | | - return |
| 186 | | -} |
| 187 | | - |
| 188 | 126 | # ----------------------------------------------------------------------------- |
| 189 | 127 | |
| 190 | 128 | main |
| 191 | 129 | exit |
| 192 | 130 | |
| 193 | 131 | ADDED tools/lib/importcvs.tcl |