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: 6d4eb24738 2007-11-02 aku: state reading symbol 6d4eb24738 2007-11-02 aku: state reading blocker 6d4eb24738 2007-11-02 aku: state reading parent 6d4eb24738 2007-11-02 aku: efc78b7a42 2007-11-06 aku: state writing 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 } 74854a30b8 2007-12-02 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 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: 7eaa420a23 2007-11-05 aku: foreach {pname sname} [state run { 7eaa420a23 2007-11-05 aku: SELECT P.name, S.name 7eaa420a23 2007-11-05 aku: FROM project P, symbol S 7eaa420a23 2007-11-05 aku: WHERE P.pid = S.pid 7eaa420a23 2007-11-05 aku: AND S.type = $undef 7eaa420a23 2007-11-05 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: 7eaa420a23 2007-11-05 aku: foreach {pname sname} [state run { 7eaa420a23 2007-11-05 aku: SELECT P.name, S.name 7eaa420a23 2007-11-05 aku: FROM project P, symbol S 7eaa420a23 2007-11-05 aku: WHERE P.pid = S.pid 7eaa420a23 2007-11-05 aku: AND S.type NOT IN (0,1,2) 7eaa420a23 2007-11-05 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: 7eaa420a23 2007-11-05 aku: foreach {pname sname bname} [state run { 7eaa420a23 2007-11-05 aku: SELECT P.name, S.name, SB.name 7eaa420a23 2007-11-05 aku: FROM project P, symbol S, blocker B, symbol SB 7eaa420a23 2007-11-05 aku: WHERE P.pid = S.pid 7eaa420a23 2007-11-05 aku: AND S.type = $excl 7eaa420a23 2007-11-05 aku: AND S.sid = B.sid 7eaa420a23 2007-11-05 aku: AND B.bid = SB.sid 7eaa420a23 2007-11-05 aku: AND SB.type != $excl 7eaa420a23 2007-11-05 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: 7eaa420a23 2007-11-05 aku: foreach {pname sname} [state run { 7eaa420a23 2007-11-05 aku: SELECT P.name, S.name 7eaa420a23 2007-11-05 aku: FROM project P, symbol S 7eaa420a23 2007-11-05 aku: WHERE P.pid = S.pid 7eaa420a23 2007-11-05 aku: AND S.type = $tag 7eaa420a23 2007-11-05 aku: AND S.commit_count > 0 7eaa420a23 2007-11-05 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 7eaa420a23 2007-11-05 aku: WhERE type = $excl); 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 7eaa420a23 2007-11-05 aku: WhERE type = $excl); 7eaa420a23 2007-11-05 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 4c8a5a44af 2007-11-06 aku: # selections. Note that we ignore excluded symbol, we 4c8a5a44af 2007-11-06 aku: # do not care about their prefered parents and do not 4c8a5a44af 2007-11-06 aku: # attempt to compute them. 4c8a5a44af 2007-11-06 aku: 930ec162ce 2007-11-22 aku: foreach {s p sname pname prname votes} [state run { 930ec162ce 2007-11-22 aku: SELECT S.sid, P.pid, S.name, SB.name, PR.name, P.n efc78b7a42 2007-11-06 aku: FROM symbol S, parent P, symbol SB, project PR efc78b7a42 2007-11-06 aku: WHERE S.sid = P.sid efc78b7a42 2007-11-06 aku: AND P.pid = SB.sid efc78b7a42 2007-11-06 aku: AND S.pid = PR.pid 4c8a5a44af 2007-11-06 aku: AND S.type != $excl efc78b7a42 2007-11-06 aku: ORDER BY P.n ASC, P.pid DESC 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. efc78b7a42 2007-11-06 aku: }] { 930ec162ce 2007-11-22 aku: log write 9 pcollsym "Voting $votes for Parent($sname) = $pname" 930ec162ce 2007-11-22 aku: efc78b7a42 2007-11-06 aku: set prefered($s) [list $p $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: efc78b7a42 2007-11-06 aku: foreach {pname sname} [state run { 4c8a5a44af 2007-11-06 aku: SELECT PR.name, S.name efc78b7a42 2007-11-06 aku: FROM project PR, symbol S LEFT OUTER JOIN preferedparent P efc78b7a42 2007-11-06 aku: ON S.sid = P.sid efc78b7a42 2007-11-06 aku: WHERE P.pid IS NULL efc78b7a42 2007-11-06 aku: AND S.name != ':trunk:' efc78b7a42 2007-11-06 aku: AND S.pid = PR.pid 4c8a5a44af 2007-11-06 aku: AND S.type != $excl efc78b7a42 2007-11-06 aku: }] { 4c8a5a44af 2007-11-06 aku: trouble fatal "$pname : '$sname' has no prefered parent." efc78b7a42 2007-11-06 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: } 6d4eb24738 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