[StGit PATCH 1/5] Expose transaction abort function
- From
Karl Hasselström <kha@treskal.com>
- Date
- Dec 14, 2007, 06:32 UTC
- Message-ID
- <20071214063213.29290.54202.stgit@yoghurt>
- In-Reply-To
- <20071214062618.29290.70792.stgit@yoghurt>
Users of stack transactions may call abort() instead of run(), if they wish to roll back the transaction instead of committing it.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/lib/transaction.py | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py index 77333b3..663d393 100644 --- a/stgit/lib/transaction.py +++ b/stgit/lib/transaction.py @@ -77,6 +77,10 @@ class StackTransaction(object): return self.__patches[self.__applied[-1]] else: return self.__stack.base + def abort(self, iw = None): + # The only state we need to restore is index+worktree. + if iw: + self.__checkout(self.__stack.head.data.tree, iw) def run(self, iw = None): self.__check_consistency() new_head = self.__head @@ -85,9 +89,8 @@ class StackTransaction(object): try: self.__checkout(new_head.data.tree, iw) except git.CheckoutException: - # We have to abort the transaction. The only state we need - # to restore is index+worktree. - self.__checkout(self.__stack.head.data.tree, iw) + # We have to abort the transaction. + self.abort(iw) self.__abort() self.__stack.set_head(new_head, self.__msg)