File Annotation
Not logged in
6d4eb24738 2007-11-02       aku: ## -*- tcl -*-
6d4eb24738 2007-11-02       aku: # # ## ### ##### ######## ############# #####################
6d4eb24738 2007-11-02       aku: ## Copyright (c) 2007 Andreas Kupries.
6d4eb24738 2007-11-02       aku: #
6d4eb24738 2007-11-02       aku: # This software is licensed as described in the file LICENSE, which
6d4eb24738 2007-11-02       aku: # you should have received as part of this distribution.
6d4eb24738 2007-11-02       aku: #
6d4eb24738 2007-11-02       aku: # This software consists of voluntary contributions made by many
6d4eb24738 2007-11-02       aku: # individuals.  For exact contribution history, see the revision
6d4eb24738 2007-11-02       aku: # history and logs, available at http://fossil-scm.hwaci.com/fossil
6d4eb24738 2007-11-02       aku: # # ## ### ##### ######## ############# #####################
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: ## Pass III. This pass divides the symbols collected by the previous
7eaa420a23 2007-11-05       aku: ## pass into branches, tags, and excludes. The latter are also
7eaa420a23 2007-11-05       aku: ## partially deleted by this pass, not only marked. It is the next
7eaa420a23 2007-11-05       aku: ## pass however, 'FilterSym', which performs the full deletion.
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: # # ## ### ##### ######## ############# #####################
6d4eb24738 2007-11-02       aku: ## Requirements
6d4eb24738 2007-11-02       aku: 
f888f06fe3 2007-11-02       aku: package require Tcl 8.4                               ; # Required runtime.
f888f06fe3 2007-11-02       aku: package require snit                                  ; # OO system.
7eaa420a23 2007-11-05       aku: package require vc::tools::trouble                    ; # Error reporting.
7eaa420a23 2007-11-05       aku: package require vc::tools::log                        ; # User feedback.
f888f06fe3 2007-11-02       aku: package require vc::fossil::import::cvs::repository   ; # Repository management.
f888f06fe3 2007-11-02       aku: package require vc::fossil::import::cvs::state        ; # State storage.
f888f06fe3 2007-11-02       aku: package require vc::fossil::import::cvs::project::sym ; # Project level symbols
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: # # ## ### ##### ######## ############# #####################
6d4eb24738 2007-11-02       aku: ## Register the pass with the management
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: vc::fossil::import::cvs::pass define \
6d4eb24738 2007-11-02       aku:     CollateSymbols \
6d4eb24738 2007-11-02       aku:     {Collate symbols} \
6d4eb24738 2007-11-02       aku:     ::vc::fossil::import::cvs::pass::collsym
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: # # ## ### ##### ######## ############# #####################
6d4eb24738 2007-11-02       aku: ##
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: snit::type ::vc::fossil::import::cvs::pass::collsym {
6d4eb24738 2007-11-02       aku:     # # ## ### ##### ######## #############
6d4eb24738 2007-11-02       aku:     ## Public API
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     typemethod setup {} {
6d4eb24738 2007-11-02       aku: 	# Define names and structure of the persistent state of this
6d4eb24738 2007-11-02       aku: 	# pass.
6d4eb24738 2007-11-02       aku: 
e288af3995 2007-12-02       aku: 	state use project
e288af3995 2007-12-02       aku: 	state use symbol
e288af3995 2007-12-02       aku: 	state use symtype
e288af3995 2007-12-02       aku: 	state use blocker
e288af3995 2007-12-02       aku: 	state use parent
e288af3995 2007-12-02       aku: 
e288af3995 2007-12-02       aku: 	state extend preferedparent {
efc78b7a42 2007-11-06       aku: 	    -- For each symbol the prefered parent. This describes the
efc78b7a42 2007-11-06       aku: 	    -- tree of the found lines of development. Actually a
efc78b7a42 2007-11-06       aku: 	    -- forest in case of multiple projects, with one tree per
efc78b7a42 2007-11-06       aku: 	    -- project.
efc78b7a42 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku: 	    sid INTEGER  NOT NULL  PRIMARY KEY  REFERENCES symbol,
efc78b7a42 2007-11-06       aku: 	    pid INTEGER  NOT NULL               REFERENCES symbol
74854a30b8 2007-12-02       aku: 	} { pid }
f7fe15cd0c 2007-12-08       aku: 	# Index on: pid (branch successors)
6d4eb24738 2007-11-02       aku: 	return
6d4eb24738 2007-11-02       aku:     }
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     typemethod load {} {
4c8a5a44af 2007-11-06       aku: 	# Pass manager interface. Executed to load data computed by
4c8a5a44af 2007-11-06       aku: 	# this pass into memory when this pass is skipped instead of
4c8a5a44af 2007-11-06       aku: 	# executed.
4c8a5a44af 2007-11-06       aku: 
4c8a5a44af 2007-11-06       aku: 	# The results of this pass are fully in the persistent state,
d314894b9a 2007-11-06       aku: 	# there is nothing to load for the next one.
6d4eb24738 2007-11-02       aku: 	return
6d4eb24738 2007-11-02       aku:     }
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     typemethod run {} {
6d4eb24738 2007-11-02       aku: 	# Pass manager interface. Executed to perform the
6d4eb24738 2007-11-02       aku: 	# functionality of the pass.
f888f06fe3 2007-11-02       aku: 
f888f06fe3 2007-11-02       aku: 	state transaction {
f888f06fe3 2007-11-02       aku: 	    repository   determinesymboltypes
f888f06fe3 2007-11-02       aku: 
f888f06fe3 2007-11-02       aku: 	    project::sym printrulestatistics
f888f06fe3 2007-11-02       aku: 	    project::sym printtypestatistics
f888f06fe3 2007-11-02       aku: 	}
f888f06fe3 2007-11-02       aku: 
7eaa420a23 2007-11-05       aku: 	if {![trouble ?]} {
7eaa420a23 2007-11-05       aku: 	    UnconvertedSymbols
7eaa420a23 2007-11-05       aku: 	    BadSymbolTypes
7eaa420a23 2007-11-05       aku: 	    BlockedExcludes
7eaa420a23 2007-11-05       aku: 	    InvalidTags
7eaa420a23 2007-11-05       aku: 	}
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku: 	if {![trouble ?]} {
7eaa420a23 2007-11-05       aku: 	    DropExcludedSymbolsFromReferences
efc78b7a42 2007-11-06       aku: 	    DeterminePreferedParents
7eaa420a23 2007-11-05       aku: 	}
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: 	log write 1 collsym "Collation completed"
6d4eb24738 2007-11-02       aku: 	return
6d4eb24738 2007-11-02       aku:     }
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     typemethod discard {} {
6d4eb24738 2007-11-02       aku: 	# Pass manager interface. Executed for all passes after the
6d4eb24738 2007-11-02       aku: 	# run passes, to remove all data of this pass from the state,
6d4eb24738 2007-11-02       aku: 	# as being out of date.
6d4eb24738 2007-11-02       aku: 
efc78b7a42 2007-11-06       aku: 	state discard preferedparent
6d4eb24738 2007-11-02       aku: 	return
6d4eb24738 2007-11-02       aku:     }
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     # # ## ### ##### ######## #############
6d4eb24738 2007-11-02       aku:     ## Internal methods
6d4eb24738 2007-11-02       aku: 
f7fe15cd0c 2007-12-08       aku:     ## TODO: Move UnconvertedSymbols, BadSymbolTypes, BlockedIncludes,
f637d42206 2008-02-24       aku:     ## TODO: InvalidTags to the integrity module?
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku:     proc UnconvertedSymbols {} {
7eaa420a23 2007-11-05       aku: 	# Paranoia - Have we left symbols without conversion
7eaa420a23 2007-11-05       aku: 	# information (i.e. with type 'undefined') ?
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku: 	set undef [project::sym undef]
7eaa420a23 2007-11-05       aku: 
f637d42206 2008-02-24       aku: 	state foreachrow {
f637d42206 2008-02-24       aku: 	    SELECT P.name AS pname, S.name AS sname
f7fe15cd0c 2007-12-08       aku: 	    FROM   symbol S, project P
f7fe15cd0c 2007-12-08       aku: 	    WHERE  S.type = $undef  -- Restrict to undefined symbols
f7fe15cd0c 2007-12-08       aku: 	    AND    P.pid = S.pid    -- Get project for symbol
f637d42206 2008-02-24       aku: 	} {
7eaa420a23 2007-11-05       aku: 	    trouble fatal "$pname : The symbol '$sname' was left undefined"
7eaa420a23 2007-11-05       aku: 	}
7eaa420a23 2007-11-05       aku: 	return
7eaa420a23 2007-11-05       aku:     }
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku:     proc BadSymbolTypes {} {
7eaa420a23 2007-11-05       aku: 	# Paranoia - Have we left symbols with bogus conversion
7eaa420a23 2007-11-05       aku: 	# information (type out of the valid range (excluded, branch,
7eaa420a23 2007-11-05       aku: 	# tag)) ?
7eaa420a23 2007-11-05       aku: 
f637d42206 2008-02-24       aku: 	state foreachrow {
f637d42206 2008-02-24       aku: 	    SELECT P.name AS pname, S.name AS sname
f7fe15cd0c 2007-12-08       aku: 	    FROM   symbol S, project P
f7fe15cd0c 2007-12-08       aku: 	    WHERE  S.type NOT IN (0,1,2) -- Restrict to symbols with bogus type codes
f7fe15cd0c 2007-12-08       aku: 	    AND    P.pid = S.pid         -- Get project of symbol
f637d42206 2008-02-24       aku: 	} {
7eaa420a23 2007-11-05       aku: 	    trouble fatal "$pname : The symbol '$sname' has no proper conversion type"
7eaa420a23 2007-11-05       aku: 	}
7eaa420a23 2007-11-05       aku: 	return
7eaa420a23 2007-11-05       aku:     }
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku:     proc BlockedExcludes {} {
7eaa420a23 2007-11-05       aku: 	# Paranoia - Have we scheduled symbols for exclusion without
7eaa420a23 2007-11-05       aku: 	# also excluding their dependent symbols ?
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku: 	set excl [project::sym excluded]
7eaa420a23 2007-11-05       aku: 
f637d42206 2008-02-24       aku: 	state foreachrow {
f637d42206 2008-02-24       aku: 	    SELECT P.name AS pname, S.name AS sname, SB.name AS bname
f7fe15cd0c 2007-12-08       aku: 	    FROM   symbol S, blocker B, symbol SB, project P
f7fe15cd0c 2007-12-08       aku: 	    WHERE  S.type = $excl   -- Restrict to excluded symbols
f7fe15cd0c 2007-12-08       aku: 	    AND    S.sid = B.sid    -- Get symbols blocking them
f7fe15cd0c 2007-12-08       aku: 	    AND    B.bid = SB.sid   -- and
f7fe15cd0c 2007-12-08       aku: 	    AND    SB.type != $excl -- which are not excluded themselves
f7fe15cd0c 2007-12-08       aku: 	    AND    P.pid = S.pid    -- Get project of symbol
f637d42206 2008-02-24       aku: 	} {
7eaa420a23 2007-11-05       aku: 	    trouble fatal "$pname : The symbol '$sname' cannot be excluded as the unexcluded symbol '$bname' depends on it."
7eaa420a23 2007-11-05       aku: 	}
7eaa420a23 2007-11-05       aku: 	return
7eaa420a23 2007-11-05       aku:     }
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku:     proc InvalidTags {} {
7eaa420a23 2007-11-05       aku: 	# Paranoia - Have we scheduled symbols for conversion as tags
7eaa420a23 2007-11-05       aku: 	# which absolutely cannot be converted as tags due to commits
7eaa420a23 2007-11-05       aku: 	# made on them ?
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku: 	# In other words, this checks finds out if the user has asked
7eaa420a23 2007-11-05       aku: 	# nonsensical conversions of symbols, which should have been
7eaa420a23 2007-11-05       aku: 	# left to the heuristics, most specifically
7eaa420a23 2007-11-05       aku: 	# 'project::sym.HasCommits()'.
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku: 	set tag [project::sym tag]
7eaa420a23 2007-11-05       aku: 
f637d42206 2008-02-24       aku: 	state foreachrow {
f637d42206 2008-02-24       aku: 	    SELECT P.name AS pname, S.name AS sname
7eaa420a23 2007-11-05       aku: 	    FROM   project P, symbol S
f7fe15cd0c 2007-12-08       aku: 	    WHERE  S.type = $tag        -- Restrict to tag symbols
f7fe15cd0c 2007-12-08       aku: 	    AND    S.commit_count > 0   -- which have revisions committed to them
f7fe15cd0c 2007-12-08       aku: 	    AND    P.pid = S.pid        -- Get project of symbol
f637d42206 2008-02-24       aku: 	} {
7eaa420a23 2007-11-05       aku: 	    trouble fatal "$pname : The symbol '$sname' cannot be forced to be converted as tag because it has commits."
7eaa420a23 2007-11-05       aku: 	}
7eaa420a23 2007-11-05       aku: 	return
7eaa420a23 2007-11-05       aku:     }
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku:     proc DropExcludedSymbolsFromReferences {} {
7eaa420a23 2007-11-05       aku: 	# The excluded symbols cann be used as blockers nor as
7eaa420a23 2007-11-05       aku: 	# possible parent for other symbols. We now drop the relevant
7eaa420a23 2007-11-05       aku: 	# entries to prevent them from causing confusion later on.
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku: 	set excl [project::sym excluded]
7eaa420a23 2007-11-05       aku: 
7eaa420a23 2007-11-05       aku: 	state run {
7eaa420a23 2007-11-05       aku: 	    DELETE FROM blocker
7eaa420a23 2007-11-05       aku: 	    WHERE bid IN (SELECT sid
7eaa420a23 2007-11-05       aku: 			  FROM   symbol
f7fe15cd0c 2007-12-08       aku: 			  WhERE  type = $excl); -- Get excluded symbols
7eaa420a23 2007-11-05       aku: 	    DELETE FROM parent
7eaa420a23 2007-11-05       aku: 	    WHERE pid IN (SELECT sid
7eaa420a23 2007-11-05       aku: 			  FROM   symbol
f7fe15cd0c 2007-12-08       aku: 			  WhERE  type = $excl); -- Get excluded symbols
efc78b7a42 2007-11-06       aku: 	}
efc78b7a42 2007-11-06       aku: 	return
efc78b7a42 2007-11-06       aku:     }
efc78b7a42 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku:     proc DeterminePreferedParents {} {
efc78b7a42 2007-11-06       aku: 	array set prefered {}
efc78b7a42 2007-11-06       aku: 
4c8a5a44af 2007-11-06       aku: 	set excl [project::sym excluded]
4c8a5a44af 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku: 	# Phase I: Pull the possible parents, using sorting to put the
efc78b7a42 2007-11-06       aku: 	#          prefered parent of each symbol last among all
efc78b7a42 2007-11-06       aku: 	#          candidates, allowing us get the prefered one by
4c8a5a44af 2007-11-06       aku: 	#          each candidate overwriting all previous
479c96c0fc 2008-03-02       aku: 	#          selections. Note that we ignore excluded symbols,
479c96c0fc 2008-03-02       aku: 	#          we do not care about their prefered parents and do
479c96c0fc 2008-03-02       aku: 	#          not attempt to compute them.
f637d42206 2008-02-24       aku: 
f637d42206 2008-02-24       aku: 	state foreachrow {
f637d42206 2008-02-24       aku: 	    SELECT   S.sid   AS xs,
f637d42206 2008-02-24       aku: 	             P.pid   AS xp,
f637d42206 2008-02-24       aku: 	             S.name  AS sname,
f637d42206 2008-02-24       aku: 	             SB.name AS pname,
f637d42206 2008-02-24       aku: 	             PR.name AS prname,
f637d42206 2008-02-24       aku: 	             P.n     AS votes
efc78b7a42 2007-11-06       aku: 	    FROM     symbol S, parent P, symbol SB, project PR
f7fe15cd0c 2007-12-08       aku: 	    WHERE    S.type != $excl      -- Restrict to wanted symbols
f7fe15cd0c 2007-12-08       aku: 	    AND      S.sid = P.sid        -- Get possible parents of symbol
f7fe15cd0c 2007-12-08       aku: 	    AND      P.pid = SB.sid       -- and
f7fe15cd0c 2007-12-08       aku: 	    AND      S.pid = PR.pid       -- the project of the symbol
f7fe15cd0c 2007-12-08       aku: 	    ORDER BY P.n ASC, P.pid DESC  -- Sorting, see below
f7fe15cd0c 2007-12-08       aku: 	    --
efc78b7a42 2007-11-06       aku: 	    -- Higher votes and smaller ids (= earlier branches) last
efc78b7a42 2007-11-06       aku: 	    -- We simply keep the last possible parent for each
efc78b7a42 2007-11-06       aku: 	    -- symbol.  This parent will have the max number of votes
efc78b7a42 2007-11-06       aku: 	    -- for its symbol and will be the earliest created branch
efc78b7a42 2007-11-06       aku: 	    -- possible among all with many votes.
f637d42206 2008-02-24       aku: 	} {
930ec162ce 2007-11-22       aku: 	    log write 9 pcollsym "Voting $votes for Parent($sname) = $pname"
930ec162ce 2007-11-22       aku: 
f637d42206 2008-02-24       aku: 	    set prefered($xs) [list $xp $sname $pname $prname]
efc78b7a42 2007-11-06       aku: 	}
efc78b7a42 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku: 	# Phase II: Write the found preferences back into the table
efc78b7a42 2007-11-06       aku: 	#           this pass defined for it.
efc78b7a42 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku: 	foreach {s x} [array get prefered] {
efc78b7a42 2007-11-06       aku: 	    struct::list assign $x p sname pname prname
efc78b7a42 2007-11-06       aku: 	    state run {
efc78b7a42 2007-11-06       aku: 		INSERT INTO preferedparent (sid, pid)
efc78b7a42 2007-11-06       aku: 		VALUES                     ($s,  $p);
efc78b7a42 2007-11-06       aku: 	    }
efc78b7a42 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku: 	    log write 3 pcollsym "$prname : '$sname's prefered parent is '$pname'"
efc78b7a42 2007-11-06       aku: 	}
efc78b7a42 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku: 	# Phase III: Check the result that all symbols except for
4c8a5a44af 2007-11-06       aku: 	#            trunks have a prefered parent. We also ignore
4c8a5a44af 2007-11-06       aku: 	#            excluded symbols, as we intentionally did not
4c8a5a44af 2007-11-06       aku: 	#            compute a prefered parent for them, see phase I.
efc78b7a42 2007-11-06       aku: 
f637d42206 2008-02-24       aku: 	state foreachrow {
f637d42206 2008-02-24       aku: 	    SELECT PR.name AS pname, S.name AS sname
f7fe15cd0c 2007-12-08       aku: 	    FROM   symbol S LEFT OUTER JOIN preferedparent P
f7fe15cd0c 2007-12-08       aku: 	    ON     S.sid = P.sid,       -- From symbol to prefered parent
f7fe15cd0c 2007-12-08       aku: 	           project PR
f7fe15cd0c 2007-12-08       aku: 	    WHERE  P.pid IS NULL        -- restrict to symbols without a preference
f7fe15cd0c 2007-12-08       aku: 	    AND    S.type != $excl      -- which are not excluded
f7fe15cd0c 2007-12-08       aku: 	    AND    S.name != ':trunk:'  -- and are not a trunk
f7fe15cd0c 2007-12-08       aku: 	    AND    S.pid = PR.pid       -- get project of symbol
f637d42206 2008-02-24       aku: 	} {
4c8a5a44af 2007-11-06       aku: 	    trouble fatal "$pname : '$sname' has no prefered parent."
7eaa420a23 2007-11-05       aku: 	}
efc78b7a42 2007-11-06       aku: 
efc78b7a42 2007-11-06       aku: 	# The reverse, having prefered parents for unknown symbols
efc78b7a42 2007-11-06       aku: 	# cannot occur.
7eaa420a23 2007-11-05       aku: 	return
7eaa420a23 2007-11-05       aku:     }
f888f06fe3 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     # # ## ### ##### ######## #############
6d4eb24738 2007-11-02       aku:     ## Configuration
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     pragma -hasinstances   no ; # singleton
6d4eb24738 2007-11-02       aku:     pragma -hastypeinfo    no ; # no introspection
6d4eb24738 2007-11-02       aku:     pragma -hastypedestroy no ; # immortal
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku:     # # ## ### ##### ######## #############
6d4eb24738 2007-11-02       aku: }
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: namespace eval ::vc::fossil::import::cvs::pass {
6d4eb24738 2007-11-02       aku:     namespace export collsym
6d4eb24738 2007-11-02       aku:     namespace eval collsym {
f888f06fe3 2007-11-02       aku: 	namespace import ::vc::fossil::import::cvs::repository
6d4eb24738 2007-11-02       aku: 	namespace import ::vc::fossil::import::cvs::state
f888f06fe3 2007-11-02       aku: 	namespace eval project {
f888f06fe3 2007-11-02       aku: 	    namespace import ::vc::fossil::import::cvs::project::sym
f888f06fe3 2007-11-02       aku: 	}
7eaa420a23 2007-11-05       aku: 	namespace import ::vc::tools::trouble
6d4eb24738 2007-11-02       aku: 	namespace import ::vc::tools::log
6d4eb24738 2007-11-02       aku: 	log register collsym
6d4eb24738 2007-11-02       aku:     }
6d4eb24738 2007-11-02       aku: }
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: # # ## ### ##### ######## ############# #####################
6d4eb24738 2007-11-02       aku: ## Ready
6d4eb24738 2007-11-02       aku: 
6d4eb24738 2007-11-02       aku: package provide vc::fossil::import::cvs::pass::collsym 1.0
6d4eb24738 2007-11-02       aku: return