comparison 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
comparison
equal deleted inserted replaced
43104:74802979dd9d 43105:649d3ac37a12
376 return orig(pushop) 376 return orig(pushop)
377 377
378 378
379 def wireprotolistkeyspatterns(repo, proto, namespace, patterns): 379 def wireprotolistkeyspatterns(repo, proto, namespace, patterns):
380 patterns = wireprototypes.decodelist(patterns) 380 patterns = wireprototypes.decodelist(patterns)
381 d = repo.listkeys(encoding.tolocal(namespace), patterns).iteritems() 381 d = pycompat.iteritems(repo.listkeys(encoding.tolocal(namespace), patterns))
382 return pushkey.encodekeys(d) 382 return pushkey.encodekeys(d)
383 383
384 384
385 def localrepolistkeys(orig, self, namespace, patterns=None): 385 def localrepolistkeys(orig, self, namespace, patterns=None):
386 if namespace == b'bookmarks' and patterns: 386 if namespace == b'bookmarks' and patterns:
390 for pattern in patterns: 390 for pattern in patterns:
391 results.update(index.getbookmarks(pattern)) 391 results.update(index.getbookmarks(pattern))
392 if pattern.endswith(b'*'): 392 if pattern.endswith(b'*'):
393 pattern = b're:^' + pattern[:-1] + b'.*' 393 pattern = b're:^' + pattern[:-1] + b'.*'
394 kind, pat, matcher = stringutil.stringmatcher(pattern) 394 kind, pat, matcher = stringutil.stringmatcher(pattern)
395 for bookmark, node in bookmarks.iteritems(): 395 for bookmark, node in pycompat.iteritems(bookmarks):
396 if matcher(bookmark): 396 if matcher(bookmark):
397 results[bookmark] = node 397 results[bookmark] = node
398 return results 398 return results
399 else: 399 else:
400 return orig(self, namespace) 400 return orig(self, namespace)
512 haschangegroup = False 512 haschangegroup = False
513 for part in unbundler.iterparts(): 513 for part in unbundler.iterparts():
514 if part.type == b'changegroup': 514 if part.type == b'changegroup':
515 haschangegroup = True 515 haschangegroup = True
516 newpart = bundle2.bundlepart(part.type, data=part.read()) 516 newpart = bundle2.bundlepart(part.type, data=part.read())
517 for key, value in part.params.iteritems(): 517 for key, value in pycompat.iteritems(part.params):
518 newpart.addparam(key, value) 518 newpart.addparam(key, value)
519 parts.append(newpart) 519 parts.append(newpart)
520 520
521 if not haschangegroup: 521 if not haschangegroup:
522 raise error.Abort( 522 raise error.Abort(
755 bookmarks[rname] = hexnode 755 bookmarks[rname] = hexnode
756 elif nametype == b'branches': 756 elif nametype == b'branches':
757 # saveremotenames expects 20 byte binary nodes for branches 757 # saveremotenames expects 20 byte binary nodes for branches
758 branches[rname].append(bin(hexnode)) 758 branches[rname].append(bin(hexnode))
759 759
760 for bookmark, hexnode in newbookmarks.iteritems(): 760 for bookmark, hexnode in pycompat.iteritems(newbookmarks):
761 bookmarks[bookmark] = hexnode 761 bookmarks[bookmark] = hexnode
762 remotenamesext.saveremotenames(repo, remotepath, branches, bookmarks) 762 remotenamesext.saveremotenames(repo, remotepath, branches, bookmarks)
763 763
764 764
765 def _savelocalbookmarks(repo, bookmarks): 765 def _savelocalbookmarks(repo, bookmarks):
766 if not bookmarks: 766 if not bookmarks:
767 return 767 return
768 with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr: 768 with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr:
769 changes = [] 769 changes = []
770 for scratchbook, node in bookmarks.iteritems(): 770 for scratchbook, node in pycompat.iteritems(bookmarks):
771 changectx = repo[node] 771 changectx = repo[node]
772 changes.append((scratchbook, changectx.node())) 772 changes.append((scratchbook, changectx.node()))
773 repo._bookmarks.applychanges(repo, tr, changes) 773 repo._bookmarks.applychanges(repo, tr, changes)
774 774
775 775
1003 if part.type == b'replycaps': 1003 if part.type == b'replycaps':
1004 # This configures the current operation to allow reply parts. 1004 # This configures the current operation to allow reply parts.
1005 bundle2._processpart(op, part) 1005 bundle2._processpart(op, part)
1006 else: 1006 else:
1007 bundlepart = bundle2.bundlepart(part.type, data=part.read()) 1007 bundlepart = bundle2.bundlepart(part.type, data=part.read())
1008 for key, value in part.params.iteritems(): 1008 for key, value in pycompat.iteritems(part.params):
1009 bundlepart.addparam(key, value) 1009 bundlepart.addparam(key, value)
1010 1010
1011 # Certain parts require a response 1011 # Certain parts require a response
1012 if part.type in (b'pushkey', b'changegroup'): 1012 if part.type in (b'pushkey', b'changegroup'):
1013 if op.reply is not None: 1013 if op.reply is not None:
1090 # Ideally we would not process any parts, and instead just 1090 # Ideally we would not process any parts, and instead just
1091 # forward them to the bundle for storage, but since this 1091 # forward them to the bundle for storage, but since this
1092 # differs from previous behavior, we need to put it behind a 1092 # differs from previous behavior, we need to put it behind a
1093 # config flag for incremental rollout. 1093 # config flag for incremental rollout.
1094 bundlepart = bundle2.bundlepart(part.type, data=part.read()) 1094 bundlepart = bundle2.bundlepart(part.type, data=part.read())
1095 for key, value in part.params.iteritems(): 1095 for key, value in pycompat.iteritems(part.params):
1096 bundlepart.addparam(key, value) 1096 bundlepart.addparam(key, value)
1097 1097
1098 # Certain parts require a response 1098 # Certain parts require a response
1099 if part.type == b'pushkey': 1099 if part.type == b'pushkey':
1100 if op.reply is not None: 1100 if op.reply is not None:
1271 b'namespace': b'bookmarks', 1271 b'namespace': b'bookmarks',
1272 b'key': bookmark, 1272 b'key': bookmark,
1273 b'new': newnode, 1273 b'new': newnode,
1274 b'old': oldnode, 1274 b'old': oldnode,
1275 } 1275 }
1276 op.reply.newpart(b'pushkey', mandatoryparams=params.iteritems()) 1276 op.reply.newpart(
1277 b'pushkey', mandatoryparams=pycompat.iteritems(params)
1278 )
1277 1279
1278 1280
1279 def bundle2pushkey(orig, op, part): 1281 def bundle2pushkey(orig, op, part):
1280 '''Wrapper of bundle2.handlepushkey() 1282 '''Wrapper of bundle2.handlepushkey()
1281 1283