histedit: create transaction outside of try
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 12 Jul 2017 13:17:49 -0700
changeset 33445 0491004e2233
parent 33444 c4e39512a661
child 33446 fad6852cf879
histedit: create transaction outside of try Just a little refactoring to simplify the next patch. Differential Revision: https://phab.mercurial-scm.org/D65
hgext/histedit.py
--- a/hgext/histedit.py	Wed Jul 12 11:18:02 2017 -0700
+++ b/hgext/histedit.py	Wed Jul 12 13:17:49 2017 -0700
@@ -1107,23 +1107,22 @@
         if action.verb == 'fold' and nextact and nextact.verb == 'fold':
             state.actions[idx].__class__ = _multifold
 
-    total = len(state.actions)
-    pos = 0
-    tr = None
-
     # Force an initial state file write, so the user can run --abort/continue
     # even if there's an exception before the first transaction serialize.
     state.write()
+
+    total = len(state.actions)
+    pos = 0
+    tr = None
+    # Don't use singletransaction by default since it rolls the entire
+    # transaction back if an unexpected exception happens (like a
+    # pretxncommit hook throws, or the user aborts the commit msg editor).
+    if ui.configbool("histedit", "singletransaction", False):
+        # Don't use a 'with' for the transaction, since actions may close
+        # and reopen a transaction. For example, if the action executes an
+        # external process it may choose to commit the transaction first.
+        tr = repo.transaction('histedit')
     try:
-        # Don't use singletransaction by default since it rolls the entire
-        # transaction back if an unexpected exception happens (like a
-        # pretxncommit hook throws, or the user aborts the commit msg editor).
-        if ui.configbool("histedit", "singletransaction", False):
-            # Don't use a 'with' for the transaction, since actions may close
-            # and reopen a transaction. For example, if the action executes an
-            # external process it may choose to commit the transaction first.
-            tr = repo.transaction('histedit')
-
         while state.actions:
             state.write(tr=tr)
             actobj = state.actions[0]