diff mercurial/transaction.py @ 49995:27fd12eca557

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 14 Feb 2023 20:09:39 +0100
parents 3128018e878b
children c8f32aa80dca
line wrap: on
line diff
--- 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: