[PATCH 2 of 3 V3] localrepo: use dirstate restorebackup instead of copying dirstate manually

Mateusz Kwapich mitrandir at fb.com
Fri May 13 20:33:14 UTC 2016


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1463171408 25200
#      Fri May 13 13:30:08 2016 -0700
# Node ID bc6bf14ef3d209aae3888d08e1c9a6431bb69c73
# Parent  17853c3207bc004fb98dfb67c1a109c7de0b97e7
localrepo: use dirstate restorebackup instead of copying dirstate manually

This is one step towards having dirstate manage its own storage. It will
be useful for the implementation of sqldirstate [1].

I'm deleting two of the dirstate.invalidate() calls in localrepo because
restorebackup method does that for us.

[1] https://www.mercurial-scm.org/wiki/SQLDirstatePlan

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1041,13 +1041,9 @@ class localrepository(object):
                 # transaction running
                 repo.dirstate.write(None)
             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')
+                repo.dirstate.restorebackup(None, prefix='journal.')
 
                 repo.invalidate(clearfilecache=True)
 
@@ -1189,7 +1185,7 @@ class localrepository(object):
             # prevent dirstateguard from overwriting already restored one
             dsguard.close()
 
-            self.vfs.rename('undo.dirstate', 'dirstate')
+            self.dirstate.restorebackup(None, prefix='undo.')
             try:
                 branch = self.vfs.read('undo.branch')
                 self.dirstate.setbranch(encoding.tolocal(branch))
@@ -1198,7 +1194,6 @@ class localrepository(object):
                           'current branch is still \'%s\'\n')
                         % self.dirstate.branch())
 
-            self.dirstate.invalidate()
             parents = tuple([p.rev() for p in self[None].parents()])
             if len(parents) > 1:
                 ui.status(_('working directory now based on '


More information about the Mercurial-devel mailing list