comparison mercurial/merge.py @ 45344: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
comparison
equal deleted inserted replaced
45343:e3826f1dab60 45344:4c6004afd836
452 invalidconflicts.add(p) 452 invalidconflicts.add(p)
453 else: 453 else:
454 # A file is in a directory which aliases a local file. 454 # A file is in a directory which aliases a local file.
455 # We will need to rename the local file. 455 # We will need to rename the local file.
456 localconflicts.add(p) 456 localconflicts.add(p)
457 if p in mresult.actions and mresult.actions[p][0] in ( 457 pd = mresult.getfile(p)
458 if pd and pd[0] in (
458 mergestatemod.ACTION_CREATED, 459 mergestatemod.ACTION_CREATED,
459 mergestatemod.ACTION_DELETED_CHANGED, 460 mergestatemod.ACTION_DELETED_CHANGED,
460 mergestatemod.ACTION_MERGE, 461 mergestatemod.ACTION_MERGE,
461 mergestatemod.ACTION_CREATED_MERGE, 462 mergestatemod.ACTION_CREATED_MERGE,
462 ): 463 ):
487 if remoteconflicts: 488 if remoteconflicts:
488 # Check if all files in the conflicting directories have been removed. 489 # Check if all files in the conflicting directories have been removed.
489 ctxname = bytes(mctx).rstrip(b'+') 490 ctxname = bytes(mctx).rstrip(b'+')
490 for f, p in _filesindirs(repo, mf, remoteconflicts): 491 for f, p in _filesindirs(repo, mf, remoteconflicts):
491 if f not in deletedfiles: 492 if f not in deletedfiles:
492 m, args, msg = mresult.actions[p] 493 m, args, msg = mresult.getfile(p)
493 pnew = util.safename( 494 pnew = util.safename(
494 p, ctxname, wctx, set(mresult.actions.keys()) 495 p, ctxname, wctx, set(mresult.actions.keys())
495 ) 496 )
496 if m in ( 497 if m in (
497 mergestatemod.ACTION_DELETED_CHANGED, 498 mergestatemod.ACTION_DELETED_CHANGED,
609 a, d, m = self._filemapping[filename] 610 a, d, m = self._filemapping[filename]
610 del self._actionmapping[a][filename] 611 del self._actionmapping[a][filename]
611 612
612 self._filemapping[filename] = (action, data, message) 613 self._filemapping[filename] = (action, data, message)
613 self._actionmapping[action][filename] = (data, message) 614 self._actionmapping[action][filename] = (data, message)
615
616 def getfile(self, filename, default_return=None):
617 """ returns (action, args, msg) about this file
618
619 returns default_return if the file is not present """
620 if filename in self._filemapping:
621 return self._filemapping[filename]
622 return default_return
614 623
615 def removefile(self, filename): 624 def removefile(self, filename):
616 """ removes a file from the mergeresult object as the file might 625 """ removes a file from the mergeresult object as the file might
617 not merging anymore """ 626 not merging anymore """
618 action, data, message = self._filemapping[filename] 627 action, data, message = self._filemapping[filename]
1958 raise error.Abort(msg, hint=hint) 1967 raise error.Abort(msg, hint=hint)
1959 1968
1960 # Prompt and create actions. Most of this is in the resolve phase 1969 # Prompt and create actions. Most of this is in the resolve phase
1961 # already, but we can't handle .hgsubstate in filemerge or 1970 # already, but we can't handle .hgsubstate in filemerge or
1962 # subrepoutil.submerge yet so we have to keep prompting for it. 1971 # subrepoutil.submerge yet so we have to keep prompting for it.
1963 if b'.hgsubstate' in mresult.actions: 1972 vals = mresult.getfile(b'.hgsubstate')
1973 if vals:
1964 f = b'.hgsubstate' 1974 f = b'.hgsubstate'
1965 m, args, msg = mresult.actions[f] 1975 m, args, msg = vals
1966 prompts = filemerge.partextras(labels) 1976 prompts = filemerge.partextras(labels)
1967 prompts[b'f'] = f 1977 prompts[b'f'] = f
1968 if m == mergestatemod.ACTION_CHANGED_DELETED: 1978 if m == mergestatemod.ACTION_CHANGED_DELETED:
1969 if repo.ui.promptchoice( 1979 if repo.ui.promptchoice(
1970 _( 1980 _(