From: Karl Hasselström Date: Wed, 23 Jul 2008 22:51:18 +0000 (+0200) Subject: Add utility function for reordering patches X-Git-Tag: v0.15-rc1~187 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/1743e45992c1eea47f52b704a6e0d36c59008924?hp=ca76dc5e788f12b6446f29570528c99f3f4bdc32 Add utility function for reordering patches Signed-off-by: Karl Hasselström --- diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py index 6880662..cbfca55 100644 --- a/stgit/lib/transaction.py +++ b/stgit/lib/transaction.py @@ -2,6 +2,7 @@ updates to an StGit stack in a safe and convenient way.""" import atexit +import itertools as it from stgit import exception, utils from stgit.utils import any, all @@ -294,3 +295,16 @@ class StackTransaction(object): self.__allow_conflicts = lambda trans: True self.__halt('Merge conflict') + + def reorder_patches(self, applied, unapplied, hidden, iw = None): + """Push and pop patches to attain the given ordering.""" + common = len(list(it.takewhile(lambda (a, b): a == b, + zip(self.applied, applied)))) + to_pop = set(self.applied[common:]) + self.pop_patches(lambda pn: pn in to_pop) + for pn in applied[common:]: + self.push_patch(pn, iw) + assert self.applied == applied + assert set(self.unapplied + self.hidden) == set(unapplied + hidden) + self.unapplied = unapplied + self.hidden = hidden