Mercurial > public > mercurial-scm > hg
comparison mercurial/merge.py @ 45292:69691c5b8ce4
mergeresult: introduce action -> (filename, data, msg) mapping and related API
Good number of places in code, we iterate over the actions dict which has
filename as keys and filter based on the action.
This patch introduced another mapping which has action as key. This will help in
refactoring the code much more in upcoming patch.
Differential Revision: https://phab.mercurial-scm.org/D8830
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Fri, 24 Jul 2020 19:48:38 +0530 |
parents | 26fa2eebc291 |
children | 4e6a2889dd1d |
comparison
equal
deleted
inserted
replaced
45291:26fa2eebc291 | 45292:69691c5b8ce4 |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import collections | |
10 import errno | 11 import errno |
11 import stat | 12 import stat |
12 import struct | 13 import struct |
13 | 14 |
14 from .i18n import _ | 15 from .i18n import _ |
562 divergent renames | 563 divergent renames |
563 renamedelete: mapping of source name -> list of destinations for files | 564 renamedelete: mapping of source name -> list of destinations for files |
564 deleted on one side and renamed on other. | 565 deleted on one side and renamed on other. |
565 commitinfo: dict containing data which should be used on commit | 566 commitinfo: dict containing data which should be used on commit |
566 contains a filename -> info mapping | 567 contains a filename -> info mapping |
568 actionmapping: dict of action names as keys and list of files and | |
569 related data as values | |
567 """ | 570 """ |
568 self._filemapping = {} | 571 self._filemapping = {} |
569 self._diverge = {} | 572 self._diverge = {} |
570 self._renamedelete = {} | 573 self._renamedelete = {} |
571 self._commitinfo = {} | 574 self._commitinfo = {} |
575 self._actionmapping = collections.defaultdict(list) | |
572 | 576 |
573 def updatevalues(self, diverge, renamedelete, commitinfo): | 577 def updatevalues(self, diverge, renamedelete, commitinfo): |
574 self._diverge = diverge | 578 self._diverge = diverge |
575 self._renamedelete = renamedelete | 579 self._renamedelete = renamedelete |
576 self._commitinfo = commitinfo | 580 self._commitinfo = commitinfo |
581 filename: file which we are adding | 585 filename: file which we are adding |
582 action: one of mergestatemod.ACTION_* | 586 action: one of mergestatemod.ACTION_* |
583 data: a tuple of information like fctx and ctx related to this merge | 587 data: a tuple of information like fctx and ctx related to this merge |
584 message: a message about the merge | 588 message: a message about the merge |
585 """ | 589 """ |
590 # if the file already existed, we need to delete it's old | |
591 # entry form _actionmapping too | |
592 if filename in self._filemapping: | |
593 # TODO: this is inefficient | |
594 a, d, m = self._filemapping[filename] | |
595 self._actionmapping[a].remove((filename, d, m)) | |
596 | |
586 self._filemapping[filename] = (action, data, message) | 597 self._filemapping[filename] = (action, data, message) |
598 self._actionmapping[action].append((filename, data, message)) | |
587 | 599 |
588 def removefile(self, filename): | 600 def removefile(self, filename): |
589 """ removes a file from the mergeresult object as the file might | 601 """ removes a file from the mergeresult object as the file might |
590 not merging anymore """ | 602 not merging anymore """ |
603 action, data, message = self._filemapping[filename] | |
591 del self._filemapping[filename] | 604 del self._filemapping[filename] |
605 # TODO: this is inefficient | |
606 self._actionmapping[action].remove((filename, data, message)) | |
607 | |
608 def getactions(self, actions): | |
609 """ get list of files which are marked with these actions | |
610 | |
611 Returns a list of tuple of form (filename, data, message) | |
612 """ | |
613 res = [] | |
614 for a in actions: | |
615 res.extend(self._actionmapping[a]) | |
616 return res | |
592 | 617 |
593 @property | 618 @property |
594 def actions(self): | 619 def actions(self): |
595 return self._filemapping | 620 return self._filemapping |
596 | 621 |
608 | 633 |
609 @property | 634 @property |
610 def actionsdict(self): | 635 def actionsdict(self): |
611 """ returns a dictionary of actions to be perfomed with action as key | 636 """ returns a dictionary of actions to be perfomed with action as key |
612 and a list of files and related arguments as values """ | 637 and a list of files and related arguments as values """ |
613 # Convert to dictionary-of-lists format | 638 return self._actionmapping |
614 actions = emptyactions() | |
615 for f, (m, args, msg) in pycompat.iteritems(self._filemapping): | |
616 if m not in actions: | |
617 actions[m] = [] | |
618 actions[m].append((f, args, msg)) | |
619 | |
620 return actions | |
621 | 639 |
622 def setactions(self, actions): | 640 def setactions(self, actions): |
623 self._filemapping = actions | 641 self._filemapping = actions |
642 self._actionmapping = collections.defaultdict(list) | |
643 for f, (act, data, msg) in pycompat.iteritems(self._filemapping): | |
644 self._actionmapping[act].append((f, data, msg)) | |
624 | 645 |
625 def updateactions(self, updates): | 646 def updateactions(self, updates): |
626 self._filemapping.update(updates) | 647 for f, (a, data, msg) in pycompat.iteritems(updates): |
648 self.addfile(f, a, data, msg) | |
627 | 649 |
628 def hasconflicts(self): | 650 def hasconflicts(self): |
629 """ tells whether this merge resulted in some actions which can | 651 """ tells whether this merge resulted in some actions which can |
630 result in conflicts or not """ | 652 result in conflicts or not """ |
631 for _f, (m, _unused, _unused) in pycompat.iteritems(self._filemapping): | 653 for _f, (m, _unused, _unused) in pycompat.iteritems(self._filemapping): |