Patchwork D6669: py: error out if a "skip" character was given with non-dict to util.dirs()

login
register
mail settings
Submitter phabricator
Date July 22, 2019, 5:06 p.m.
Message ID <differential-rev-PHID-DREV-kh6fmerk2skczkn7tcok-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41002/
State Superseded
Headers show

Comments

phabricator - July 22, 2019, 5:06 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  util.dirs() keeps track of the directories in its input collection. If
  a "skip" character is given to it, it will assume the input is a
  dirstate map and it will skip entries that are in the given "skip"
  state. I think this is used only for skipping removed entries ("r") in
  the dirtate. The C implementation of util.dirs() errors out if it was
  given a skip character and a non-dict was passed. The pure
  implementation simply ignored the request skip state. Let's make it
  easier to discover bugs here by erroring out in the pure
  implementation too. Let's also switch to checking for the dict-ness,
  to make the C implementation (since that's clearly been sufficient for
  many years). This last change makes test-issue660.t pass on py3 in
  pure mode, since the old check was for existence of iteritems(), which
  doesn't exist on py3.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -3173,10 +3173,13 @@ 
     def __init__(self, map, skip=None):
         self._dirs = {}
         addpath = self.addpath
-        if safehasattr(map, 'iteritems') and skip is not None:
+        if isinstance(map, dict) and skip is not None:
             for f, s in map.iteritems():
                 if s[0] != skip:
                     addpath(f)
+        elif skip is not None:
+            raise error.ProgrammingError("skip character is only supported "
+                                         "with a dict source")
         else:
             for f in map:
                 addpath(f)