Mercurial > public > mercurial-scm > hg
comparison mercurial/merge.py @ 45299:e98f7c5babd7
mergeresult: make actionmapping a dict of dict instead of dict of lists
This makes deleting a specific filename entry faster and easier.
Differential Revision: https://phab.mercurial-scm.org/D8837
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 25 Jul 2020 01:42:41 +0530 |
parents | cb0cd87e16b4 |
children | f569ca3eb430 |
comparison
equal
deleted
inserted
replaced
45298:a3cd63d6005b | 45299:e98f7c5babd7 |
---|---|
563 divergent renames | 563 divergent renames |
564 renamedelete: mapping of source name -> list of destinations for files | 564 renamedelete: mapping of source name -> list of destinations for files |
565 deleted on one side and renamed on other. | 565 deleted on one side and renamed on other. |
566 commitinfo: dict containing data which should be used on commit | 566 commitinfo: dict containing data which should be used on commit |
567 contains a filename -> info mapping | 567 contains a filename -> info mapping |
568 actionmapping: dict of action names as keys and list of files and | 568 actionmapping: dict of action names as keys and values are dict of |
569 related data as values | 569 filename as key and related data as values |
570 """ | 570 """ |
571 self._filemapping = {} | 571 self._filemapping = {} |
572 self._diverge = {} | 572 self._diverge = {} |
573 self._renamedelete = {} | 573 self._renamedelete = {} |
574 self._commitinfo = {} | 574 self._commitinfo = {} |
575 self._actionmapping = collections.defaultdict(list) | 575 self._actionmapping = collections.defaultdict(dict) |
576 | 576 |
577 def updatevalues(self, diverge, renamedelete, commitinfo): | 577 def updatevalues(self, diverge, renamedelete, commitinfo): |
578 self._diverge = diverge | 578 self._diverge = diverge |
579 self._renamedelete = renamedelete | 579 self._renamedelete = renamedelete |
580 self._commitinfo = commitinfo | 580 self._commitinfo = commitinfo |
588 message: a message about the merge | 588 message: a message about the merge |
589 """ | 589 """ |
590 # if the file already existed, we need to delete it's old | 590 # if the file already existed, we need to delete it's old |
591 # entry form _actionmapping too | 591 # entry form _actionmapping too |
592 if filename in self._filemapping: | 592 if filename in self._filemapping: |
593 # TODO: this is inefficient | |
594 a, d, m = self._filemapping[filename] | 593 a, d, m = self._filemapping[filename] |
595 self._actionmapping[a].remove((filename, d, m)) | 594 del self._actionmapping[a][filename] |
596 | 595 |
597 self._filemapping[filename] = (action, data, message) | 596 self._filemapping[filename] = (action, data, message) |
598 self._actionmapping[action].append((filename, data, message)) | 597 self._actionmapping[action][filename] = (data, message) |
599 | 598 |
600 def removefile(self, filename): | 599 def removefile(self, filename): |
601 """ removes a file from the mergeresult object as the file might | 600 """ removes a file from the mergeresult object as the file might |
602 not merging anymore """ | 601 not merging anymore """ |
603 action, data, message = self._filemapping[filename] | 602 action, data, message = self._filemapping[filename] |
604 del self._filemapping[filename] | 603 del self._filemapping[filename] |
605 # TODO: this is inefficient | 604 del self._actionmapping[action][filename] |
606 self._actionmapping[action].remove((filename, data, message)) | |
607 | 605 |
608 def getactions(self, actions): | 606 def getactions(self, actions): |
609 """ get list of files which are marked with these actions | 607 """ get list of files which are marked with these actions |
610 | 608 |
611 Returns a list of tuple of form (filename, data, message) | 609 Returns a list of tuple of form (filename, data, message) |
612 """ | 610 """ |
613 res = [] | 611 res = [] |
614 for a in actions: | 612 for a in actions: |
615 res.extend(self._actionmapping[a]) | 613 for f, (args, msg) in pycompat.iteritems(self._actionmapping[a]): |
614 res.append((f, args, msg)) | |
616 return res | 615 return res |
617 | 616 |
618 @property | 617 @property |
619 def actions(self): | 618 def actions(self): |
620 return self._filemapping | 619 return self._filemapping |
633 | 632 |
634 @property | 633 @property |
635 def actionsdict(self): | 634 def actionsdict(self): |
636 """ returns a dictionary of actions to be perfomed with action as key | 635 """ returns a dictionary of actions to be perfomed with action as key |
637 and a list of files and related arguments as values """ | 636 and a list of files and related arguments as values """ |
638 return self._actionmapping | 637 res = emptyactions() |
638 for a, d in pycompat.iteritems(self._actionmapping): | |
639 for f, (args, msg) in pycompat.iteritems(d): | |
640 res[a].append((f, args, msg)) | |
641 return res | |
639 | 642 |
640 def setactions(self, actions): | 643 def setactions(self, actions): |
641 self._filemapping = actions | 644 self._filemapping = actions |
642 self._actionmapping = collections.defaultdict(list) | 645 self._actionmapping = collections.defaultdict(dict) |
643 for f, (act, data, msg) in pycompat.iteritems(self._filemapping): | 646 for f, (act, data, msg) in pycompat.iteritems(self._filemapping): |
644 self._actionmapping[act].append((f, data, msg)) | 647 self._actionmapping[act][f] = data, msg |
645 | 648 |
646 def updateactions(self, updates): | 649 def updateactions(self, updates): |
647 for f, (a, data, msg) in pycompat.iteritems(updates): | 650 for f, (a, data, msg) in pycompat.iteritems(updates): |
648 self.addfile(f, a, data, msg) | 651 self.addfile(f, a, data, msg) |
649 | 652 |