dirstate: call and cache os.getcwd() in constructor
authorMartin von Zweigbergk <martinvonz@google.com>
Sun, 10 Feb 2019 21:33:21 -0800
changeset 41674 e178b131906a
parent 41673 1db5ae4b0dda
child 41675 ddbebce94665
dirstate: call and cache os.getcwd() in constructor I'm about to make scmutil.matchfiles() not pass the root and cwd paths to match.exact(), since they no longer have any effect. That turned out to have the surprising effect of making some tests (test-rebase-scenario-global.t and test-removeemptydirs.t) crash when the working directory was removed. The problem was that my patch removed the call to repo.getcwd(), which caused the current working directory to not be cached in the dirstate as early as it was before. This patch fixes that by caching the current working directory in the dirstate constructor. Differential Revision: https://phab.mercurial-scm.org/D5928
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Sun Feb 10 14:16:37 2019 -0800
+++ b/mercurial/dirstate.py	Sun Feb 10 21:33:21 2019 -0800
@@ -81,6 +81,10 @@
         self._origpl = None
         self._updatedfiles = set()
         self._mapcls = dirstatemap
+        # Access and cache cwd early, so we don't access it for the first time
+        # after a working-copy update caused it to not exist (accessing it then
+        # raises an exception).
+        self._cwd
 
     @contextlib.contextmanager
     def parentchange(self):