changeset 45365:4c6004afd836

mergeresult: introduce getfile() and use it where required We want to hide the underlying dictionary from the users and provide API for valid and sane use cases. Differential Revision: https://phab.mercurial-scm.org/D8886
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 05 Aug 2020 15:37:26 +0530
parents e3826f1dab60
children e5b4061f32be
files hgext/largefiles/overrides.py mercurial/merge.py
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Wed Aug 05 14:03:59 2020 +0530
+++ b/hgext/largefiles/overrides.py	Wed Aug 05 15:37:26 2020 +0530
@@ -571,8 +571,8 @@
 
     for lfile in sorted(lfiles):
         standin = lfutil.standin(lfile)
-        (lm, largs, lmsg) = mresult.actions.get(lfile, (None, None, None))
-        (sm, sargs, smsg) = mresult.actions.get(standin, (None, None, None))
+        (lm, largs, lmsg) = mresult.getfile(lfile, (None, None, None))
+        (sm, sargs, smsg) = mresult.getfile(standin, (None, None, None))
         if sm in (b'g', b'dc') and lm != b'r':
             if sm == b'dc':
                 f1, f2, fa, move, anc = sargs
--- a/mercurial/merge.py	Wed Aug 05 14:03:59 2020 +0530
+++ b/mercurial/merge.py	Wed Aug 05 15:37:26 2020 +0530
@@ -454,7 +454,8 @@
                 # A file is in a directory which aliases a local file.
                 # We will need to rename the local file.
                 localconflicts.add(p)
-        if p in mresult.actions and mresult.actions[p][0] in (
+        pd = mresult.getfile(p)
+        if pd and pd[0] in (
             mergestatemod.ACTION_CREATED,
             mergestatemod.ACTION_DELETED_CHANGED,
             mergestatemod.ACTION_MERGE,
@@ -489,7 +490,7 @@
         ctxname = bytes(mctx).rstrip(b'+')
         for f, p in _filesindirs(repo, mf, remoteconflicts):
             if f not in deletedfiles:
-                m, args, msg = mresult.actions[p]
+                m, args, msg = mresult.getfile(p)
                 pnew = util.safename(
                     p, ctxname, wctx, set(mresult.actions.keys())
                 )
@@ -612,6 +613,14 @@
         self._filemapping[filename] = (action, data, message)
         self._actionmapping[action][filename] = (data, message)
 
+    def getfile(self, filename, default_return=None):
+        """ returns (action, args, msg) about this file
+
+        returns default_return if the file is not present """
+        if filename in self._filemapping:
+            return self._filemapping[filename]
+        return default_return
+
     def removefile(self, filename):
         """ removes a file from the mergeresult object as the file might
         not merging anymore """
@@ -1960,9 +1969,10 @@
         # Prompt and create actions. Most of this is in the resolve phase
         # already, but we can't handle .hgsubstate in filemerge or
         # subrepoutil.submerge yet so we have to keep prompting for it.
-        if b'.hgsubstate' in mresult.actions:
+        vals = mresult.getfile(b'.hgsubstate')
+        if vals:
             f = b'.hgsubstate'
-            m, args, msg = mresult.actions[f]
+            m, args, msg = vals
             prompts = filemerge.partextras(labels)
             prompts[b'f'] = f
             if m == mergestatemod.ACTION_CHANGED_DELETED: