From 1743e45992c1eea47f52b704a6e0d36c59008924 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karl=20Hasselstr=C3=B6m?= Date: Thu, 24 Jul 2008 00:51:18 +0200 Subject: [PATCH] Add utility function for reordering patches MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Karl Hasselström --- stgit/lib/transaction.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 -- 2.11.0