Check-in [a766b08198]
Not logged in
Overview

SHA1 Hash:a766b08198e86c8aa0ca60c9b79e02af0afefacc
Date: 2007-10-23 03:29:36
User: aku
Comment:Reworked object deletion to happen centrally after the file has been processed (drop). Simplified the code restructuring the revision tree as it now doesn't have to think about when and where to remove objects.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified tools/cvs2fossil/lib/c2f_file.tcl from [1f4a6c30ea] to [78de4a9477].

@@ -67,10 +67,16 @@
 
     method persist {} {
     }
 
     method drop {} {
+	foreach {_ rev}    [array get myrev]      { $rev destroy }
+	foreach {_ branch} [array get mybranches] { $branch destroy }
+	foreach {_ taglist} [array get mytags] {
+	    foreach tag $taglist { $tag destroy }
+	}
+	return
     }
 
     # # ## ### ##### ######## #############
     ## Implement the sink
 
@@ -577,10 +583,20 @@
 	} else {
 	    return {}
 	}
     }
 
+    # General note: In the following methods we only modify the links
+    # between revisions and symbols to restructure the revision
+    # tree. We do __not__ destroy the objects. Given the complex links
+    # GC is difficult at this level. It is much easier to drop
+    # everything when we we are done. This happens in 'drop', using
+    # the state variable 'myrev', 'mybranches', and 'mytags'. What we
+    # have to persist, performed by 'persist', we know will be
+    # reachable through the revisions listed in 'myroots' and their
+    # children and symbols.
+
     method AdjustNonTrunkDefaultBranch {revlist} {
 	set stop [$myroot child] ;# rev '1.2'
 
 	log write 5 file "Adjusting NTDB containing [nsp [llength $revlist] revision]"
 
@@ -640,11 +656,10 @@
 	    log write 3 file "Removing irrelevant revision [$rev11 revnr]"
 
 	    # Cut out the old myroot revision.
 
 	    ldelete myroots $rev11 ; # Not a root any longer.
-	    unset myrev([$rev11 revnr])
 
 	    $first cutfromparent ; # Sever revision from parent revision.
 	    if {$stop ne ""} {
 		$stop cutfromparent
 		lappend myroots $stop ; # New root, after vendor branch
@@ -653,11 +668,10 @@
 	    # Cut out the vendor branch symbol
 
 	    set vendor [$first parentbranch]
 	    if {$vendor eq ""} { trouble internal "First NTDB revision has no branch" }
 	    if {[$vendor parent] eq $rev11} {
-		unset mybranches([$vendor branchnr])
 		$rev11 removebranch        $vendor
 		$rev11 removechildonbranch $first
 		$first cutfromparentbranch
 		lappend myroots $first
 	    }
@@ -665,11 +679,10 @@
 	    # Change the type of first (typically from Change to Add):
 	    $first retype add
 
 	    # Move any tags and branches from the old to the new root.
 	    $rev11 movesymbolsto $first
-	    $rev11 destroy
 	}
 
 	# Mark all the special revisions as such
 	foreach rev $revlist {
 	    log write 3 file "Revision on default branch: [$rev revnr]"
@@ -764,19 +777,15 @@
 	    set branch [$root parentbranch]
 	    set parent [$root parent]
 	    set child  [$root child]
 
 	    ldelete myroots $root
-	    unset myrev([$root revnr])
-	    $child cutfromparent
 	    lappend myroots $child
 
-	    $parent removechildonbranch $root
+	    $child  cutfromparent
 	    $parent removebranch        $branch
-
-	    $branch destroy
-	    $root   destroy
+	    $parent removechildonbranch $root
 	}
 	return
     }
 
     method LinesOfDevelopment {} {
@@ -847,12 +856,13 @@
 	    upvar 1 $nv ntdbroot
 	    set ntdbroot $root
 
 	    set rev [$root child]
 	    while {$rev ne ""} {
-		# See note [x].
 		$rev removeallbranches
+		# See note [x].
+
 		if {[$rev isondefaultbranch]} {
 		    set rev [$rev child]
 		} else {
 		    set rev ""
 		}
@@ -864,20 +874,17 @@
 
 	    if {$rev ne ""}  {
 		set lastntdb [$rev parent]
 		$lastntdb cutfromchild
 		while {$rev ne ""} {
-		    set next [$rev child]
-		    unset myrev([$rev revnr])
 		    $rev removealltags
+		    $rev removeallbranches
 		    # Note [x]: We may still have had branches on the
 		    # revision. Branches without revisions committed
 		    # on them do not show up in the list of roots aka
-		    # lines of development).
-		    $root removeallbranches
-		    $rev destroy
-		    set rev $next
+		    # lines of development.
+		    set rev [$rev child]
 		}
 	    }
 	    return
 	}
 
@@ -884,27 +891,24 @@
 	# No NTDB stuff to deal with. First delete the branch object
 	# itself, after cutting all the various connections.
 
 	set branch [$root parentbranch]
 	if {$branch ne ""} {
-	    set bparentrev [$branch parent]
-	    $bparentrev removebranch        $branch
-	    $bparentrev removechildonbranch $root
-	    $branch destroy
+	    set branchparent [$branch parent]
+	    $branchparent removebranch        $branch
+	    $branchparent removechildonbranch $root
 	}
 
 	# The root is no such any longer either.
 	ldelete myroots $root
 
 	# Now go through the line and remove all its revisions.
 
 	while {$root ne ""} {
-	    set next [$root child]
-	    unset myrev([$root revnr])
 	    $root removealltags
-	    # Note: See the note [x].
 	    $root removeallbranches
+	    # Note: See the note [x].
 
 	    # From cvs2svn: If this is the last default revision on a
 	    # non-trunk default branch followed by a 1.2 revision,
 	    # then the 1.2 revision depends on this one.  FIXME: It is
 	    # questionable whether this handling is correct, since the
@@ -921,12 +925,11 @@
 		if {[$ntdbchild hasparent]} {
 		    lappend myroots [$ntdbchild parent]
 		}
 	    }
 
-	    $root destroy
-	    set root $next
+	    set root [$root child]
 	}
 
 	return
     }
 

Modified tools/cvs2fossil/lib/c2f_frev.tcl from [383bf3739a] to [2e41dc7df6].

@@ -211,13 +211,10 @@
 	set mybranchchildren {}
 	return
     }
 
     method removeallbranches {} {
-	foreach branch $mybranches {
-	    $branch destroy
-	}
 	set mybranches       {}
 	set mybranchchildren {}
 	return
     }
 
@@ -229,11 +226,10 @@
     }
 
     method tags {} { return $mytags }
 
     method removealltags {} {
-	foreach tag $mytags { $tag destroy }
 	set mytags {}
 	return
     }
 
     method movetagsto {rev} {