contrib: fix dirstatenonnormalcheck to work in Python 3
authorAugie Fackler <augie@google.com>
Thu, 01 Feb 2018 16:01:43 -0500
changeset 35918 6e7fae8f1c6c
parent 35917 11fdf1486519
child 35919 6c1d3779c052
contrib: fix dirstatenonnormalcheck to work in Python 3 This is a redo of D1963 that has the added benefit of not breaking Python 2. Oops. # skip-blame because this is bytes prefixes and a s/iteritems/items/ Differential Revision: https://phab.mercurial-scm.org/D1970
contrib/dirstatenonnormalcheck.py
mercurial/dirstate.py
--- a/contrib/dirstatenonnormalcheck.py	Thu Jan 18 13:12:09 2018 -0500
+++ b/contrib/dirstatenonnormalcheck.py	Thu Feb 01 16:01:43 2018 -0500
@@ -17,7 +17,7 @@
     """Compute nonnormal entries from dirstate's dmap"""
     res = set()
     for f, e in dmap.iteritems():
-        if e[0] != 'n' or e[3] == -1:
+        if e[0] != b'n' or e[3] == -1:
             res.add(f)
     return res
 
@@ -25,24 +25,25 @@
     """Compute nonnormalset from dmap, check that it matches _nonnormalset"""
     nonnormalcomputedmap = nonnormalentries(dmap)
     if _nonnormalset != nonnormalcomputedmap:
-        ui.develwarn("%s call to %s\n" % (label, orig), config='dirstate')
-        ui.develwarn("inconsistency in nonnormalset\n", config='dirstate')
-        ui.develwarn("[nonnormalset] %s\n" % _nonnormalset, config='dirstate')
-        ui.develwarn("[map] %s\n" % nonnormalcomputedmap, config='dirstate')
+        ui.develwarn(b"%s call to %s\n" % (label, orig), config=b'dirstate')
+        ui.develwarn(b"inconsistency in nonnormalset\n", config=b'dirstate')
+        ui.develwarn(b"[nonnormalset] %s\n" % _nonnormalset, config=b'dirstate')
+        ui.develwarn(b"[map] %s\n" % nonnormalcomputedmap, config=b'dirstate')
 
 def _checkdirstate(orig, self, arg):
     """Check nonnormal set consistency before and after the call to orig"""
     checkconsistency(self._ui, orig, self._map, self._map.nonnormalset,
-                     "before")
+                     b"before")
     r = orig(self, arg)
-    checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, "after")
+    checkconsistency(self._ui, orig, self._map, self._map.nonnormalset,
+                     b"after")
     return r
 
 def extsetup(ui):
     """Wrap functions modifying dirstate to check nonnormalset consistency"""
     dirstatecl = dirstate.dirstate
-    devel = ui.configbool('devel', 'all-warnings')
-    paranoid = ui.configbool('experimental', 'nonnormalparanoidcheck')
+    devel = ui.configbool(b'devel', b'all-warnings')
+    paranoid = ui.configbool(b'experimental', b'nonnormalparanoidcheck')
     if devel:
         extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate)
         if paranoid:
--- a/mercurial/dirstate.py	Thu Jan 18 13:12:09 2018 -0500
+++ b/mercurial/dirstate.py	Thu Feb 01 16:01:43 2018 -0500
@@ -1237,9 +1237,12 @@
         util.clearcachedproperty(self, "nonnormalset")
         util.clearcachedproperty(self, "otherparentset")
 
-    def iteritems(self):
+    def items(self):
         return self._map.iteritems()
 
+    # forward for python2,3 compat
+    iteritems = items
+
     def __len__(self):
         return len(self._map)