Patchwork D8837: mergeresult: make actionmapping a dict of dict instead of dict of lists

login
register
mail settings
Submitter phabricator
Date July 25, 2020, 10:04 a.m.
Message ID <differential-rev-PHID-DREV-zkpriqvb6jl3v2ptbk3m-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46908/
State Superseded
Headers show

Comments

phabricator - July 25, 2020, 10:04 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This makes deleting a specific filename entry faster and easier.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8837

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -565,14 +565,14 @@ 
                       deleted on one side and renamed on other.
         commitinfo: dict containing data which should be used on commit
                     contains a filename -> info mapping
-        actionmapping: dict of action names as keys and list of files and
-                       related data as values
+        actionmapping: dict of action names as keys and values are dict of
+                       filename as key and related data as values
         """
         self._filemapping = {}
         self._diverge = {}
         self._renamedelete = {}
         self._commitinfo = {}
-        self._actionmapping = collections.defaultdict(list)
+        self._actionmapping = collections.defaultdict(dict)
 
     def updatevalues(self, diverge, renamedelete, commitinfo):
         self._diverge = diverge
@@ -590,20 +590,18 @@ 
         # if the file already existed, we need to delete it's old
         # entry form _actionmapping too
         if filename in self._filemapping:
-            # TODO: this is inefficient
             a, d, m = self._filemapping[filename]
-            self._actionmapping[a].remove((filename, d, m))
+            del self._actionmapping[a][filename]
 
         self._filemapping[filename] = (action, data, message)
-        self._actionmapping[action].append((filename, data, message))
+        self._actionmapping[action][filename] = (data, message)
 
     def removefile(self, filename):
         """ removes a file from the mergeresult object as the file might
         not merging anymore """
         action, data, message = self._filemapping[filename]
         del self._filemapping[filename]
-        # TODO: this is inefficient
-        self._actionmapping[action].remove((filename, data, message))
+        del self._actionmapping[action][filename]
 
     def getactions(self, actions):
         """ get list of files which are marked with these actions
@@ -612,7 +610,8 @@ 
         """
         res = []
         for a in actions:
-            res.extend(self._actionmapping[a])
+            for f, (args, msg) in pycompat.iteritems(self._actionmapping[a]):
+                res.append((f, args, msg))
         return res
 
     @property
@@ -635,13 +634,17 @@ 
     def actionsdict(self):
         """ returns a dictionary of actions to be perfomed with action as key
         and a list of files and related arguments as values """
-        return self._actionmapping
+        res = emptyactions()
+        for a, d in pycompat.iteritems(self._actionmapping):
+            for f, (args, msg) in pycompat.iteritems(d):
+                res[a].append((f, args, msg))
+        return res
 
     def setactions(self, actions):
         self._filemapping = actions
-        self._actionmapping = collections.defaultdict(list)
+        self._actionmapping = collections.defaultdict(dict)
         for f, (act, data, msg) in pycompat.iteritems(self._filemapping):
-            self._actionmapping[act].append((f, data, msg))
+            self._actionmapping[act][f] = data, msg
 
     def updateactions(self, updates):
         for f, (a, data, msg) in pycompat.iteritems(updates):