[PATCH 4 of 5] localrepo: do not write dirstate if it's not in transaction scope

Jun Wu quark at fb.com
Mon Feb 27 12:35:28 EST 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1488189479 28800
#      Mon Feb 27 01:57:59 2017 -0800
# Node ID f88c37484782ae7fede3c7a2a27a5f5d9b12bc9a
# Parent  89793c9bfdc93896fd308ad9f4c400710ff2bde2
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r f88c37484782
localrepo: do not write dirstate if it's not in transaction scope

See the previous patch for why.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1077,14 +1077,16 @@ class localrepository(object):
             repo = reporef()
             if success:
-                # this should be explicitly invoked here, because
-                # in-memory changes aren't written out at closing
-                # transaction, if tr.addfilegenerator (via
-                # dirstate.write or so) isn't invoked while
-                # transaction running
-                repo.dirstate.write(None)
+                if 'dirstate' in tr.scope():
+                    # this should be explicitly invoked here, because
+                    # in-memory changes aren't written out at closing
+                    # transaction, if tr.addfilegenerator (via
+                    # dirstate.write or so) isn't invoked while
+                    # transaction running
+                    repo.dirstate.write(None)
             else:
-                # discard all changes (including ones already written
-                # out) in this transaction
-                repo.dirstate.restorebackup(None, prefix='journal.')
+                if 'dirstate' in tr.scope():
+                    # discard all changes (including ones already written
+                    # out) in this transaction
+                    repo.dirstate.restorebackup(None, prefix='journal.')
 
                 repo.invalidate(clearfilecache=True)


More information about the Mercurial-devel mailing list