Diff
Not logged in

Differences From:

File tools/lib/rcsparser.tcl part of check-in [d4aa7da67d] - Continuing namespace changes, rcs parser. Basic structure is now ok IMHO. by aku on 2007-09-13 06:24:31. [view]

To:

File tools/lib/rcsparser.tcl part of check-in [3852590ce6] - New feature for importer. rcs parser extended so that it can store parse results for quick loading in future runs. This feature has no real use in regular use of the importer, i.e. one-shot conversion of a CVS repository to fossil. It is however useful for debugging when the source repository is scanned many times during test runs. Especially for large files, with lots of changes (like ChangeLogs), the direct loading of a Tcl dictionary is much faster than actually parsing the archive files. by aku on 2007-09-26 05:02:06. [view]

@@ -16,9 +16,9 @@
 package require vc::tools::log ; # User feedback
 
 namespace eval ::vc::rcs::parser {
     vc::tools::log::system rcs
-    namespace import ::vc::tools::log::progress
+    namespace import ::vc::tools::log::*
 }
 
 # -----------------------------------------------------------------------------
 # API
@@ -46,9 +46,44 @@
 
 # -----------------------------------------------------------------------------
 # API Implementation
 
+proc ::vc::rcs::parser::configure {key value} {
+    variable cache
+    switch -exact -- $key {
+	-cache  {
+	    set cache $value
+	}
+	default {
+	    return -code error "Unknown switch $key, expected one of -cache"
+	}
+    }
+    return
+}
+
 proc ::vc::rcs::parser::process {path} {
+    set cache [Cache $path]
+    if {
+	[file exists $cache] &&
+	([file mtime $cache] > [file mtime $path])
+    } {
+	# Use preparsed data if not invalidated by changes to the
+	# archive they are derived from.
+	write 4 rcs {Load preparsed data block}
+	return [fileutil::cat -encoding binary $cache]
+    }
+
+    set res [Process $path]
+
+    # Save parse result for quick pickup by future runs.
+    fileutil::writeFile $cache $res
+
+    return $res
+}
+
+# -----------------------------------------------------------------------------
+
+proc ::vc::rcs::parser::Process {path} {
     set data [fileutil::cat -encoding binary $path]
     array set res {}
     set res(size) [file size $path]
     set res(done) 0
@@ -66,8 +101,12 @@
     unset res(nsize)
     unset res(done)
 
     return [array get res]
+}
+
+proc ::vc::rcs::parser::Cache {path} {
+    return ${path},,preparsed
 }
 
 # -----------------------------------------------------------------------------
 # Internal - Recursive Descent functions implementing the syntax.
@@ -317,13 +356,17 @@
     progress 2 rcs $res(done) $res(size)
     return
 }
 
+# -----------------------------------------------------------------------------
+
 namespace eval ::vc::rcs::parser {
-    namespace export process
+    variable cache 0 ; # No result caching by default.
+
+    namespace export process configure
 }
 
 # -----------------------------------------------------------------------------
 # Ready
 
 package provide vc::rcs::parser 1.0
 return