comparison mercurial/merge.py @ 45524:6877b0ee5f9d

mergestate: introduce a new ACTION_KEEP_NEW `ACTION_KEEP` is overloaded and it's hard to figure out how we end up with this KEEP, what was the state of things. In a previous patch, we introduced `ACTION_KEEP_ABSENT` which represents files which are kept absent in the working directory. There is another special case where we keep the file when it's not present on both ancestor and remote side. We introduce a dedicated action for that. The goal is to use these information to make bid merge smarter. Differential Revision: https://phab.mercurial-scm.org/D9002
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 09 Sep 2020 16:49:19 +0530
parents 32ce4cbaec4b
children 590a840fa367
comparison
equal deleted inserted replaced
45521:e7587430ca23 45524:6877b0ee5f9d
550 mapping of divergent renames and other such cases. ''' 550 mapping of divergent renames and other such cases. '''
551 551
552 NO_OP_ACTIONS = ( 552 NO_OP_ACTIONS = (
553 mergestatemod.ACTION_KEEP, 553 mergestatemod.ACTION_KEEP,
554 mergestatemod.ACTION_KEEP_ABSENT, 554 mergestatemod.ACTION_KEEP_ABSENT,
555 mergestatemod.ACTION_KEEP_NEW,
555 ) 556 )
556 557
557 def __init__(self): 558 def __init__(self):
558 """ 559 """
559 filemapping: dict of filename as keys and action related info as values 560 filemapping: dict of filename as keys and action related info as values
919 f, mergestatemod.ACTION_REMOVE, None, b'other deleted', 920 f, mergestatemod.ACTION_REMOVE, None, b'other deleted',
920 ) 921 )
921 else: # file not in ancestor, not in remote 922 else: # file not in ancestor, not in remote
922 mresult.addfile( 923 mresult.addfile(
923 f, 924 f,
924 mergestatemod.ACTION_KEEP, 925 mergestatemod.ACTION_KEEP_NEW,
925 None, 926 None,
926 b'ancestor missing, remote missing', 927 b'ancestor missing, remote missing',
927 ) 928 )
928 929
929 elif n2: # file exists only on remote side 930 elif n2: # file exists only on remote side
1188 continue 1189 continue
1189 # If keep absent is an option, just do that 1190 # If keep absent is an option, just do that
1190 if mergestatemod.ACTION_KEEP_ABSENT in bids: 1191 if mergestatemod.ACTION_KEEP_ABSENT in bids:
1191 repo.ui.note(_(b" %s: picking 'keep absent' action\n") % f) 1192 repo.ui.note(_(b" %s: picking 'keep absent' action\n") % f)
1192 mresult.addfile(f, *bids[mergestatemod.ACTION_KEEP_ABSENT][0]) 1193 mresult.addfile(f, *bids[mergestatemod.ACTION_KEEP_ABSENT][0])
1194 continue
1195 # If keep new is an option, let's just do that
1196 if mergestatemod.ACTION_KEEP_NEW in bids:
1197 repo.ui.note(_(b" %s: picking 'keep new' action\n") % f)
1198 mresult.addfile(f, *bids[mergestatemod.ACTION_KEEP_NEW][0])
1193 continue 1199 continue
1194 # If there are gets and they all agree [how could they not?], do it. 1200 # If there are gets and they all agree [how could they not?], do it.
1195 if mergestatemod.ACTION_GET in bids: 1201 if mergestatemod.ACTION_GET in bids:
1196 ga0 = bids[mergestatemod.ACTION_GET][0] 1202 ga0 = bids[mergestatemod.ACTION_GET][0]
1197 if all(a == ga0 for a in bids[mergestatemod.ACTION_GET][1:]): 1203 if all(a == ga0 for a in bids[mergestatemod.ACTION_GET][1:]):
1494 ): 1500 ):
1495 repo.ui.debug(b" %s: %s -> am\n" % (f, msg)) 1501 repo.ui.debug(b" %s: %s -> am\n" % (f, msg))
1496 progress.increment(item=f) 1502 progress.increment(item=f)
1497 1503
1498 # keep (noop, just log it) 1504 # keep (noop, just log it)
1499 for f, args, msg in mresult.getactions( 1505 for a in mergeresult.NO_OP_ACTIONS:
1500 (mergestatemod.ACTION_KEEP,), sort=True 1506 for f, args, msg in mresult.getactions((a,), sort=True):
1501 ): 1507 repo.ui.debug(b" %s: %s -> %s\n" % (f, msg, a))
1502 repo.ui.debug(b" %s: %s -> k\n" % (f, msg)) 1508 # no progress
1503 # no progress
1504 for f, args, msg in mresult.getactions(
1505 (mergestatemod.ACTION_KEEP_ABSENT,), sort=True
1506 ):
1507 repo.ui.debug(b" %s: %s -> ka\n" % (f, msg))
1508 # no progress
1509 1509
1510 # directory rename, move local 1510 # directory rename, move local
1511 for f, args, msg in mresult.getactions( 1511 for f, args, msg in mresult.getactions(
1512 (mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL,), sort=True 1512 (mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL,), sort=True
1513 ): 1513 ):