Thread (6 messages) flat view 6 messages, 1 author, 2016-06-15
DORMANTno replies

[StGit PATCH 1/5] Expose transaction abort function

From: Karl Hasselström <hidden>
Date: 2016-06-15 22:43:59
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>

---

 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)
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help