Differences From:
File
tools/cvs2fossil/lib/c2f_file.tcl
part of check-in
[e94b52b6f2]
- Restructured the code handling NTBD in ExcludeBranch a bit to prevent the asserts in GraftNTDB2Trunk to bail out.
by
aku on
2007-10-23 04:36:31.
[view]
To:
File
tools/cvs2fossil/lib/c2f_file.tcl
part of check-in
[adf168e23e]
- Extended handling of id's for files so that we have them for backreferences from symbols and revisions. Completed persistence of revisions and symbols at file-level and fixed small problem with left-over links to branches.
by
aku on
2007-10-24 08:01:01.
[view]
@@ -20,8 +20,9 @@
package require snit ; # OO system.
package require struct::set ; # Set operations.
package require vc::fossil::import::cvs::file::rev ; # CVS per file revisions.
package require vc::fossil::import::cvs::file::sym ; # CVS per file symbols.
+package require vc::fossil::import::cvs::state ; # State storage.
package require vc::tools::trouble ; # Error reporting.
package require vc::tools::log ; # User feedback
package require vc::tools::misc ; # Text formatting
@@ -31,9 +32,10 @@
snit::type ::vc::fossil::import::cvs::file {
# # ## ### ##### ######## #############
## Public API
- constructor {path usrpath executable project} {
+ constructor {id path usrpath executable project} {
+ set myid $id
set mypath $path
set myusrpath $usrpath
set myexecutable $executable
set myproject $project
@@ -40,8 +42,15 @@
set mytrunk [$myproject trunk]
return
}
+ method setid {id} {
+ if {$myid ne ""} { trouble internal "File '$mypath' already has an id, '$myid'" }
+ set myid $id
+ return
+ }
+
+ method id {} { return $myid }
method path {} { return $mypath }
method usrpath {} { return $myusrpath }
method project {} { return $myproject }
@@ -65,8 +74,28 @@
# # ## ### ##### ######## #############
## Persistence (pass II)
method persist {} {
+ # First collect the reachable revisions and symbols, then
+ # assign id's to all. They are sorted so that we will have ids
+ # which sort in order of creation. Then we can save them. This
+ # is done bottom up. Revisions, then symbols. __NOTE__ This
+ # works only because sqlite is not checking foreign key
+ # references during insert. This allows to have dangling
+ # references which are fixed later. The longest dangling
+ # references are for the project level symbols, these we do
+ # not save here, but at the end of the pass. What we need are
+ # the ids, hence the two phases.
+
+ struct::list assign [$self Active] revisions symbols
+ foreach rev $revisions { $rev defid }
+ foreach sym $symbols { $sym defid }
+
+ state transaction {
+ foreach rev $revisions { $rev persist }
+ foreach sym $symbols { $sym persist }
+ }
+ return
}
method drop {} {
foreach {_ rev} [array get myrev] { $rev destroy }
@@ -221,8 +250,9 @@
# # ## ### ##### ######## #############
## State
+ variable myid {} ; # File id in the persistent state.
variable mypath {} ; # Path of the file's rcs archive.
variable myusrpath {} ; # Path of the file as seen by users.
variable myexecutable 0 ; # Boolean flag 'file executable'.
variable myproject {} ; # Reference to the project object
@@ -309,16 +339,16 @@
log write 1 file "In '$mypath': Branch '$branchnr' named '[$mybranches($branchnr) name]'"
log write 1 file "Cannot have second name '$name', ignoring it"
return
}
- set branch [sym %AUTO% branch $branchnr [$myproject getsymbol $name]]
+ set branch [sym %AUTO% branch $branchnr [$myproject getsymbol $name] $self]
$branch setposition [incr mybranchcnt]
set mybranches($branchnr) $branch
return $branch
}
method AddTag {name revnr} {
- set tag [sym %AUTO% tag $revnr [$myproject getsymbol $name]]
+ set tag [sym %AUTO% tag $revnr [$myproject getsymbol $name] $self]
lappend mytags($revnr) $tag
return $tag
}
@@ -379,9 +409,9 @@
# reference to the branch there, and further declare
# the first child's parent to be branch's parent, and
# list this child in the parent revision.
- if {[$branch haschild]} {
+ if {[$branch haschildrev]} {
set childrevnr [$branch childrevnr]
set child $myrev($childrevnr)
$branch setchild $child
@@ -671,8 +701,9 @@
if {$vendor eq ""} { trouble internal "First NTDB revision has no branch" }
if {[$vendor parent] eq $rev11} {
$rev11 removebranch $vendor
$rev11 removechildonbranch $first
+ $vendor cutchild
$first cutfromparentbranch
lappend myroots $first
}
@@ -727,9 +758,9 @@
$child cutfromparent
lappend myroots $child
}
- # Remove the branches spawned by the revision to be
+ # Cut out the branches spawned by the revision to be
# deleted. If the branch has revisions they should already
# use operation 'add', no need to change that. The first
# revision on each branch becomes a new and disconnected
# root.
@@ -738,8 +769,9 @@
if {![$branch haschild]} continue
set first [$branch child]
$first cutfromparentbranch
$first cutfromparent
+ $branch cutchild
lappend myroots $first
}
$root removeallbranches
@@ -780,9 +812,11 @@
ldelete myroots $root
lappend myroots $child
+ $branch cutchild
$child cutfromparent
+
$parent removebranch $branch
$parent removechildonbranch $root
}
return
@@ -972,8 +1006,27 @@
return
}
+ method Active {} {
+ set revisions {}
+ set symbols {}
+
+ foreach root [$self LinesOfDevelopment] {
+ if {[$root hasparentbranch]} { lappend symbols [$root parentbranch] }
+ while {$root ne ""} {
+ lappend revisions $root
+ foreach tag [$root tags] { lappend symbols $tag }
+ foreach branch [$root branches] { lappend symbols $branch }
+ set lod [$root lod]
+ if {![$lod istrunk]} { lappend symbols $lod }
+ set root [$root child]
+ }
+ }
+
+ return [list [lsort -unique -dict $revisions] [lsort -unique -dict $symbols]]
+ }
+
# # ## ### ##### ######## #############
## Configuration
pragma -hastypeinfo no ; # no type introspection
@@ -991,8 +1044,9 @@
# namespace import ::vc::fossil::import::cvs::file::sym
namespace import ::vc::tools::misc::*
namespace import ::vc::tools::trouble
namespace import ::vc::tools::log
+ namespace import ::vc::fossil::import::cvs::state
}
}
# # ## ### ##### ######## ############# #####################