git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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)
 
Previous: Karl HasselströmNext: Karl Hasselström
Message 2 of 6 in “More experimental patches”
  1. 0/5 More experimental patchesKarl Hasselström, Dec 14, 2007
  2. 1/5 Expose transaction abort functionKarl Hasselström, Dec 14, 2007
  3. 2/5 stg coalesce: Support --file and --save-templateKarl Hasselström, Dec 14, 2007
  4. 3/5 Set exit code to 3 on merge conflictKarl Hasselström, Dec 14, 2007
  5. 4/5 Convert "stg commit" to new infrastructureKarl Hasselström, Dec 14, 2007
  6. 5/5 Make "stg commit" fancierKarl Hasselström, Dec 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.