comparison mercurial/localrepo.py @ 43106:d783f945a701

py3: finish porting iteritems() to pycompat and remove source transformer This commit finishes porting .iteritems() to pycompat.iteritems() for the mercurial package. The translation of .iteritems() to .items() was the last conversion performed by the source transformer. With the porting to pycompat complete, we no longer have a need for the source transformer. So the source transformer has been removed. Good riddance! The code base is now compatible with Python 2 and Python 3. For the record, as the person who introduced the source transformer, it brings me joy to delete it. It accomplished its goal to facilitate a port to Python 3 without overly burdening people on some painful low-level differences between Python 2 and 3. It is unfortunate we still have to wallpaper over many differences with the pycompat shim. But it is what it is. Differential Revision: https://phab.mercurial-scm.org/D7015
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 07 Oct 2019 00:04:04 -0400
parents 74802979dd9d
children 8ff1ecfadcd1
comparison
equal deleted inserted replaced
43105:649d3ac37a12 43106:d783f945a701
1687 if self.changelog.filteredrevs: 1687 if self.changelog.filteredrevs:
1688 tags, tt = self._findtags() 1688 tags, tt = self._findtags()
1689 else: 1689 else:
1690 tags = self._tagscache.tags 1690 tags = self._tagscache.tags
1691 rev = self.changelog.rev 1691 rev = self.changelog.rev
1692 for k, v in tags.iteritems(): 1692 for k, v in pycompat.iteritems(tags):
1693 try: 1693 try:
1694 # ignore tags to unknown nodes 1694 # ignore tags to unknown nodes
1695 rev(v) 1695 rev(v)
1696 t[k] = v 1696 t[k] = v
1697 except (error.LookupError, ValueError): 1697 except (error.LookupError, ValueError):
1722 # Build the return dicts. Have to re-encode tag names because 1722 # Build the return dicts. Have to re-encode tag names because
1723 # the tags module always uses UTF-8 (in order not to lose info 1723 # the tags module always uses UTF-8 (in order not to lose info
1724 # writing to the cache), but the rest of Mercurial wants them in 1724 # writing to the cache), but the rest of Mercurial wants them in
1725 # local encoding. 1725 # local encoding.
1726 tags = {} 1726 tags = {}
1727 for (name, (node, hist)) in alltags.iteritems(): 1727 for (name, (node, hist)) in pycompat.iteritems(alltags):
1728 if node != nullid: 1728 if node != nullid:
1729 tags[encoding.tolocal(name)] = node 1729 tags[encoding.tolocal(name)] = node
1730 tags[b'tip'] = self.changelog.tip() 1730 tags[b'tip'] = self.changelog.tip()
1731 tagtypes = dict( 1731 tagtypes = dict(
1732 [ 1732 [
1733 (encoding.tolocal(name), value) 1733 (encoding.tolocal(name), value)
1734 for (name, value) in tagtypes.iteritems() 1734 for (name, value) in pycompat.iteritems(tagtypes)
1735 ] 1735 ]
1736 ) 1736 )
1737 return (tags, tagtypes) 1737 return (tags, tagtypes)
1738 1738
1739 def tagtype(self, tagname): 1739 def tagtype(self, tagname):
1749 1749
1750 def tagslist(self): 1750 def tagslist(self):
1751 '''return a list of tags ordered by revision''' 1751 '''return a list of tags ordered by revision'''
1752 if not self._tagscache.tagslist: 1752 if not self._tagscache.tagslist:
1753 l = [] 1753 l = []
1754 for t, n in self.tags().iteritems(): 1754 for t, n in pycompat.iteritems(self.tags()):
1755 l.append((self.changelog.rev(n), t, n)) 1755 l.append((self.changelog.rev(n), t, n))
1756 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] 1756 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
1757 1757
1758 return self._tagscache.tagslist 1758 return self._tagscache.tagslist
1759 1759
1760 def nodetags(self, node): 1760 def nodetags(self, node):
1761 '''return the tags associated with a node''' 1761 '''return the tags associated with a node'''
1762 if not self._tagscache.nodetagscache: 1762 if not self._tagscache.nodetagscache:
1763 nodetagscache = {} 1763 nodetagscache = {}
1764 for t, n in self._tagscache.tags.iteritems(): 1764 for t, n in pycompat.iteritems(self._tagscache.tags):
1765 nodetagscache.setdefault(n, []).append(t) 1765 nodetagscache.setdefault(n, []).append(t)
1766 for tags in pycompat.itervalues(nodetagscache): 1766 for tags in pycompat.itervalues(nodetagscache):
1767 tags.sort() 1767 tags.sort()
1768 self._tagscache.nodetagscache = nodetagscache 1768 self._tagscache.nodetagscache = nodetagscache
1769 return self._tagscache.nodetagscache.get(node, []) 1769 return self._tagscache.nodetagscache.get(node, [])
1884 if cmd == b'!': 1884 if cmd == b'!':
1885 continue 1885 continue
1886 mf = matchmod.match(self.root, b'', [pat]) 1886 mf = matchmod.match(self.root, b'', [pat])
1887 fn = None 1887 fn = None
1888 params = cmd 1888 params = cmd
1889 for name, filterfn in self._datafilters.iteritems(): 1889 for name, filterfn in pycompat.iteritems(self._datafilters):
1890 if cmd.startswith(name): 1890 if cmd.startswith(name):
1891 fn = filterfn 1891 fn = filterfn
1892 params = cmd[len(name) :].lstrip() 1892 params = cmd[len(name) :].lstrip()
1893 break 1893 break
1894 if not fn: 1894 if not fn: