Artifact Content
Not logged in

Artifact 96780b3d36b6672b6b3d93127ca61d36c63b258d

File tools/cvs2fossil/lib/c2f_prtopsort.tcl part of check-in [66c85b4db4] - Investigation of changeset order differences between running passes 1 to 6 and pass 6 alone show why the topological sort passes are separate in cvs2svn. The breaking of cycles can change the order of things due to different timeranges and dependencies of the broken changesets. Created two new passes for the sorting. The break passes 7 and 8 are now passes 8 and 9, and the new sort passes are 7 and 10. by aku on 2007-11-25 02:59:21.

## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
## Copyright (c) 2007 Andreas Kupries.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# This software consists of voluntary contributions made by many
# individuals.  For exact contribution history, see the revision
# history and logs, available at http://fossil-scm.hwaci.com/fossil
# # ## ### ##### ######## ############# #####################

## Pass VII. This pass goes over the set of revision based changesets
## and sorts them topologically. It assumes that there are no cycles
## which could impede it, any having been broken by the previous pass,
## and aborts if that condition doesn't hold.

# # ## ### ##### ######## ############# #####################
## Requirements

package require Tcl 8.4                                   ; # Required runtime.
package require snit                                      ; # OO system.
package require struct::list                              ; # Higher order list operations.
package require vc::tools::log                            ; # User feedback.
package require vc::fossil::import::cvs::cyclebreaker     ; # Breaking dependency cycles.
package require vc::fossil::import::cvs::state            ; # State storage.
package require vc::fossil::import::cvs::project::rev     ; # Project level changesets

# # ## ### ##### ######## ############# #####################
## Register the pass with the management

vc::fossil::import::cvs::pass define \
    RevTopologicalSort \
    {Topologically Sort Revision ChangeSets} \
    ::vc::fossil::import::cvs::pass::rtopsort

# # ## ### ##### ######## ############# #####################
## 

snit::type ::vc::fossil::import::cvs::pass::rtopsort {
    # # ## ### ##### ######## #############
    ## Public API

    typemethod setup {} {
	# Define the names and structure of the persistent state of
	# this pass.

	state reading revision
	state reading changeset
	state reading csrevision

	state writing csorder {
	    -- Commit order of the revision changesets based on their
	    -- dependencies

	    cid INTEGER  NOT NULL  REFERENCES changeset,
	    pos INTEGER  NOT NULL,
	    UNIQUE (cid),
	    UNIQUE (pos)
	}
	return
    }

    typemethod load {} {
	# Pass manager interface. Executed to load data computed by
	# this pass into memory when this pass is skipped instead of
	# executed.

	state reading changeset
	project::rev loadcounter
	return
    }

    typemethod run {} {
	# Pass manager interface. Executed to perform the
	# functionality of the pass.

	cyclebreaker savecmd  [myproc SaveOrder]
	state transaction {
	    cyclebreaker run break-rev [myproc Changesets]
	}
	return
    }

    typemethod discard {} {
	# Pass manager interface. Executed for all passes after the
	# run passes, to remove all data of this pass from the state,
	# as being out of date.

	state discard csorder
	return
    }

    # # ## ### ##### ######## #############
    ## Internal methods

    proc Changesets {} {
	return [struct::list filter [project::rev all] [myproc IsByRevision]]
    }

    proc IsByRevision {cset} { $cset byrevision }

    proc SaveOrder {graph at cset} {
	set cid [$cset id]

	log write 4 rtopsort "Changeset @ $at: [$cset str] <<[$graph node set $cset timerange]>>"
	state run {
	    INSERT INTO csorder (cid,  pos)
	    VALUES              ($cid, $at)
	}
	return
    }

    # # ## ### ##### ######## #############
    ## Configuration

    pragma -hasinstances   no ; # singleton
    pragma -hastypeinfo    no ; # no introspection
    pragma -hastypedestroy no ; # immortal

    # # ## ### ##### ######## #############
}

namespace eval ::vc::fossil::import::cvs::pass {
    namespace export rtopsort
    namespace eval rtopsort {
	namespace import ::vc::fossil::import::cvs::cyclebreaker
	namespace import ::vc::fossil::import::cvs::state
	namespace eval project {
	    namespace import ::vc::fossil::import::cvs::project::rev
	}
	namespace import ::vc::tools::log
	log register rtopsort
    }
}

# # ## ### ##### ######## ############# #####################
## Ready

package provide vc::fossil::import::cvs::pass::rtopsort 1.0
return