changeset 41384:57c462db87fd

localrepo: use context manager for transaction in commit() A side-effect is that the transaction is released a little earlier, so the "commit message saved in ..." messages now comes after the "rollback completed" message. That seems slightly better to me. Differential Revision: https://phab.mercurial-scm.org/D5622
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 16 Jan 2019 17:33:47 -0800
parents 092c5d05ba01
children b87a009d1b3b
files mercurial/localrepo.py tests/test-histedit-edit.t tests/test-mq-qnew.t tests/test-rollback.t tests/test-tag.t
diffstat 5 files changed, 13 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Wed Jan 16 17:46:39 2019 -0800
+++ b/mercurial/localrepo.py	Wed Jan 16 17:33:47 2019 -0800
@@ -2409,7 +2409,7 @@
             match.explicitdir = vdirs.append
             match.bad = fail
 
-        wlock = lock = tr = None
+        wlock = lock = None
         try:
             wlock = self.wlock()
             lock = self.lock() # for recent changelog (see issue4368)
@@ -2473,13 +2473,12 @@
             try:
                 self.hook("precommit", throw=True, parent1=hookp1,
                           parent2=hookp2)
-                tr = self.transaction('commit')
-                ret = self.commitctx(cctx, True)
-                # update bookmarks, dirstate and mergestate
-                bookmarks.update(self, [p1, p2], ret)
-                cctx.markcommitted(ret)
-                ms.reset()
-                tr.close()
+                with self.transaction('commit'):
+                    ret = self.commitctx(cctx, True)
+                    # update bookmarks, dirstate and mergestate
+                    bookmarks.update(self, [p1, p2], ret)
+                    cctx.markcommitted(ret)
+                    ms.reset()
             except: # re-raises
                 if edited:
                     self.ui.write(
@@ -2487,7 +2486,7 @@
                 raise
 
         finally:
-            lockmod.release(tr, lock, wlock)
+            lockmod.release(lock, wlock)
 
         def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
             # hack for command that use a temporary commit (eg: histedit)
--- a/tests/test-histedit-edit.t	Wed Jan 16 17:46:39 2019 -0800
+++ b/tests/test-histedit-edit.t	Wed Jan 16 17:33:47 2019 -0800
@@ -370,9 +370,9 @@
   HG: branch 'default'
   HG: added f
   ====
-  note: commit message saved in .hg/last-message.txt
   transaction abort!
   rollback completed
+  note: commit message saved in .hg/last-message.txt
   abort: pretxncommit.unexpectedabort hook exited with status 1
   [255]
   $ cat .hg/last-message.txt
@@ -394,9 +394,9 @@
   HG: user: test
   HG: branch 'default'
   HG: added f
-  note: commit message saved in .hg/last-message.txt
   transaction abort!
   rollback completed
+  note: commit message saved in .hg/last-message.txt
   abort: pretxncommit.unexpectedabort hook exited with status 1
   [255]
 
--- a/tests/test-mq-qnew.t	Wed Jan 16 17:46:39 2019 -0800
+++ b/tests/test-mq-qnew.t	Wed Jan 16 17:33:47 2019 -0800
@@ -305,9 +305,9 @@
   HG: branch 'default'
   HG: no files changed
   ====
-  note: commit message saved in .hg/last-message.txt
   transaction abort!
   rollback completed
+  note: commit message saved in .hg/last-message.txt
   abort: pretxncommit.unexpectedabort hook exited with status 1
   [255]
   $ cat .hg/last-message.txt
--- a/tests/test-rollback.t	Wed Jan 16 17:46:39 2019 -0800
+++ b/tests/test-rollback.t	Wed Jan 16 17:33:47 2019 -0800
@@ -113,9 +113,9 @@
   > echo "another precious commit message" > "$1"
   > __EOF__
   $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg --config hooks.pretxncommit=false commit 2>&1
-  note: commit message saved in .hg/last-message.txt
   transaction abort!
   rollback completed
+  note: commit message saved in .hg/last-message.txt
   abort: pretxncommit hook exited with status * (glob)
   [255]
   $ cat .hg/last-message.txt
--- a/tests/test-tag.t	Wed Jan 16 17:46:39 2019 -0800
+++ b/tests/test-tag.t	Wed Jan 16 17:33:47 2019 -0800
@@ -320,9 +320,9 @@
   HG: branch 'tag-and-branch-same-name'
   HG: changed .hgtags
   ====
-  note: commit message saved in .hg/last-message.txt
   transaction abort!
   rollback completed
+  note: commit message saved in .hg/last-message.txt
   abort: pretxncommit.unexpectedabort hook exited with status 1
   [255]
   $ cat .hg/last-message.txt