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.
--- a/mercurial/dirstate.py Mon Jul 03 02:52:39 2017 +0900
+++ b/mercurial/dirstate.py Mon Jul 03 02:52:40 2017 +0900
@@ -83,10 +83,6 @@
# 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 @@
@propertycache
def _cwd(self):
+ # internal config: ui.forcecwd
+ forcecwd = self._ui.config('ui', 'forcecwd')
+ if forcecwd:
+ return forcecwd
return pycompat.getcwd()
def getcwd(self):