[PATCH 4 of 7] dirstate: centralize _cwd handling into _cwd method

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Jul 2 13:53:18 EDT 2017


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1499017960 -32400
#      Mon Jul 03 02:52:40 2017 +0900
# Node ID ce3d2f9b19ec075671ba185bb77cde064c049b27
# Parent  8e03783672a372061aa6567e370fc28c5b7bda3b
dirstate: centralize _cwd handling into _cwd method

Before this patch, immediate value is assigned to dirstate._cwd, if
ui.forcecwd is specified at instantiation of dirstate.

But this doesn't work as expected in some cases.

For example, hgweb set ui.forcecwd after instantiation of repo object.
If an extension touches repo.dirstate in its reposetup(), dirstate is
instantiated without setting ui.forcecwd, and dirstate.getcwd()
returns incorrect result.

In addition to it, hgweb.__init__() can take already instantiated repo
object, too. In this case, repo.dirstate might be already
instantiated, even if all enabled extensions don't so in their own
reposetup().

To avoid such issue, this patch centralizes _cwd handling into _cwd
method.

This issue can be reproduced by running test-hgweb-commands.t with
fsmonitor-run-tests.py.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -83,10 +83,6 @@ class dirstate(object):
         # ntpath.join(root, '') of Python 2.7.9 does not add sep if root is
         # UNC path pointing to root share (issue4557)
         self._rootdir = pathutil.normasprefix(root)
-        # internal config: ui.forcecwd
-        forcecwd = ui.config('ui', 'forcecwd')
-        if forcecwd:
-            self._cwd = forcecwd
         self._dirty = False
         self._dirtypl = False
         self._lastnormaltime = 0
@@ -299,6 +295,10 @@ class dirstate(object):
 
     @propertycache
     def _cwd(self):
+        # internal config: ui.forcecwd
+        forcecwd = self._ui.config('ui', 'forcecwd')
+        if forcecwd:
+            return forcecwd
         return pycompat.getcwd()
 
     def getcwd(self):


More information about the Mercurial-devel mailing list