effect-flag: rework existing test to prepare for mor tests
importcollectionsfrommercurialimportobsolete# Copied from evolve 081605c2e9b6def_orderrevs(repo,revs):"""Compute an ordering to solve instability for the given revs revs is a list of unstable revisions. Returns the same revisions ordered to solve their instability from the bottom to the top of the stack that the stabilization process will produce eventually. This ensures the minimal number of stabilizations, as we can stabilize each revision on its final stabilized destination. """# Step 1: Build the dependency graphdependencies,rdependencies=builddependencies(repo,revs)# Step 2: Build the ordering# Remove the revisions with no dependency(A) and add them to the ordering.# Removing these revisions leads to new revisions with no dependency (the# one depending on A) that we can remove from the dependency graph and add# to the ordering. We progress in a similar fashion until the ordering is# builtsolvablerevs=[rforrinsorted(dependencies.keys())ifnotdependencies[r]]ordering=[]whilesolvablerevs:rev=solvablerevs.pop()fordependentinrdependencies[rev]:dependencies[dependent].remove(rev)ifnotdependencies[dependent]:solvablerevs.append(dependent)deldependencies[rev]ordering.append(rev)ordering.extend(sorted(dependencies))returnorderingdefbuilddependencies(repo,revs):"""returns dependency graphs giving an order to solve instability of revs (see _orderrevs for more information on usage)"""# For each troubled revision we keep track of what instability if any should# be resolved in order to resolve it. Example:# dependencies = {3: [6], 6:[]}# Means that: 6 has no dependency, 3 depends on 6 to be solveddependencies={}# rdependencies is the inverted dict of dependenciesrdependencies=collections.defaultdict(set)forrinrevs:dependencies[r]=set()forpinrepo[r].parents():try:succ=_singlesuccessor(repo,p)exceptMultipleSuccessorsErrorasexc:dependencies[r]=exc.successorssetscontinueifsuccinrevs:dependencies[r].add(succ)rdependencies[succ].add(r)returndependencies,rdependenciesdef_singlesuccessor(repo,p):"""returns p (as rev) if not obsolete or its unique latest successors fail if there are no such successor"""ifnotp.obsolete():returnp.rev()obs=repo[p]ui=repo.uinewer=obsolete.successorssets(repo,obs.node())# search of a parent which is not killedwhilenotnewer:ui.debug("stabilize target %s is plain dead,"" trying to stabilize on its parent\n"%obs)obs=obs.parents()[0]newer=obsolete.successorssets(repo,obs.node())iflen(newer)>1orlen(newer[0])>1:raiseMultipleSuccessorsError(newer)returnrepo[newer[0][0]].rev()classMultipleSuccessorsError(RuntimeError):"""Exception raised by _singlesuccessor when multiple successor sets exists The object contains the list of successorssets in its 'successorssets' attribute to call to easily recover. """def__init__(self,successorssets):self.successorssets=successorssets