Mercurial > public > mercurial-scm > hg
comparison mercurial/merge.py @ 45340:cdc50e1929b0
mergeresult: yield from getactions() instead of buidling a list and returning
Only 7 out of 29 callers change the underlying dict while iterating. So it's
better to yield and wrap the 7 callers with `list()`.
Differential Revision: https://phab.mercurial-scm.org/D8882
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 03 Aug 2020 18:08:37 +0530 |
parents | 72b8c082676b |
children | e335936cd4e1 |
comparison
equal
deleted
inserted
replaced
45339:9320f66854f6 | 45340:cdc50e1929b0 |
---|---|
173 ignoredconflicts = {c for c in allconflicts if repo.dirstate._ignore(c)} | 173 ignoredconflicts = {c for c in allconflicts if repo.dirstate._ignore(c)} |
174 unknownconflicts = allconflicts - ignoredconflicts | 174 unknownconflicts = allconflicts - ignoredconflicts |
175 collectconflicts(ignoredconflicts, ignoredconfig) | 175 collectconflicts(ignoredconflicts, ignoredconfig) |
176 collectconflicts(unknownconflicts, unknownconfig) | 176 collectconflicts(unknownconflicts, unknownconfig) |
177 else: | 177 else: |
178 for f, args, msg in mresult.getactions( | 178 for f, args, msg in list( |
179 [mergestatemod.ACTION_CREATED_MERGE] | 179 mresult.getactions([mergestatemod.ACTION_CREATED_MERGE]) |
180 ): | 180 ): |
181 fl2, anc = args | 181 fl2, anc = args |
182 different = _checkunknownfile(repo, wctx, mctx, f) | 182 different = _checkunknownfile(repo, wctx, mctx, f) |
183 if repo.dirstate._ignore(f): | 183 if repo.dirstate._ignore(f): |
184 config = ignoredconfig | 184 config = ignoredconfig |
241 if repo.wvfs.isfileorlink(f): | 241 if repo.wvfs.isfileorlink(f): |
242 repo.ui.warn(_(b"%s: replacing untracked file\n") % f) | 242 repo.ui.warn(_(b"%s: replacing untracked file\n") % f) |
243 else: | 243 else: |
244 repo.ui.warn(_(b"%s: replacing untracked files in directory\n") % f) | 244 repo.ui.warn(_(b"%s: replacing untracked files in directory\n") % f) |
245 | 245 |
246 for f, args, msg in mresult.getactions([mergestatemod.ACTION_CREATED]): | 246 for f, args, msg in list( |
247 mresult.getactions([mergestatemod.ACTION_CREATED]) | |
248 ): | |
247 backup = ( | 249 backup = ( |
248 f in fileconflicts | 250 f in fileconflicts |
249 or f in pathconflicts | 251 or f in pathconflicts |
250 or any(p in pathconflicts for p in pathutil.finddirs(f)) | 252 or any(p in pathconflicts for p in pathutil.finddirs(f)) |
251 ) | 253 ) |
608 """ get list of files which are marked with these actions | 610 """ get list of files which are marked with these actions |
609 if sort is true, files for each action is sorted and then added | 611 if sort is true, files for each action is sorted and then added |
610 | 612 |
611 Returns a list of tuple of form (filename, data, message) | 613 Returns a list of tuple of form (filename, data, message) |
612 """ | 614 """ |
613 res = [] | |
614 for a in actions: | 615 for a in actions: |
615 if sort: | 616 if sort: |
616 for f in sorted(self._actionmapping[a]): | 617 for f in sorted(self._actionmapping[a]): |
617 args, msg = self._actionmapping[a][f] | 618 args, msg = self._actionmapping[a][f] |
618 res.append((f, args, msg)) | 619 yield f, args, msg |
619 else: | 620 else: |
620 for f, (args, msg) in pycompat.iteritems( | 621 for f, (args, msg) in pycompat.iteritems( |
621 self._actionmapping[a] | 622 self._actionmapping[a] |
622 ): | 623 ): |
623 res.append((f, args, msg)) | 624 yield f, args, msg |
624 return res | |
625 | 625 |
626 def len(self, actions=None): | 626 def len(self, actions=None): |
627 """ returns number of files which needs actions | 627 """ returns number of files which needs actions |
628 | 628 |
629 if actions is passed, total of number of files in that action | 629 if actions is passed, total of number of files in that action |
1005 def _resolvetrivial(repo, wctx, mctx, ancestor, mresult): | 1005 def _resolvetrivial(repo, wctx, mctx, ancestor, mresult): |
1006 """Resolves false conflicts where the nodeid changed but the content | 1006 """Resolves false conflicts where the nodeid changed but the content |
1007 remained the same.""" | 1007 remained the same.""" |
1008 # We force a copy of actions.items() because we're going to mutate | 1008 # We force a copy of actions.items() because we're going to mutate |
1009 # actions as we resolve trivial conflicts. | 1009 # actions as we resolve trivial conflicts. |
1010 for f, args, msg in mresult.getactions( | 1010 for f, args, msg in list( |
1011 [mergestatemod.ACTION_CHANGED_DELETED] | 1011 mresult.getactions([mergestatemod.ACTION_CHANGED_DELETED]) |
1012 ): | 1012 ): |
1013 if f in ancestor and not wctx[f].cmp(ancestor[f]): | 1013 if f in ancestor and not wctx[f].cmp(ancestor[f]): |
1014 # local did change but ended up with same content | 1014 # local did change but ended up with same content |
1015 mresult.addfile( | 1015 mresult.addfile( |
1016 f, mergestatemod.ACTION_REMOVE, None, b'prompt same' | 1016 f, mergestatemod.ACTION_REMOVE, None, b'prompt same' |
1380 ms.addmergedother(f) | 1380 ms.addmergedother(f) |
1381 | 1381 |
1382 moves = [] | 1382 moves = [] |
1383 | 1383 |
1384 # 'cd' and 'dc' actions are treated like other merge conflicts | 1384 # 'cd' and 'dc' actions are treated like other merge conflicts |
1385 mergeactions = mresult.getactions( | 1385 mergeactions = list( |
1386 [ | 1386 mresult.getactions( |
1387 mergestatemod.ACTION_CHANGED_DELETED, | 1387 [ |
1388 mergestatemod.ACTION_DELETED_CHANGED, | 1388 mergestatemod.ACTION_CHANGED_DELETED, |
1389 mergestatemod.ACTION_MERGE, | 1389 mergestatemod.ACTION_DELETED_CHANGED, |
1390 ], | 1390 mergestatemod.ACTION_MERGE, |
1391 sort=True, | 1391 ], |
1392 sort=True, | |
1393 ) | |
1392 ) | 1394 ) |
1393 for f, args, msg in mergeactions: | 1395 for f, args, msg in mergeactions: |
1394 f1, f2, fa, move, anc = args | 1396 f1, f2, fa, move, anc = args |
1395 if f == b'.hgsubstate': # merged internally | 1397 if f == b'.hgsubstate': # merged internally |
1396 continue | 1398 continue |
1457 prog = worker.worker( | 1459 prog = worker.worker( |
1458 repo.ui, | 1460 repo.ui, |
1459 cost, | 1461 cost, |
1460 batchremove, | 1462 batchremove, |
1461 (repo, wctx), | 1463 (repo, wctx), |
1462 mresult.getactions([mergestatemod.ACTION_REMOVE], sort=True), | 1464 list(mresult.getactions([mergestatemod.ACTION_REMOVE], sort=True)), |
1463 ) | 1465 ) |
1464 for i, item in prog: | 1466 for i, item in prog: |
1465 progress.increment(step=i, item=item) | 1467 progress.increment(step=i, item=item) |
1466 removed = mresult.len((mergestatemod.ACTION_REMOVE,)) | 1468 removed = mresult.len((mergestatemod.ACTION_REMOVE,)) |
1467 | 1469 |
1485 prog = worker.worker( | 1487 prog = worker.worker( |
1486 repo.ui, | 1488 repo.ui, |
1487 cost, | 1489 cost, |
1488 batchget, | 1490 batchget, |
1489 (repo, mctx, wctx, wantfiledata), | 1491 (repo, mctx, wctx, wantfiledata), |
1490 mresult.getactions([mergestatemod.ACTION_GET], sort=True), | 1492 list(mresult.getactions([mergestatemod.ACTION_GET], sort=True)), |
1491 threadsafe=threadsafe, | 1493 threadsafe=threadsafe, |
1492 hasretval=True, | 1494 hasretval=True, |
1493 ) | 1495 ) |
1494 getfiledata = {} | 1496 getfiledata = {} |
1495 for final, res in prog: | 1497 for final, res in prog: |
1665 # | 1667 # |
1666 # We don't need to do the same operation for 'dc' and 'cd' because | 1668 # We don't need to do the same operation for 'dc' and 'cd' because |
1667 # those lists aren't consulted again. | 1669 # those lists aren't consulted again. |
1668 mfiles.difference_update(a[0] for a in acts) | 1670 mfiles.difference_update(a[0] for a in acts) |
1669 | 1671 |
1670 for a in mresult.getactions([mergestatemod.ACTION_MERGE]): | 1672 for a in list(mresult.getactions((mergestatemod.ACTION_MERGE,))): |
1671 if a[0] not in mfiles: | 1673 if a[0] not in mfiles: |
1672 mresult.removefile(a[0]) | 1674 mresult.removefile(a[0]) |
1673 | 1675 |
1674 progress.complete() | 1676 progress.complete() |
1675 assert len(getfiledata) == ( | 1677 assert len(getfiledata) == ( |