Diff
Not logged in

Differences From:

File tools/lib/importcvs.tcl part of check-in [7b2619b7ef] - Unhacked the fossil backend. IOW reworked the API and made it nicer, more structured, better command and option names. Gave the internals more structure, and simplified the handling of -breakat (old -stopat breakpoint). Updated users, and updated the user visible switches as well. Added a -h switch for help. by aku on 2007-09-13 08:02:26. [view]

To:

File tools/lib/importcvs.tcl part of check-in [18251642f3] - Moved the handling of the import statistics into its own package. Untested. by aku on 2007-09-14 23:23:48. [view]

@@ -4,17 +4,19 @@
 # -----------------------------------------------------------------------------
 # Requirements
 
 package require Tcl 8.4
-package require vc::cvs::ws     ; # Frontend, reading from source repository
-package require vc::fossil::ws  ; # Backend,  writing to destination repository.
-package require vc::tools::log  ; # User feedback
+package require vc::cvs::ws               ; # Frontend, reading from source repository
+package require vc::fossil::ws            ; # Backend,  writing to destination repository.
+package require vc::tools::log            ; # User feedback
+package require vc::fossil::import::stats ; # Import Statistics
 
 namespace eval ::vc::fossil::import::cvs {
     vc::tools::log::system import
     namespace import ::vc::tools::log::write
     namespace eval cvs    { namespace import ::vc::cvs::ws::* }
     namespace eval fossil { namespace import ::vc::fossil::ws::* }
+    namespace eval stats  { namespace import ::vc::fossil::import::stats::* }
 
     fossil::configure -appname cvs2fossil
     fossil::configure -ignore  ::vc::cvs::ws::wsignore
 }
@@ -60,71 +62,44 @@
     cvs::scan     ; # Gather revision data from the archives
     cvs::csets    ; # Group changes into sets
     cvs::rtree    ; # Build revision tree (trunk only right now).
 
-    set tot 0.0
-    set nto 0
-
     write 0 import {Begin conversion}
     write 0 import {Setting up workspaces}
 
     cvs::workspace      ; # cd's to workspace
     fossil::begin [pwd] ; # Uses cwd as workspace to connect to.
-
-    set ntrunk [cvs::ntrunk] ; set ntfmt %[string length $ntrunk]s
-    set nmax   [cvs::ncsets] ; set nmfmt %[string length $nmax]s
+    stats::setup [cvs::ntrunk] [cvs::ncsets]
 
     cvs::foreach_cset cset [cvs::root] {
-	write 0 import "ChangeSet [format $nmfmt $cset] @ [format $ntfmt $nto]/$ntrunk ([format %6.2f [expr {$nto*100.0/$ntrunk}]]%)"
-	Statistics [OneChangeSet $cset]
+	OneChangeSet $cset
     }
 
-    write 0 import "========= [string repeat = 61]"
-    write 0 import "Imported $nto [expr {($nto == 1) ? "changeset" : "changesets"}]"
-    write 0 import "Within [format %.2f $tot] seconds (avg [format %.2f [expr {$tot/$nto}]] seconds/changeset)"
-
+    stats::done
     cvs::wsclear
     fossil::close $dst
+
     write 0 import Ok.
     return
 }
 
 # -----------------------------------------------------------------------------
 # Internal operations - Import a single changeset.
 
-proc ::vc::fossil::import::cvs::Statistics {sec} {
-    upvar 1 tot tot nto nto ntrunk ntrunk
+proc ::vc::fossil::import::cvs::OneChangeSet {cset} {
+    stats::csbegin $cset
 
-    # No statistics if the commit was stopped before it was run
-    if {$sec eq ""} return
-
-    incr nto
-
-    set tot [expr {$tot + $sec}]
-    set avg [expr {$tot/$nto}]
-    set max [expr {$ntrunk * $avg}]
-    set rem [expr {$max - $tot}]
-
-    write 3 import "st avg [format %.2f $avg] sec"
-    write 3 import "st run [format %7.2f $tot] sec [format %6.2f [expr {$tot/60}]] min [format %5.2f [expr {$tot/3600}]] hr"
-    write 3 import "st end [format %7.2f $max] sec [format %6.2f [expr {$max/60}]] min [format %5.2f [expr {$max/3600}]] hr"
-    write 3 import "st rem [format %7.2f $rem] sec [format %6.2f [expr {$rem/60}]] min [format %5.2f [expr {$rem/3600}]] hr"
-    return
-}
-
-proc ::vc::fossil::import::cvs::OneChangeSet {cset} {
-    set usec [lindex [time {
+    set microseconds [lindex [time {
 	foreach {user message timestamp} [cvs::wssetup $cset] break
 	foreach {uuid ad rm ch} [fossil::commit $cset $user $timestamp $message] break
     } 1] 0]
-    cvs::uuid $cset $uuid
+    set seconds [expr {$microseconds/1e6}]
 
-    set sec [expr {$usec/1e6}]
-
+    cvs::uuid $cset $uuid
     write 2 import "== $uuid +${ad}-${rm}*${ch}"
-    write 2 import "st in  [format %.2f $sec] sec"
 
-    return $sec
+    stats::csend $seconds
+    return
 }
 
 # -----------------------------------------------------------------------------