# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1596622046 -19800 # Node ID 4c6004afd8367dcf08c6562793e805e35e6c5f66 # Parent e3826f1dab60e0871305a46bb57a18bef57e57bb 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 diff -r e3826f1dab60 -r 4c6004afd836 hgext/largefiles/overrides.py --- 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 diff -r e3826f1dab60 -r 4c6004afd836 mercurial/merge.py --- 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: