Overview
SHA1 Hash: | 99e165d5c40732458560dfc0522b4c301621b0ca |
---|---|
Date: | 2007-10-21 04:42:14 |
User: | aku |
Comment: | Created a separate common class for the id databases used by the repository, and updated the repository code to use it. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified tools/cvs2fossil/lib/c2f_repository.tcl from [ac4b426bcc] to [2bc22e9971].
@@ -20,10 +20,11 @@ package require Tcl 8.4 ; # Required runtime. package require snit ; # OO system. package require vc::tools::trouble ; # Error reporting. package require vc::tools::log ; # User feedback. package require vc::tools::misc ; # Text formatting. +package require vc::tools::id ; # Indexing and id generation. package require vc::fossil::import::cvs::project ; # CVS projects. package require vc::fossil::import::cvs::state ; # State storage. package require struct::list ; # List operations. package require fileutil ; # File operations. @@ -73,49 +74,18 @@ } } return } - typemethod defauthor {a} { - if {![info exists myauthor($a)]} { - set myauthor($a) [incr myauthorcnt] - log write 7 repository "author '$a' = $myauthor($a)" - } - return $myauthor($a) - } - - typemethod defcmessage {cm} { - if {![info exists mycmsg($cm)]} { - set mycmsg($cm) [set cid [incr mycmsgcnt]] - set mycmsginv($cid) $cm - log write 7 repository "cmessage '$cm' = $cid" - } - return $mycmsg($cm) - } - - typemethod defsymbol {pid name} { - set key [list $pid $name] - if {![info exists mysymbol($key)]} { - set mysymbol($key) [incr mysymbolcnt] - log write 7 repository "symbol ($key) = $mysymbol($key)" - } - return $mysymbol($key) - } - - typemethod defmeta {pid bid aid cid} { - set key [list $pid $bid $aid $cid] - if {![info exists mymeta($key)]} { - set mymeta($key) [set mid [incr mymetacnt]] - set mymetainv($mid) $key - log write 7 repository "meta ($key) = $mymeta($key)" - } - return $mymeta($key) - } - - typemethod commitmessageof {metaid} { - struct::list assign $mymetainv($metaid) pid bid aid cid - return $mycmsginv($cid) + typemethod defauthor {a} { $myauthor put $a } + typemethod defcmessage {cm} { $mycmsg put $cm } + typemethod defsymbol {pid name} { $mysymbol put [list $pid $name] } + typemethod defmeta {pid bid aid cid} { $mymeta put [list $pid $bid $aid $cid] } + + typemethod commitmessageof {mid} { + struct::list assign [$mymeta keyof $mid] pid bid aid cid + return [$mycmsg keyof $cid] } # pass I results typemethod printstatistics {} { set prlist [TheProjects] @@ -215,33 +185,35 @@ typevariable mybase {} ; # Base path to CVS repository. typevariable myprojpaths {} ; # List of paths to all declared # projects, relative to mybase. typevariable myprojects {} ; # List of objects for all # declared projects. - typevariable myauthor -array {} ; # Names of all authors found, + typevariable myauthor {} ; # Names of all authors found, # maps to their ids. - typevariable myauthorcnt 0 ; # Counter for author ids. - typevariable mycmsg -array {} ; # All commit messages found, + typevariable mycmsg {} ; # All commit messages found, # maps to their ids. - typevariable mycmsginv -array {} ; # Inverted index, keyed by id. - typevariable mycmsgcnt 0 ; # Counter for message ids. - typevariable mymeta -array {} ; # Maps all meta data tuples + typevariable mymeta {} ; # Maps all meta data tuples # (project, branch, author, # cmessage) to their ids. - typevariable mymetainv -array {} ; # Inverted index, keyed by id. - typevariable mymetacnt 0 ; # Counter for meta ids. - typevariable mysymbol -array {} ; # Map symbols identified by + typevariable mysymbol {} ; # Map symbols identified by # project and name to their # id. This information is not # saved directly. - typevariable mysymbolcnt 0 ; # Counter for symbol ids. typevariable mytrunkonly 0 ; # Boolean flag. Set by option # processing when the user # requested a trunk-only import # # ## ### ##### ######## ############# ## Internal methods + + typeconstructor { + set myauthor [vc::tools::id %AUTO%] + set mycmsg [vc::tools::id %AUTO%] + set mymeta [vc::tools::id %AUTO%] + set mysymbol [vc::tools::id %AUTO%] + return + } proc .BaseLength {p} { return [string length [$p printbase]] } @@ -352,10 +324,11 @@ namespace export repository namespace eval repository { namespace import ::vc::fossil::import::cvs::project namespace import ::vc::fossil::import::cvs::state namespace import ::vc::tools::misc::* + namespace import ::vc::tools::id namespace import ::vc::tools::trouble namespace import ::vc::tools::log log register repository } }
Added tools/cvs2fossil/lib/id.tcl version [43c9bdd480]
@@ -1,1 +1,57 @@ +# # ## ### ##### ######## ############# + +## A simple class for handling an in-memory index mapping from +## arbitrary strings to a small numeric id. Can be queried in reverse +## too, returning the string for the id. + +## Id's are starting from 1. + +# # ## ### ##### ######## ############# +## Requirements. + +package require Tcl ; # Runtime. +package require snit ; # OO runtime. + +# # ## ### ##### ######## ############# +## Implementation. + +snit::type ::vc::tools::id { + # # ## ### ##### ######## ############# + + constructor {} {} + + # # ## ### ##### ######## ############# + ## Public API. + ## - Put data into the index, incl. query for id of key. + ## - Lookup data for id. + + method put {key} { + if {[info exists mydata($key)]} { return $mydata($key) } + incr mycounter + + set mydata($key) $mycounter + set myinvert($mycounter) $key + + return $mycounter + } + + method keyof {id} { return $myinvert($id) } + + # # ## ### ##### ######## ############# + ## Internal. State. + + variable mydata -array {} ; # Map data -> id + variable myinvert -array {} ; # Map id -> data + variable mycounter 0 ; # Counter for id generation. + + # # ## ### ##### ######## ############# +} + +namespace eval ::vc::tools { + namespace export id +} + +# # ## ### ##### ######## ############# +## Ready. +package provide vc::tools::id 1.0
Modified tools/cvs2fossil/lib/pkgIndex.tcl from [4291c23aa8] to [94c8694e66].
@@ -22,6 +22,6 @@ package ifneeded vc::fossil::import::cvs::state 1.0 [list source [file join $dir c2f_state.tcl]] package ifneeded vc::rcs::parser 1.0 [list source [file join $dir rcsparser.tcl]] package ifneeded vc::tools::log 1.0 [list source [file join $dir log.tcl]] package ifneeded vc::tools::misc 1.0 [list source [file join $dir misc.tcl]] package ifneeded vc::tools::trouble 1.0 [list source [file join $dir trouble.tcl]] - +package ifneeded vc::tools::id 1.0 [list source [file join $dir id.tcl]]