mercurial/localrepo.py
changeset 26577 8f2ff40fe9c9
parent 26499 e72b62b154b0
child 26587 56b2bcea2529
--- a/mercurial/localrepo.py	Fri Oct 09 03:53:46 2015 +0900
+++ b/mercurial/localrepo.py	Fri Oct 09 03:53:46 2015 +0900
@@ -997,13 +997,26 @@
             pending = lambda: tr.writepending() and self.root or ""
             reporef().hook('pretxnclose', throw=True, pending=pending,
                            txnname=desc, **tr.hookargs)
+        def releasefn(tr, success):
+            repo = reporef()
+            if success:
+                repo.dirstate.write()
+            else:
+                # prevent in-memory changes from being written out at
+                # the end of outer wlock scope or so
+                repo.dirstate.invalidate()
+
+                # discard all changes (including ones already written
+                # out) in this transaction
+                repo.vfs.rename('journal.dirstate', 'dirstate')
 
         tr = transaction.transaction(rp, self.svfs, vfsmap,
                                      "journal",
                                      "undo",
                                      aftertrans(renames),
                                      self.store.createmode,
-                                     validator=validate)
+                                     validator=validate,
+                                     releasefn=releasefn)
 
         tr.hookargs['txnid'] = txnid
         # note: writing the fncache only during finalize mean that the file is