[StGit PATCH 04/14] Add utility function for reordering patches
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/lib/transaction.py | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 4c4da1a..16f5a4b 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -1,6 +1,8 @@
"""The L{StackTransaction} class makes it possible to make complex
updates to an StGit stack in a safe and convenient way."""
+import itertools as it
+
from stgit import exception, utils
from stgit.utils import any, all
from stgit.out import *
@@ -274,3 +276,15 @@ class StackTransaction(object):
self.__allow_conflicts = lambda trans: True
self.__halt('Merge conflict')
+
+ def reorder_patches(self, applied, unapplied, 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) == set(unapplied)
+ self.unapplied = unapplied