comparison mercurial/copies.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 687b865b95ad
children 8ff1ecfadcd1
comparison
equal deleted inserted replaced
43105:649d3ac37a12 43106:d783f945a701
15 15
16 from . import ( 16 from . import (
17 match as matchmod, 17 match as matchmod,
18 node, 18 node,
19 pathutil, 19 pathutil,
20 pycompat,
20 util, 21 util,
21 ) 22 )
22 from .utils import stringutil 23 from .utils import stringutil
23 24
24 25
142 143
143 144
144 def _chain(a, b): 145 def _chain(a, b):
145 """chain two sets of copies 'a' and 'b'""" 146 """chain two sets of copies 'a' and 'b'"""
146 t = a.copy() 147 t = a.copy()
147 for k, v in b.iteritems(): 148 for k, v in pycompat.iteritems(b):
148 if v in t: 149 if v in t:
149 t[k] = t[v] 150 t[k] = t[v]
150 else: 151 else:
151 t[k] = v 152 t[k] = v
152 return t 153 return t
351 # We don't want to pass in "match" here, since that would filter 352 # We don't want to pass in "match" here, since that would filter
352 # the destination by it. Since we're reversing the copies, we want 353 # the destination by it. Since we're reversing the copies, we want
353 # to filter the source instead. 354 # to filter the source instead.
354 f = _forwardcopies(b, a) 355 f = _forwardcopies(b, a)
355 r = {} 356 r = {}
356 for k, v in sorted(f.iteritems()): 357 for k, v in sorted(pycompat.iteritems(f)):
357 if match and not match(v): 358 if match and not match(v):
358 continue 359 continue
359 # remove copies 360 # remove copies
360 if v in a: 361 if v in a:
361 continue 362 continue
630 invalid = set() 631 invalid = set()
631 dirmove = {} 632 dirmove = {}
632 633
633 # examine each file copy for a potential directory move, which is 634 # examine each file copy for a potential directory move, which is
634 # when all the files in a directory are moved to a new directory 635 # when all the files in a directory are moved to a new directory
635 for dst, src in fullcopy.iteritems(): 636 for dst, src in pycompat.iteritems(fullcopy):
636 dsrc, ddst = pathutil.dirname(src), pathutil.dirname(dst) 637 dsrc, ddst = pathutil.dirname(src), pathutil.dirname(dst)
637 if dsrc in invalid: 638 if dsrc in invalid:
638 # already seen to be uninteresting 639 # already seen to be uninteresting
639 continue 640 continue
640 elif dsrc in d1 and ddst in d1: 641 elif dsrc in d1 and ddst in d1:
656 del d1, d2, invalid 657 del d1, d2, invalid
657 658
658 if not dirmove: 659 if not dirmove:
659 return copy, {}, diverge, renamedelete, {} 660 return copy, {}, diverge, renamedelete, {}
660 661
661 dirmove = {k + b"/": v + b"/" for k, v in dirmove.iteritems()} 662 dirmove = {k + b"/": v + b"/" for k, v in pycompat.iteritems(dirmove)}
662 663
663 for d in dirmove: 664 for d in dirmove:
664 repo.ui.debug( 665 repo.ui.debug(
665 b" discovered dir src: '%s' -> dst: '%s'\n" % (d, dirmove[d]) 666 b" discovered dir src: '%s' -> dst: '%s'\n" % (d, dirmove[d])
666 ) 667 )
734 return _fullcopytracing(repo, c1, c2, base) 735 return _fullcopytracing(repo, c1, c2, base)
735 changedfiles.update(ctx.files()) 736 changedfiles.update(ctx.files())
736 ctx = ctx.p1() 737 ctx = ctx.p1()
737 738
738 cp = _forwardcopies(base, c2) 739 cp = _forwardcopies(base, c2)
739 for dst, src in cp.iteritems(): 740 for dst, src in pycompat.iteritems(cp):
740 if src in m1: 741 if src in m1:
741 copies[dst] = src 742 copies[dst] = src
742 743
743 # file is missing if it isn't present in the destination, but is present in 744 # file is missing if it isn't present in the destination, but is present in
744 # the base and present in the source. 745 # the base and present in the source.
843 # copytrace='off' skips this line, but not the entire function because 844 # copytrace='off' skips this line, but not the entire function because
844 # the line below is O(size of the repo) during a rebase, while the rest 845 # the line below is O(size of the repo) during a rebase, while the rest
845 # of the function is much faster (and is required for carrying copy 846 # of the function is much faster (and is required for carrying copy
846 # metadata across the rebase anyway). 847 # metadata across the rebase anyway).
847 exclude = pathcopies(repo[fromrev], repo[skiprev]) 848 exclude = pathcopies(repo[fromrev], repo[skiprev])
848 for dst, src in pathcopies(repo[fromrev], repo[rev]).iteritems(): 849 for dst, src in pycompat.iteritems(pathcopies(repo[fromrev], repo[rev])):
849 if dst in exclude: 850 if dst in exclude:
850 continue 851 continue
851 if dst in wctx: 852 if dst in wctx:
852 wctx[dst].markcopied(src) 853 wctx[dst].markcopied(src)
853 854