comparison hgext/fastannotate/context.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 be384a2052aa
comparison
equal deleted inserted replaced
43104:74802979dd9d 43105:649d3ac37a12
167 b'followmerge': True, 167 b'followmerge': True,
168 } 168 }
169 169
170 def __init__(self, **opts): 170 def __init__(self, **opts):
171 opts = pycompat.byteskwargs(opts) 171 opts = pycompat.byteskwargs(opts)
172 for k, v in self.defaults.iteritems(): 172 for k, v in pycompat.iteritems(self.defaults):
173 setattr(self, k, opts.get(k, v)) 173 setattr(self, k, opts.get(k, v))
174 174
175 @util.propertycache 175 @util.propertycache
176 def shortstr(self): 176 def shortstr(self):
177 """represent opts in a short string, suitable for a directory name""" 177 """represent opts in a short string, suitable for a directory name"""
576 key2idxs[(revs[i], annotateresult[i][1])].append(i) 576 key2idxs[(revs[i], annotateresult[i][1])].append(i)
577 while key2idxs: 577 while key2idxs:
578 # find an unresolved line and its linelog rev to annotate 578 # find an unresolved line and its linelog rev to annotate
579 hsh = None 579 hsh = None
580 try: 580 try:
581 for (rev, _linenum), idxs in key2idxs.iteritems(): 581 for (rev, _linenum), idxs in pycompat.iteritems(key2idxs):
582 if revmap.rev2flag(rev) & revmapmod.sidebranchflag: 582 if revmap.rev2flag(rev) & revmapmod.sidebranchflag:
583 continue 583 continue
584 hsh = annotateresult[idxs[0]][0] 584 hsh = annotateresult[idxs[0]][0]
585 break 585 break
586 except StopIteration: # no more unresolved lines 586 except StopIteration: # no more unresolved lines
587 return result 587 return result
588 if hsh is None: 588 if hsh is None:
589 # the remaining key2idxs are not in main branch, resolving them 589 # the remaining key2idxs are not in main branch, resolving them
590 # using the hard way... 590 # using the hard way...
591 revlines = {} 591 revlines = {}
592 for (rev, linenum), idxs in key2idxs.iteritems(): 592 for (rev, linenum), idxs in pycompat.iteritems(key2idxs):
593 if rev not in revlines: 593 if rev not in revlines:
594 hsh = annotateresult[idxs[0]][0] 594 hsh = annotateresult[idxs[0]][0]
595 if self.ui.debugflag: 595 if self.ui.debugflag:
596 self.ui.debug( 596 self.ui.debug(
597 b'fastannotate: reading %s line #%d ' 597 b'fastannotate: reading %s line #%d '