File Annotation
Not logged in
11e5d7ce42 2007-11-06       aku: ## -*- tcl -*-
11e5d7ce42 2007-11-06       aku: # # ## ### ##### ######## ############# #####################
11e5d7ce42 2007-11-06       aku: ## Copyright (c) 2007 Andreas Kupries.
11e5d7ce42 2007-11-06       aku: #
11e5d7ce42 2007-11-06       aku: # This software is licensed as described in the file LICENSE, which
11e5d7ce42 2007-11-06       aku: # you should have received as part of this distribution.
11e5d7ce42 2007-11-06       aku: #
11e5d7ce42 2007-11-06       aku: # This software consists of voluntary contributions made by many
11e5d7ce42 2007-11-06       aku: # individuals.  For exact contribution history, see the revision
11e5d7ce42 2007-11-06       aku: # history and logs, available at http://fossil-scm.hwaci.com/fossil
11e5d7ce42 2007-11-06       aku: # # ## ### ##### ######## ############# #####################
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: ## Pass IV. Coming after the symbol collation pass this pass now
11e5d7ce42 2007-11-06       aku: ## removes all revisions and symbols referencing any of the excluded
11e5d7ce42 2007-11-06       aku: ## symbols from the persistent database.
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: # # ## ### ##### ######## ############# #####################
11e5d7ce42 2007-11-06       aku: ## Requirements
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: package require Tcl 8.4                               ; # Required runtime.
11e5d7ce42 2007-11-06       aku: package require snit                                  ; # OO system.
11e5d7ce42 2007-11-06       aku: package require vc::tools::log                        ; # User feedback.
11e5d7ce42 2007-11-06       aku: package require vc::fossil::import::cvs::state        ; # State storage.
69bf6ab99b 2007-11-06       aku: package require vc::fossil::import::cvs::project::sym ; # Project level symbols
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: # # ## ### ##### ######## ############# #####################
11e5d7ce42 2007-11-06       aku: ## Register the pass with the management
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: vc::fossil::import::cvs::pass define \
11e5d7ce42 2007-11-06       aku:     FilterSymbols \
11e5d7ce42 2007-11-06       aku:     {Filter symbols, remove all excluded pieces} \
11e5d7ce42 2007-11-06       aku:     ::vc::fossil::import::cvs::pass::filtersym
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: # # ## ### ##### ######## ############# #####################
11e5d7ce42 2007-11-06       aku: ##
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: snit::type ::vc::fossil::import::cvs::pass::filtersym {
11e5d7ce42 2007-11-06       aku:     # # ## ### ##### ######## #############
11e5d7ce42 2007-11-06       aku:     ## Public API
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     typemethod setup {} {
11e5d7ce42 2007-11-06       aku: 	# Define names and structure of the persistent state of this
11e5d7ce42 2007-11-06       aku: 	# pass.
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: 	state reading symbol
11e5d7ce42 2007-11-06       aku: 	state reading blocker
11e5d7ce42 2007-11-06       aku: 	state reading parent
11e5d7ce42 2007-11-06       aku: 	state reading preferedparent
11e5d7ce42 2007-11-06       aku: 	state reading revision
11e5d7ce42 2007-11-06       aku: 	state reading branch
11e5d7ce42 2007-11-06       aku: 	state reading tag
11e5d7ce42 2007-11-06       aku: 	return
11e5d7ce42 2007-11-06       aku:     }
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     typemethod load {} {
11e5d7ce42 2007-11-06       aku: 	# Pass manager interface. Executed to load data computed by
11e5d7ce42 2007-11-06       aku: 	# this pass into memory when this pass is skipped instead of
11e5d7ce42 2007-11-06       aku: 	# executed.
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: 	# The results of this pass are fully in the persistent state,
11e5d7ce42 2007-11-06       aku: 	# there is nothing to load for the next one.
11e5d7ce42 2007-11-06       aku: 	return
11e5d7ce42 2007-11-06       aku:     }
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     typemethod run {} {
11e5d7ce42 2007-11-06       aku: 	# Pass manager interface. Executed to perform the
11e5d7ce42 2007-11-06       aku: 	# functionality of the pass.
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: 	# The removal of excluded symbols and everything referencing
11e5d7ce42 2007-11-06       aku: 	# to them is done completely in the database.
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: 	state transaction {
11e5d7ce42 2007-11-06       aku: 	    FilterExcludedSymbols
ffafc0bd65 2007-11-06       aku: 	    MutateTagsToBranch
ffafc0bd65 2007-11-06       aku: 	    MutateBranchesToTag
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku: 	    # Consider a rerun of the pass 2 paranoia checks.
11e5d7ce42 2007-11-06       aku: 	}
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: 	log write 1 filtersym "Filtering completed"
11e5d7ce42 2007-11-06       aku: 	return
11e5d7ce42 2007-11-06       aku:     }
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     typemethod discard {} {
11e5d7ce42 2007-11-06       aku: 	# Pass manager interface. Executed for all passes after the
11e5d7ce42 2007-11-06       aku: 	# run passes, to remove all data of this pass from the state,
11e5d7ce42 2007-11-06       aku: 	# as being out of date.
11e5d7ce42 2007-11-06       aku: 	return
11e5d7ce42 2007-11-06       aku:     }
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     # # ## ### ##### ######## #############
11e5d7ce42 2007-11-06       aku:     ## Internal methods
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     proc FilterExcludedSymbols {} {
ffafc0bd65 2007-11-06       aku: 	log write 3 filtersym "Filter out excluded symbols and users"
ffafc0bd65 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	# We pull all the excluded symbols together into a table for
69bf6ab99b 2007-11-06       aku: 	# easy reference by the upcoming DELETE and other statements.
69bf6ab99b 2007-11-06       aku: 	# ('x IN table' clauses).
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	set excl [project::sym excluded]
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	state run {
69bf6ab99b 2007-11-06       aku: 	    CREATE TEMPORARY TABLE excludedsymbols AS
69bf6ab99b 2007-11-06       aku: 	    SELECT sid
69bf6ab99b 2007-11-06       aku: 	    FROM   symbol
69bf6ab99b 2007-11-06       aku: 	    WHERE  type = $excl
69bf6ab99b 2007-11-06       aku: 	}
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	# First we have to handle the possibility of an excluded
69bf6ab99b 2007-11-06       aku: 	# NTDB. This is a special special case there we have to
69bf6ab99b 2007-11-06       aku: 	# regraft the revisions which are shared between the NTDB and
69bf6ab99b 2007-11-06       aku: 	# Trunk onto the trunk, preventing their deletion later. We
69bf6ab99b 2007-11-06       aku: 	# have code for that in 'file', however that operated on the
69bf6ab99b 2007-11-06       aku: 	# in-memory revision objects, which we do not have here. We do
69bf6ab99b 2007-11-06       aku: 	# the same now without object, by directly manipulating the
69bf6ab99b 2007-11-06       aku: 	# links in the database.
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	array set ntdb {}
69bf6ab99b 2007-11-06       aku: 	array set link {}
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	foreach {id parent transfer} [state run {
69bf6ab99b 2007-11-06       aku: 	    SELECT R.rid, R.parent, R.dbchild
69bf6ab99b 2007-11-06       aku: 	    FROM  revision R, symbol S
69bf6ab99b 2007-11-06       aku: 	    WHERE R.lod = S.sid
69bf6ab99b 2007-11-06       aku: 	    AND   S.sid IN excludedsymbols
69bf6ab99b 2007-11-06       aku: 	    AND   R.isdefault
69bf6ab99b 2007-11-06       aku: 	}] {
69bf6ab99b 2007-11-06       aku: 	    set ntdb($id) $parent
69bf6ab99b 2007-11-06       aku: 	    if {$transfer eq ""} continue
69bf6ab99b 2007-11-06       aku: 	    set link($id) $transfer
69bf6ab99b 2007-11-06       aku: 	}
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	foreach joint [array names link] {
69bf6ab99b 2007-11-06       aku: 	    # The joints are the highest NTDB revisions which are
69bf6ab99b 2007-11-06       aku: 	    # shared with their respective trunk. We disconnect from
69bf6ab99b 2007-11-06       aku: 	    # their NTDB children, and make them parents of their
69bf6ab99b 2007-11-06       aku: 	    # 'dbchild'. The associated 'dbparent' is squashed
69bf6ab99b 2007-11-06       aku: 	    # instead. All parents of the joints are moved to the
69bf6ab99b 2007-11-06       aku: 	    # trunk as well.
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	    set tjoint $link($joint)
69bf6ab99b 2007-11-06       aku: 	    set tlod [lindex [state run {
69bf6ab99b 2007-11-06       aku: 		SELECT lod FROM revision WHERE rid = $tjoint
69bf6ab99b 2007-11-06       aku: 	    }] 0]
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	    # Covnert db/parent/child into regular parent/child links.
69bf6ab99b 2007-11-06       aku: 	    state run {
69bf6ab99b 2007-11-06       aku: 		UPDATE revision SET dbparent = NULL, parent = $joint  WHERE rid = $tjoint ;
69bf6ab99b 2007-11-06       aku: 		UPDATE revision SET dbchild  = NULL, child  = $tjoint WHERE rid = $joint  ;
69bf6ab99b 2007-11-06       aku: 	    }
69bf6ab99b 2007-11-06       aku: 	    while {1} {
69bf6ab99b 2007-11-06       aku: 		# Move the NTDB trunk revisions to trunk.
69bf6ab99b 2007-11-06       aku: 		state run {
69bf6ab99b 2007-11-06       aku: 		    UPDATE revision SET lod = $tlod, isdefault = 0 WHERE rid = $joint
69bf6ab99b 2007-11-06       aku: 		}
69bf6ab99b 2007-11-06       aku: 		set last $joint
69bf6ab99b 2007-11-06       aku: 		set joint $ntdb($joint)
69bf6ab99b 2007-11-06       aku: 		if {![info exists ntdb($joint)]} break
69bf6ab99b 2007-11-06       aku: 	    }
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	    # Reached the NTDB basis in the trunk. Finalize the
69bf6ab99b 2007-11-06       aku: 	    # parent/child linkage and squash the branch parent symbol
69bf6ab99b 2007-11-06       aku: 	    # reference.
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	    state run {
69bf6ab99b 2007-11-06       aku: 		UPDATE revision SET child   = $last WHERE rid = $joint ;
69bf6ab99b 2007-11-06       aku: 		UPDATE revision SET bparent = NULL  WHERE rid = $last  ;
69bf6ab99b 2007-11-06       aku: 	    }
69bf6ab99b 2007-11-06       aku: 	}
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	# Now that the special case is done we can simply kill all the
69bf6ab99b 2007-11-06       aku: 	# revisions, tags, and branches referencing any of the
69bf6ab99b 2007-11-06       aku: 	# excluded symbols in some way. This is easy as we do not have
69bf6ab99b 2007-11-06       aku: 	# to select them again and again from the base tables any
69bf6ab99b 2007-11-06       aku: 	# longer.
69bf6ab99b 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: 	state run {
69bf6ab99b 2007-11-06       aku: 	    DELETE FROM revision WHERE lod IN excludedsymbols;
69bf6ab99b 2007-11-06       aku: 	    DELETE FROM tag      WHERE lod IN excludedsymbols;
69bf6ab99b 2007-11-06       aku: 	    DELETE FROM tag      WHERE sid IN excludedsymbols;
69bf6ab99b 2007-11-06       aku: 	    DELETE FROM branch   WHERE lod IN excludedsymbols;
69bf6ab99b 2007-11-06       aku: 	    DELETE FROM branch   WHERE sid IN excludedsymbols;
69bf6ab99b 2007-11-06       aku: 
69bf6ab99b 2007-11-06       aku: 	    DROP TABLE excludedsymbols;
ffafc0bd65 2007-11-06       aku: 	}
ffafc0bd65 2007-11-06       aku: 	return
ffafc0bd65 2007-11-06       aku:     }
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku:     proc MutateTagsToBranch {} {
ffafc0bd65 2007-11-06       aku: 	log write 3 filtersym "Mutate tags to branches"
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku: 	# Next, now that we know which symbols are what we look for
ffafc0bd65 2007-11-06       aku: 	# file level tags which are actually converted as branches
ffafc0bd65 2007-11-06       aku: 	# (project level), and put them into the correct table.
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku: 	set branch [project::sym branch]
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku: 	set tagstomutate [state run {
ffafc0bd65 2007-11-06       aku: 	    SELECT T.tid, T.fid, T.lod, T.sid, T.rev
ffafc0bd65 2007-11-06       aku: 	    FROM tag T, symbol S
ffafc0bd65 2007-11-06       aku: 	    WHERE T.sid = S.sid
ffafc0bd65 2007-11-06       aku: 	    AND S.type = $branch
ffafc0bd65 2007-11-06       aku: 	}]
ffafc0bd65 2007-11-06       aku: 	foreach {id fid lod sid rev} $tagstomutate {
ffafc0bd65 2007-11-06       aku: 	    state run {
ffafc0bd65 2007-11-06       aku: 		DELETE FROM tag WHERE tid = $id ;
ffafc0bd65 2007-11-06       aku: 		INSERT INTO branch (bid, fid,  lod,  sid,  root, first, bra)
ffafc0bd65 2007-11-06       aku: 		VALUES             ($id, $fid, $lod, $sid, $rev, NULL,  '');
ffafc0bd65 2007-11-06       aku: 	    }
ffafc0bd65 2007-11-06       aku: 	}
ffafc0bd65 2007-11-06       aku: 	return
ffafc0bd65 2007-11-06       aku:     }
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku:     proc MutateBranchesToTag {} {
ffafc0bd65 2007-11-06       aku: 	log write 3 filtersym "Mutate branches to tags"
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku: 	# Next, now that we know which symbols are what we look for
ffafc0bd65 2007-11-06       aku: 	# file level branches which are actually converted as tags
ffafc0bd65 2007-11-06       aku: 	# (project level), and put them into the correct table.
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku: 	set tag [project::sym tag]
ffafc0bd65 2007-11-06       aku: 
ffafc0bd65 2007-11-06       aku: 	set branchestomutate [state run {
ffafc0bd65 2007-11-06       aku: 	    SELECT B.bid, B.fid, B.lod, B.sid, B.root, B.first, B.bra
ffafc0bd65 2007-11-06       aku: 	    FROM branch B, symbol S
ffafc0bd65 2007-11-06       aku: 	    WHERE B.sid = S.sid
ffafc0bd65 2007-11-06       aku: 	    AND S.type = $tag
ffafc0bd65 2007-11-06       aku: 	}]
ffafc0bd65 2007-11-06       aku: 	foreach {id fid lod sid root first bra} $branchestomutate {
ffafc0bd65 2007-11-06       aku: 	    state run {
ffafc0bd65 2007-11-06       aku: 		DELETE FROM branch WHERE bid = $id ;
ffafc0bd65 2007-11-06       aku: 		INSERT INTO tag (tid, fid,  lod,  sid,  rev)
ffafc0bd65 2007-11-06       aku: 		VALUES          ($id, $fid, $lod, $sid, $root);
ffafc0bd65 2007-11-06       aku: 	    }
11e5d7ce42 2007-11-06       aku: 	}
11e5d7ce42 2007-11-06       aku: 	return
11e5d7ce42 2007-11-06       aku:     }
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     # # ## ### ##### ######## #############
11e5d7ce42 2007-11-06       aku:     ## Configuration
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     pragma -hasinstances   no ; # singleton
11e5d7ce42 2007-11-06       aku:     pragma -hastypeinfo    no ; # no introspection
11e5d7ce42 2007-11-06       aku:     pragma -hastypedestroy no ; # immortal
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku:     # # ## ### ##### ######## #############
11e5d7ce42 2007-11-06       aku: }
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: namespace eval ::vc::fossil::import::cvs::pass {
11e5d7ce42 2007-11-06       aku:     namespace export filtersym
11e5d7ce42 2007-11-06       aku:     namespace eval filtersym {
11e5d7ce42 2007-11-06       aku: 	namespace import ::vc::fossil::import::cvs::state
69bf6ab99b 2007-11-06       aku: 	namespace eval project {
69bf6ab99b 2007-11-06       aku: 	    namespace import ::vc::fossil::import::cvs::project::sym
69bf6ab99b 2007-11-06       aku: 	}
11e5d7ce42 2007-11-06       aku: 	namespace import ::vc::tools::log
11e5d7ce42 2007-11-06       aku: 	log register filtersym
11e5d7ce42 2007-11-06       aku:     }
11e5d7ce42 2007-11-06       aku: }
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: # # ## ### ##### ######## ############# #####################
11e5d7ce42 2007-11-06       aku: ## Ready
11e5d7ce42 2007-11-06       aku: 
11e5d7ce42 2007-11-06       aku: package provide vc::fossil::import::cvs::pass::filtersym 1.0
11e5d7ce42 2007-11-06       aku: return