comparison hgext/convert/subversion.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 eef9a2d67051
children 8ff1ecfadcd1
comparison
equal deleted inserted replaced
43104:74802979dd9d 43105:649d3ac37a12
149 protocol = -1 149 protocol = -1
150 150
151 def receiver(orig_paths, revnum, author, date, message, pool): 151 def receiver(orig_paths, revnum, author, date, message, pool):
152 paths = {} 152 paths = {}
153 if orig_paths is not None: 153 if orig_paths is not None:
154 for k, v in orig_paths.iteritems(): 154 for k, v in pycompat.iteritems(orig_paths):
155 paths[k] = changedpath(v) 155 paths[k] = changedpath(v)
156 pickle.dump((paths, revnum, author, date, message), fp, protocol) 156 pickle.dump((paths, revnum, author, date, message), fp, protocol)
157 157
158 try: 158 try:
159 # Use an ra of our own so that our parent can consume 159 # Use an ra of our own so that our parent can consume
243 strict_node_history=False, 243 strict_node_history=False,
244 ): 244 ):
245 def receiver(orig_paths, revnum, author, date, message, pool): 245 def receiver(orig_paths, revnum, author, date, message, pool):
246 paths = {} 246 paths = {}
247 if orig_paths is not None: 247 if orig_paths is not None:
248 for k, v in orig_paths.iteritems(): 248 for k, v in pycompat.iteritems(orig_paths):
249 paths[k] = changedpath(v) 249 paths[k] = changedpath(v)
250 self.append((paths, revnum, author, date, message)) 250 self.append((paths, revnum, author, date, message))
251 251
252 # Use an ra of our own so that our parent can consume 252 # Use an ra of our own so that our parent can consume
253 # our results without confusing the server. 253 # our results without confusing the server.
589 entries = svn.client.ls( 589 entries = svn.client.ls(
590 self.baseurl + quote(module), optrev(revnum), True, self.ctx 590 self.baseurl + quote(module), optrev(revnum), True, self.ctx
591 ) 591 )
592 files = [ 592 files = [
593 n 593 n
594 for n, e in entries.iteritems() 594 for n, e in pycompat.iteritems(entries)
595 if e.kind == svn.core.svn_node_file 595 if e.kind == svn.core.svn_node_file
596 ] 596 ]
597 self.removed = set() 597 self.removed = set()
598 598
599 files.sort() 599 files.sort()
679 origpaths, revnum, author, date, message = entry 679 origpaths, revnum, author, date, message = entry
680 if not origpaths: 680 if not origpaths:
681 origpaths = [] 681 origpaths = []
682 copies = [ 682 copies = [
683 (e.copyfrom_path, e.copyfrom_rev, p) 683 (e.copyfrom_path, e.copyfrom_rev, p)
684 for p, e in origpaths.iteritems() 684 for p, e in pycompat.iteritems(origpaths)
685 if e.copyfrom_path 685 if e.copyfrom_path
686 ] 686 ]
687 # Apply moves/copies from more specific to general 687 # Apply moves/copies from more specific to general
688 copies.sort(reverse=True) 688 copies.sort(reverse=True)
689 689
710 # Here/tags/tag.1 discarded as well as its children. 710 # Here/tags/tag.1 discarded as well as its children.
711 # It happens with tools like cvs2svn. Such tags cannot 711 # It happens with tools like cvs2svn. Such tags cannot
712 # be represented in mercurial. 712 # be represented in mercurial.
713 addeds = dict( 713 addeds = dict(
714 (p, e.copyfrom_path) 714 (p, e.copyfrom_path)
715 for p, e in origpaths.iteritems() 715 for p, e in pycompat.iteritems(origpaths)
716 if e.action == b'A' and e.copyfrom_path 716 if e.action == b'A' and e.copyfrom_path
717 ) 717 )
718 badroots = set() 718 badroots = set()
719 for destroot in addeds: 719 for destroot in addeds:
720 for source, sourcerev, dest in pendings: 720 for source, sourcerev, dest in pendings:
999 return None, branched 999 return None, branched
1000 1000
1001 parents = [] 1001 parents = []
1002 # check whether this revision is the start of a branch or part 1002 # check whether this revision is the start of a branch or part
1003 # of a branch renaming 1003 # of a branch renaming
1004 orig_paths = sorted(orig_paths.iteritems()) 1004 orig_paths = sorted(pycompat.iteritems(orig_paths))
1005 root_paths = [ 1005 root_paths = [
1006 (p, e) for p, e in orig_paths if self.module.startswith(p) 1006 (p, e) for p, e in orig_paths if self.module.startswith(p)
1007 ] 1007 ]
1008 if root_paths: 1008 if root_paths:
1009 path, ent = root_paths[-1] 1009 path, ent = root_paths[-1]
1166 entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool) 1166 entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool)
1167 if path: 1167 if path:
1168 path += b'/' 1168 path += b'/'
1169 return ( 1169 return (
1170 (path + p) 1170 (path + p)
1171 for p, e in entries.iteritems() 1171 for p, e in pycompat.iteritems(entries)
1172 if e.kind == svn.core.svn_node_file 1172 if e.kind == svn.core.svn_node_file
1173 ) 1173 )
1174 1174
1175 def getrelpath(self, path, module=None): 1175 def getrelpath(self, path, module=None):
1176 if module is None: 1176 if module is None: