[PATCH 1 of 3] transaction: always remove empty journal on abort

Sune Foldager cryo at cyanite.org
Fri Oct 30 16:42:42 UTC 2009


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1256920863 -3600
# Node ID 035e516c15acca1abb1ce845bc1ec9ade88f3c20
# Parent  5bbf4f130684e27ce4491ea31fbe1629dcc4ebdb
transaction: always remove empty journal on abort

When transactions without entries were aborted, the journal (of size 0) was not
unlinked, which prevents subsequent operations until hg recover is run on the
repository.

We also make sure the journal is unlinked when committing, even if the provided
hook doesn't do so.

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -59,8 +59,7 @@
 
     def __del__(self):
         if self.journal:
-            if self.entries: self._abort()
-            self.file.close()
+            self._abort()
 
     @active
     def startgroup(self):
@@ -126,6 +125,8 @@
         self.entries = []
         if self.after:
             self.after()
+            if os.path.isfile(self.journal):
+                os.unlink(self.journal)
         else:
             os.unlink(self.journal)
         self.journal = None
@@ -141,7 +142,10 @@
         self.count = 0
         self.file.close()
 
-        if not self.entries: return
+        if not self.entries:
+            if self.journal:
+                os.unlink(self.journal)
+            return
 
         self.report(_("transaction abort!\n"))
 
diff --git a/tests/test-journal-exists b/tests/test-journal-exists
--- a/tests/test-journal-exists
+++ b/tests/test-journal-exists
@@ -3,6 +3,7 @@
 hg init
 echo a > a
 hg ci -Am0
+hg -q clone . foo
 
 touch .hg/store/journal
 
@@ -10,3 +11,10 @@
 hg ci -Am0
 
 hg recover
+
+echo % check that zero-size journals are correctly aborted
+hg bundle -qa repo.hg
+chmod -w foo/.hg/store/00changelog.i
+hg -R foo unbundle repo.hg 2>&1 | sed 's/\(abort: Permission denied\).*/\1/'
+if test -f foo/.hg/store/journal; then echo 'journal exists :-('; fi
+exit 0
diff --git a/tests/test-journal-exists.out b/tests/test-journal-exists.out
--- a/tests/test-journal-exists.out
+++ b/tests/test-journal-exists.out
@@ -6,3 +6,6 @@
 crosschecking files in changesets and manifests
 checking files
 1 files, 1 changesets, 1 total revisions
+% check that zero-size journals are correctly aborted
+adding changesets
+abort: Permission denied



More information about the Mercurial-devel mailing list