D1313: dirstate: gate access to self._map.dirs

mbolin (Michael Bolin) phabricator at mercurial-scm.org
Fri Nov 3 18:59:43 EDT 2017


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

REVISION SUMMARY
  `_droppath()` already checks `"dirs" in self._map.__dict__` before accessing
  `self._map.dirs`. This updates `_addpath()` to be equally cautious.

REPOSITORY
  rHG Mercurial

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

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
@@ -388,7 +388,7 @@
         return self._map.copymap
 
     def _droppath(self, f):
-        if self[f] not in "?r" and "dirs" in self._map.__dict__:
+        if "dirs" in self._map.__dict__ and self[f] not in "?r":
             self._map.dirs.delpath(f)
 
         if "filefoldmap" in self._map.__dict__:
@@ -402,16 +402,17 @@
         oldstate = self[f]
         if state == 'a' or oldstate == 'r':
             scmutil.checkfilename(f)
-            if f in self._map.dirs:
-                raise error.Abort(_('directory %r already in dirstate') % f)
-            # shadows
-            for d in util.finddirs(f):
-                if d in self._map.dirs:
-                    break
-                entry = self._map.get(d)
-                if entry is not None and entry[0] != 'r':
-                    raise error.Abort(
-                        _('file %r in dirstate clashes with %r') % (d, f))
+            if "dirs" in self._map.__dict__:
+                if f in self._map.dirs:
+                    raise error.Abort(_('directory %r already in dirstate') % f)
+                # shadows
+                for d in util.finddirs(f):
+                    if d in self._map.dirs:
+                        break
+                    entry = self._map.get(d)
+                    if entry is not None and entry[0] != 'r':
+                        raise error.Abort(
+                            _('file %r in dirstate clashes with %r') % (d, f))
         if oldstate in "?r" and "dirs" in self._map.__dict__:
             self._map.dirs.addpath(f)
         self._dirty = True



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


More information about the Mercurial-devel mailing list