diff hgext/infinitepush/__init__.py @ 43105:649d3ac37a12

py3: define and use pycompat.iteritems() for hgext/ .iteritems() -> .items() is the last source transform being performed. But it is also the most widely used. This commit adds a pycompat.iteritems symbol and imports it in place of .iteritems() for usage in hgext/. I chose to stop at just hgext/ because the patch will be large and it is an easy boundary to stop at since we can disable source transformation on a per-package basis. There are places where the type does implement items() and we could call items() directly. However, this would require critical thought and I thought it would be easier to just blindly change the code. We know which call sites need to be audited in the future because they have "pycompat.iteritems." With this change, we no longer perform source transformation on hgext! Differential Revision: https://phab.mercurial-scm.org/D7014
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Oct 2019 19:25:18 -0400
parents c59eb1560c44
children e5d535621ee1
line wrap: on
line diff
--- a/hgext/infinitepush/__init__.py	Sun Oct 06 17:59:15 2019 -0400
+++ b/hgext/infinitepush/__init__.py	Sun Oct 06 19:25:18 2019 -0400
@@ -378,7 +378,7 @@
 
 def wireprotolistkeyspatterns(repo, proto, namespace, patterns):
     patterns = wireprototypes.decodelist(patterns)
-    d = repo.listkeys(encoding.tolocal(namespace), patterns).iteritems()
+    d = pycompat.iteritems(repo.listkeys(encoding.tolocal(namespace), patterns))
     return pushkey.encodekeys(d)
 
 
@@ -392,7 +392,7 @@
             if pattern.endswith(b'*'):
                 pattern = b're:^' + pattern[:-1] + b'.*'
             kind, pat, matcher = stringutil.stringmatcher(pattern)
-            for bookmark, node in bookmarks.iteritems():
+            for bookmark, node in pycompat.iteritems(bookmarks):
                 if matcher(bookmark):
                     results[bookmark] = node
         return results
@@ -514,7 +514,7 @@
                     if part.type == b'changegroup':
                         haschangegroup = True
                     newpart = bundle2.bundlepart(part.type, data=part.read())
-                    for key, value in part.params.iteritems():
+                    for key, value in pycompat.iteritems(part.params):
                         newpart.addparam(key, value)
                     parts.append(newpart)
 
@@ -757,7 +757,7 @@
             # saveremotenames expects 20 byte binary nodes for branches
             branches[rname].append(bin(hexnode))
 
-    for bookmark, hexnode in newbookmarks.iteritems():
+    for bookmark, hexnode in pycompat.iteritems(newbookmarks):
         bookmarks[bookmark] = hexnode
     remotenamesext.saveremotenames(repo, remotepath, branches, bookmarks)
 
@@ -767,7 +767,7 @@
         return
     with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr:
         changes = []
-        for scratchbook, node in bookmarks.iteritems():
+        for scratchbook, node in pycompat.iteritems(bookmarks):
             changectx = repo[node]
             changes.append((scratchbook, changectx.node()))
         repo._bookmarks.applychanges(repo, tr, changes)
@@ -1005,7 +1005,7 @@
                 bundle2._processpart(op, part)
             else:
                 bundlepart = bundle2.bundlepart(part.type, data=part.read())
-                for key, value in part.params.iteritems():
+                for key, value in pycompat.iteritems(part.params):
                     bundlepart.addparam(key, value)
 
                 # Certain parts require a response
@@ -1092,7 +1092,7 @@
                     # differs from previous behavior, we need to put it behind a
                     # config flag for incremental rollout.
                     bundlepart = bundle2.bundlepart(part.type, data=part.read())
-                    for key, value in part.params.iteritems():
+                    for key, value in pycompat.iteritems(part.params):
                         bundlepart.addparam(key, value)
 
                     # Certain parts require a response
@@ -1273,7 +1273,9 @@
                 b'new': newnode,
                 b'old': oldnode,
             }
-            op.reply.newpart(b'pushkey', mandatoryparams=params.iteritems())
+            op.reply.newpart(
+                b'pushkey', mandatoryparams=pycompat.iteritems(params)
+            )
 
 
 def bundle2pushkey(orig, op, part):