chiark / gitweb /
Expose transaction abort function
authorKarl Hasselström <kha@treskal.com>
Thu, 13 Dec 2007 17:10:45 +0000 (18:10 +0100)
committerKarl Hasselström <kha@treskal.com>
Wed, 9 Jan 2008 23:37:12 +0000 (00:37 +0100)
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

index 77333b3c027d20d71f5a39fc68f6088d1c65e090..663d393f1860debbe38b64ae7cc2106fddc87a18 100644 (file)
@@ -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)