Diff
Not logged in

Differences From:

File tools/cvs2fossil/lib/c2f_cyclebreaker.tcl part of check-in [d58423cdc4] - API change cycle breaker. The save callback command is now specified through a separate configuration command. Moved callback invokation to helper command. Updated pass 6. Moved changeset selection to helper command. by aku on 2007-11-21 03:46:22. [view]

To:

File tools/cvs2fossil/lib/c2f_cyclebreaker.tcl part of check-in [2cf0462b82] - Cycle breaker, API change. Routing the core cycle breaking through a callback so that users can choose their own algorithms. Updated passes 6 and 7. Moven changesets selection in pass 7 to separate command. by aku on 2007-11-21 04:05:53. [view]

@@ -21,8 +21,9 @@
 package require struct::graph                             ; # Graph handling.
 package require struct::list                              ; # Higher order list operations.
 package require vc::tools::dot                            ; # User feedback. DOT export.
 package require vc::tools::log                            ; # User feedback.
+package require vc::tools::trouble                        ; # Error reporting.
 package require vc::tools::misc                           ; # Text formatting.
 package require vc::fossil::import::cvs::project::rev     ; # Project level changesets
 package require vc::fossil::import::cvs::project::revlink ; # Cycle links.
 
@@ -37,8 +38,15 @@
 	::variable mysavecmd $cmd
 	return
     }
 
+    typemethod breakcmd {cmd} {
+	::variable mybreakcmd $cmd
+	return
+    }
+
+    # # ## ### ##### ######## #############
+
     typemethod dotsto {path} {
 	::variable mydotdestination $path
 	return
     }
@@ -51,8 +59,10 @@
 	Mark $dg
 	$dg destroy
 	return
     }
+
+    # # ## ### ##### ######## #############
 
     typemethod run {label changesets} {
 	::variable myat        0
 	::variable mydotprefix $label
@@ -78,20 +88,30 @@
 
 	InitializeCandidates $dg
 	while {1} {
 	    while {[WithoutPredecessor $dg n]} {
-		SaveAndRemove $dg $n
+		ProcessedHook $n $myat
+		$dg node delete $n
+		incr myat
 	    }
+
 	    if {![llength [dg nodes]]} break
-	    BreakCycle $dg [FindCycle $dg]
+
+	    BreakCycleHook       $dg
 	    InitializeCandidates $dg
 	}
 
 	dg destroy
 
 	log write 3 cyclebreaker Done.
-
 	ClearHooks
+	return
+    }
+
+    # # ## ### ##### ######## #############
+
+    typemethod break {graph} {
+	BreakCycle $graph [FindCycle $graph]
 	return
     }
 
     # # ## ### ##### ######## #############
@@ -174,16 +194,8 @@
 	# We do not delete the node immediately, to allow the Save
 	# procedure to save the dependencies as well (encoded in the
 	# arcs).
 	return 1
-    }
-
-    proc SaveAndRemove {dg n} {
-	::variable myat
-	ProcessedHook $n $myat
-	$dg node delete $n
-	incr myat
-	return
     }
 
     proc FindCycle {dg} {
 	# This procedure is run if and only the graph is not empty and
@@ -340,10 +352,25 @@
 	uplevel #0 [linsert $mysavecmd end $pos $cset]
 	return
     }
 
+    proc BreakCycleHook {graph} {
+	# Call out to the chosen algorithm for cycle breaking. Finding
+	# a cycle if no breaker was chosen is an error.
+
+	::variable mybreakcmd
+	if {![llength $mybreakcmd]} {
+	    trouble fatal "Found a cycle, expecting none."
+	    exit 1
+	}
+
+	uplevel #0 [linsert $mybreakcmd end $graph]
+	return
+    }
+
     proc ClearHooks {} {
-	::variable mysavecmd {}
+	::variable mysavecmd  {}
+	::variable mybreakcmd {}
 	return
     }
 
     # # ## ### ##### ######## #############
@@ -353,8 +380,9 @@
     typevariable mybottom {} ; # List of the candidate nodes for
 			       # committing.
 
     typevariable mysavecmd  {} ; # Callback, for each processed node.
+    typevariable mybreakcmd {} ; # Callback, for each found cycle.
 
     typevariable mydotdestination {} ; # Destination directory for the
 				       # generated .dot files.
     typevariable mydotprefix      {} ; # Prefix for dot files when
@@ -380,8 +408,9 @@
 	    namespace import ::vc::fossil::import::cvs::project::revlink
 	}
 	namespace import ::vc::tools::misc::*
 	namespace import ::vc::tools::log
+	namespace import ::vc::tools::trouble
 	namespace import ::vc::tools::dot
 	log register cyclebreaker
     }
 }