Fix undo after aborted commit bug
authormpm@selenic.com
Wed, 27 Jul 2005 18:16:20 -0800
changeset 785 46a8dd3145cc
parent 784 853bfbf1a312
child 786 902b12d55751
Fix undo after aborted commit bug Commit would overwrite undo.dirstate unconditionally, so an undo after an aborted commit would restore the dirstate from the aborted commit and not the prior transaction. This copies dirstate to journal.dirstate and moves it after a successful transaction.
mercurial/hg.py
mercurial/transaction.py
tests/test-hup.out
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -675,11 +675,15 @@ class localrepository:
             ds = self.opener("dirstate").read()
         except IOError:
             ds = ""
-        self.opener("undo.dirstate", "w").write(ds)
+        self.opener("journal.dirstate", "w").write(ds)
 
-        return transaction.transaction(self.ui.warn,
-                                       self.opener, self.join("journal"),
-                                       self.join("undo"))
+        def after():
+            util.rename(self.join("journal"), self.join("undo"))
+            util.rename(self.join("journal.dirstate"),
+                        self.join("undo.dirstate"))
+
+        return transaction.transaction(self.ui.warn, self.opener,
+                                       self.join("journal"), after)
 
     def recover(self):
         lock = self.lock()
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -50,7 +50,7 @@ class transaction:
         self.file.close()
         self.entries = []
         if self.after:
-            util.rename(self.journal, self.after)
+            self.after()
         else:
             os.unlink(self.journal)
         self.journal = None
--- a/tests/test-hup.out
+++ b/tests/test-hup.out
@@ -7,4 +7,4 @@ rollback completed
 00changelog.d
 00changelog.i
 data
-undo.dirstate
+journal.dirstate