comparison mercurial/merge.py @ 48913:f254fc73d956

global: bulk replace simple pycompat.iteritems(x) with x.items() pycompat.iteritems() just calls .items(). This commit applies a regular expression search and replace to convert simple instances of pycompat.iteritems() with .items(). There are still a handful of calls to pycompat.iteritems() remaining. But these all have more complicated expressions that I wasn't comfortable performing an automated replace on. In addition, some simple replacements were withheld because they broke pytype. These will be handled by their own changesets. Differential Revision: https://phab.mercurial-scm.org/D12318
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 03 Mar 2022 18:28:30 -0800
parents 6000f5b25c9b
children c17aee610bab
comparison
equal deleted inserted replaced
48912:a0674e916fb6 48913:f254fc73d956
641 641
642 return sum(len(self._actionmapping[a]) for a in actions) 642 return sum(len(self._actionmapping[a]) for a in actions)
643 643
644 def filemap(self, sort=False): 644 def filemap(self, sort=False):
645 if sorted: 645 if sorted:
646 for key, val in sorted(pycompat.iteritems(self._filemapping)): 646 for key, val in sorted(self._filemapping.items()):
647 yield key, val 647 yield key, val
648 else: 648 else:
649 for key, val in pycompat.iteritems(self._filemapping): 649 for key, val in self._filemapping.items():
650 yield key, val 650 yield key, val
651 651
652 def addcommitinfo(self, filename, key, value): 652 def addcommitinfo(self, filename, key, value):
653 """adds key-value information about filename which will be required 653 """adds key-value information about filename which will be required
654 while committing this merge""" 654 while committing this merge"""
669 @property 669 @property
670 def actionsdict(self): 670 def actionsdict(self):
671 """returns a dictionary of actions to be perfomed with action as key 671 """returns a dictionary of actions to be perfomed with action as key
672 and a list of files and related arguments as values""" 672 and a list of files and related arguments as values"""
673 res = collections.defaultdict(list) 673 res = collections.defaultdict(list)
674 for a, d in pycompat.iteritems(self._actionmapping): 674 for a, d in self._actionmapping.items():
675 for f, (args, msg) in pycompat.iteritems(d): 675 for f, (args, msg) in d.items():
676 res[a].append((f, args, msg)) 676 res[a].append((f, args, msg))
677 return res 677 return res
678 678
679 def setactions(self, actions): 679 def setactions(self, actions):
680 self._filemapping = actions 680 self._filemapping = actions
681 self._actionmapping = collections.defaultdict(dict) 681 self._actionmapping = collections.defaultdict(dict)
682 for f, (act, data, msg) in pycompat.iteritems(self._filemapping): 682 for f, (act, data, msg) in self._filemapping.items():
683 self._actionmapping[act][f] = data, msg 683 self._actionmapping[act][f] = data, msg
684 684
685 def hasconflicts(self): 685 def hasconflicts(self):
686 """tells whether this merge resulted in some actions which can 686 """tells whether this merge resulted in some actions which can
687 result in conflicts or not""" 687 result in conflicts or not"""
784 # total m1-vs-m2 diff to just those files. This has significant 784 # total m1-vs-m2 diff to just those files. This has significant
785 # performance benefits in large repositories. 785 # performance benefits in large repositories.
786 relevantfiles = set(ma.diff(m2).keys()) 786 relevantfiles = set(ma.diff(m2).keys())
787 787
788 # For copied and moved files, we need to add the source file too. 788 # For copied and moved files, we need to add the source file too.
789 for copykey, copyvalue in pycompat.iteritems(branch_copies1.copy): 789 for copykey, copyvalue in branch_copies1.copy.items():
790 if copyvalue in relevantfiles: 790 if copyvalue in relevantfiles:
791 relevantfiles.add(copykey) 791 relevantfiles.add(copykey)
792 for movedirkey in branch_copies1.movewithdir: 792 for movedirkey in branch_copies1.movewithdir:
793 relevantfiles.add(movedirkey) 793 relevantfiles.add(movedirkey)
794 filesmatcher = scmutil.matchfiles(repo, relevantfiles) 794 filesmatcher = scmutil.matchfiles(repo, relevantfiles)
795 matcher = matchmod.intersectmatchers(matcher, filesmatcher) 795 matcher = matchmod.intersectmatchers(matcher, filesmatcher)
796 796
797 diff = m1.diff(m2, match=matcher) 797 diff = m1.diff(m2, match=matcher)
798 798
799 for f, ((n1, fl1), (n2, fl2)) in pycompat.iteritems(diff): 799 for f, ((n1, fl1), (n2, fl2)) in diff.items():
800 if n1 and n2: # file exists on both local and remote side 800 if n1 and n2: # file exists on both local and remote side
801 if f not in ma: 801 if f not in ma:
802 # TODO: what if they're renamed from different sources? 802 # TODO: what if they're renamed from different sources?
803 fa = branch_copies1.copy.get( 803 fa = branch_copies1.copy.get(
804 f, None 804 f, None
1509 1509
1510 updated, merged, removed = 0, 0, 0 1510 updated, merged, removed = 0, 0, 0
1511 ms = wctx.mergestate(clean=True) 1511 ms = wctx.mergestate(clean=True)
1512 ms.start(wctx.p1().node(), mctx.node(), labels) 1512 ms.start(wctx.p1().node(), mctx.node(), labels)
1513 1513
1514 for f, op in pycompat.iteritems(mresult.commitinfo): 1514 for f, op in mresult.commitinfo.items():
1515 # the other side of filenode was choosen while merging, store this in 1515 # the other side of filenode was choosen while merging, store this in
1516 # mergestate so that it can be reused on commit 1516 # mergestate so that it can be reused on commit
1517 ms.addcommitinfo(f, op) 1517 ms.addcommitinfo(f, op)
1518 1518
1519 num_no_op = mresult.len(mergestatemod.MergeAction.NO_OP_ACTIONS) 1519 num_no_op = mresult.len(mergestatemod.MergeAction.NO_OP_ACTIONS)
2070 _checkcollision(repo, p2.manifest(), None) 2070 _checkcollision(repo, p2.manifest(), None)
2071 else: 2071 else:
2072 _checkcollision(repo, wc.manifest(), mresult) 2072 _checkcollision(repo, wc.manifest(), mresult)
2073 2073
2074 # divergent renames 2074 # divergent renames
2075 for f, fl in sorted(pycompat.iteritems(mresult.diverge)): 2075 for f, fl in sorted(mresult.diverge.items()):
2076 repo.ui.warn( 2076 repo.ui.warn(
2077 _( 2077 _(
2078 b"note: possible conflict - %s was renamed " 2078 b"note: possible conflict - %s was renamed "
2079 b"multiple times to:\n" 2079 b"multiple times to:\n"
2080 ) 2080 )
2082 ) 2082 )
2083 for nf in sorted(fl): 2083 for nf in sorted(fl):
2084 repo.ui.warn(b" %s\n" % nf) 2084 repo.ui.warn(b" %s\n" % nf)
2085 2085
2086 # rename and delete 2086 # rename and delete
2087 for f, fl in sorted(pycompat.iteritems(mresult.renamedelete)): 2087 for f, fl in sorted(mresult.renamedelete.items()):
2088 repo.ui.warn( 2088 repo.ui.warn(
2089 _( 2089 _(
2090 b"note: possible conflict - %s was deleted " 2090 b"note: possible conflict - %s was deleted "
2091 b"and renamed to:\n" 2091 b"and renamed to:\n"
2092 ) 2092 )
2122 labels=labels, 2122 labels=labels,
2123 ) 2123 )
2124 2124
2125 if updatedirstate: 2125 if updatedirstate:
2126 if extraactions: 2126 if extraactions:
2127 for k, acts in pycompat.iteritems(extraactions): 2127 for k, acts in extraactions.items():
2128 for a in acts: 2128 for a in acts:
2129 mresult.addfile(a[0], k, *a[1:]) 2129 mresult.addfile(a[0], k, *a[1:])
2130 if k == mergestatemod.ACTION_GET and wantfiledata: 2130 if k == mergestatemod.ACTION_GET and wantfiledata:
2131 # no filedata until mergestate is updated to provide it 2131 # no filedata until mergestate is updated to provide it
2132 for a in acts: 2132 for a in acts:
2193 # the dirstate content anyway, no need to put cache 2193 # the dirstate content anyway, no need to put cache
2194 # information. 2194 # information.
2195 getfiledata = None 2195 getfiledata = None
2196 else: 2196 else:
2197 now_sec = now[0] 2197 now_sec = now[0]
2198 for f, m in pycompat.iteritems(getfiledata): 2198 for f, m in getfiledata.items():
2199 if m is not None and m[2][0] >= now_sec: 2199 if m is not None and m[2][0] >= now_sec:
2200 ambiguous_mtime[f] = (m[0], m[1], None) 2200 ambiguous_mtime[f] = (m[0], m[1], None)
2201 for f, m in pycompat.iteritems(ambiguous_mtime): 2201 for f, m in ambiguous_mtime.items():
2202 getfiledata[f] = m 2202 getfiledata[f] = m
2203 2203
2204 repo.setparents(fp1, fp2) 2204 repo.setparents(fp1, fp2)
2205 mergestatemod.recordupdates( 2205 mergestatemod.recordupdates(
2206 repo, mresult.actionsdict, branchmerge, getfiledata 2206 repo, mresult.actionsdict, branchmerge, getfiledata