transaction: quietly rollback if no other changes than temporary files
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 14 Feb 2023 20:09:39 +0100
changeset 49995 27fd12eca557
parent 49994 3128018e878b
child 49996 89796af68b27
transaction: quietly rollback if no other changes than temporary files If no actual change have been made, we don't really need to roll them back. We only have to cleanup some temporary files and it seems reasonable to do that quietly. This will help us to use the transaction in wider context¹ without impacting the user experience. [1] as in Python context managers that lives longer.
mercurial/transaction.py
tests/test-bookmarks.t
tests/test-phases.t
tests/test-rebase-transaction.t
tests/test-share-bookmarks.t
tests/test-split.t
--- a/mercurial/transaction.py	Tue Feb 14 20:04:17 2023 +0100
+++ b/mercurial/transaction.py	Tue Feb 14 20:09:39 2023 +0100
@@ -691,13 +691,22 @@
         True if nothing, except temporary files has been writen on disk."""
         if entries:
             return False
-        if self._backupentries:
-            return False
+        for e in self._backupentries:
+            if e[1]:
+                return False
         return True
 
     def _do_quick_abort(self, entries):
         """(Silently) do a quick cleanup (see _can_quick_abort)"""
         assert self._can_quick_abort(entries)
+        tmp_files = [e for e in self._backupentries if not e[1]]
+        for vfs_id, old_path, tmp_path, xxx in tmp_files:
+            assert not old_path
+            vfs = self._vfsmap[vfs_id]
+            try:
+                vfs.unlink(tmp_path)
+            except FileNotFoundError:
+                pass
         if self._backupjournal:
             self._opener.unlink(self._backupjournal)
         if self._journal:
--- a/tests/test-bookmarks.t	Tue Feb 14 20:04:17 2023 +0100
+++ b/tests/test-bookmarks.t	Tue Feb 14 20:09:39 2023 +0100
@@ -1126,8 +1126,6 @@
   $ hg add a
   $ hg commit -m '#0'
   $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" bookmarks INVISIBLE
-  transaction abort!
-  rollback completed
   abort: pretxnclose hook exited with status 1
   [40]
   $ cp .hg/bookmarks.pending.saved .hg/bookmarks.pending
@@ -1159,8 +1157,6 @@
      x  y                      2:db815d6d32e6
   @unrelated
   no bookmarks set
-  transaction abort!
-  rollback completed
   abort: pretxnclose hook exited with status 1
   [40]
 
@@ -1243,8 +1239,6 @@
 attempt to create on a default changeset
 
   $ hg bookmark -r 81dcce76aa0b NEW
-  transaction abort!
-  rollback completed
   abort: pretxnclose-bookmark.force-public hook exited with status 1
   [40]
 
@@ -1255,7 +1249,5 @@
 move to the other branch
 
   $ hg bookmark -f -r 125c9a1d6df6 NEW
-  transaction abort!
-  rollback completed
   abort: pretxnclose-bookmark.force-forward hook exited with status 1
   [40]
--- a/tests/test-phases.t	Tue Feb 14 20:04:17 2023 +0100
+++ b/tests/test-phases.t	Tue Feb 14 20:09:39 2023 +0100
@@ -818,8 +818,6 @@
   $ hg phase 6
   6: draft
   $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" phase -f -s 6
-  transaction abort!
-  rollback completed
   abort: pretxnclose hook exited with status 1
   [40]
   $ cp .hg/store/phaseroots.pending.saved .hg/store/phaseroots.pending
@@ -841,8 +839,6 @@
   7: secret
   @push-dest
   6: draft
-  transaction abort!
-  rollback completed
   abort: pretxnclose hook exited with status 1
   [40]
 
@@ -915,13 +911,9 @@
 Try various actions. only the draft move should succeed
 
   $ hg phase --public b3325c91a4d9
-  transaction abort!
-  rollback completed
   abort: pretxnclose-phase.nopublish_D hook exited with status 1
   [40]
   $ hg phase --public a603bfb5a83e
-  transaction abort!
-  rollback completed
   abort: pretxnclose-phase.nopublish_D hook exited with status 1
   [40]
   $ hg phase --draft 17a481b3bccb
@@ -932,8 +924,6 @@
   test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde:  secret -> draft
   test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af:  secret -> draft
   $ hg phase --public 17a481b3bccb
-  transaction abort!
-  rollback completed
   abort: pretxnclose-phase.nopublish_D hook exited with status 1
   [40]
 
--- a/tests/test-rebase-transaction.t	Tue Feb 14 20:04:17 2023 +0100
+++ b/tests/test-rebase-transaction.t	Tue Feb 14 20:09:39 2023 +0100
@@ -168,8 +168,6 @@
   rebasing 1:112478962961 B "B"
   rebasing 3:26805aba1e60 C "C"
   rebasing 5:f585351a92f8 D tip "D"
-  transaction abort!
-  rollback completed
   abort: edit failed: false exited with status 1
   [250]
   $ hg tglog
--- a/tests/test-share-bookmarks.t	Tue Feb 14 20:04:17 2023 +0100
+++ b/tests/test-share-bookmarks.t	Tue Feb 14 20:09:39 2023 +0100
@@ -99,8 +99,6 @@
      bm2                       2:c2e0ac586386 (svfs !)
    * bm3                       2:c2e0ac586386
      bmX                       2:c2e0ac586386 (vfs !)
-  transaction abort!
-  rollback completed
   abort: pretxnclose hook exited with status 1
   [40]
   $ hg book bm1
@@ -124,8 +122,6 @@
      bm2                       2:c2e0ac586386 (svfs !)
      bm3                       2:c2e0ac586386
    * bmX                       2:c2e0ac586386
-  transaction abort!
-  rollback completed
   abort: pretxnclose hook exited with status 1
   [40]
   $ hg book bm3
--- a/tests/test-split.t	Tue Feb 14 20:04:17 2023 +0100
+++ b/tests/test-split.t	Tue Feb 14 20:09:39 2023 +0100
@@ -156,8 +156,6 @@
   record change 3/3 to 'a'?
   (enter ? for help) [Ynesfdaq?] y
   
-  transaction abort!
-  rollback completed
   abort: edit failed: false exited with status 1
   [250]
   $ hg status