D5928: dirstate: call and cache os.getcwd() in constructor

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Feb 11 05:52:49 UTC 2019


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5928

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -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):



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list