[Updated] D8837: mergeresult: make actionmapping a dict of dict instead of dict of lists

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Sun Aug 2 17:47:26 UTC 2020


Closed by commit rHGe98f7c5babd7: mergeresult: make actionmapping a dict of dict instead of dict of lists (authored by pulkit).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8837?vs=22128&id=22220

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8837/new/

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

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

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):



To: pulkit, #hg-reviewers, indygreg
Cc: indygreg, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200802/389acde2/attachment-0002.html>


More information about the Mercurial-patches mailing list