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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date July 2, 2017, 5:53 p.m.
Message ID <ce3d2f9b19ec075671ba.1499017998@speaknoevil>
Download mbox | patch
Permalink /patch/21921/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - July 2, 2017, 5:53 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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.
Yuya Nishihara - July 4, 2017, 2:06 p.m.
On Mon, 03 Jul 2017 02:53:18 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@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

Queued up to here, thanks.

Patch

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):