comparison mercurial/merge.py @ 45333:f569ca3eb430

merge: pass mergeresult obj instead of actions in _checkcollision() (API) The goal is to not use the actions dict and replace it with a rich mergeresult object. Differential Revision: https://phab.mercurial-scm.org/D8875
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 03 Aug 2020 13:30:14 +0530
parents e98f7c5babd7
children b9b055f15035
comparison
equal deleted inserted replaced
45332:54eeb1a0e325 45333:f569ca3eb430
286 ) 286 )
287 287
288 return actions 288 return actions
289 289
290 290
291 def _checkcollision(repo, wmf, actions): 291 def _checkcollision(repo, wmf, mresult):
292 """ 292 """
293 Check for case-folding collisions. 293 Check for case-folding collisions.
294 """ 294 """
295 # If the repo is narrowed, filter out files outside the narrowspec. 295 # If the repo is narrowed, filter out files outside the narrowspec.
296 narrowmatch = repo.narrowmatch() 296 narrowmatch = repo.narrowmatch()
297 if not narrowmatch.always(): 297 if not narrowmatch.always():
298 pmmf = set(wmf.walk(narrowmatch)) 298 pmmf = set(wmf.walk(narrowmatch))
299 if actions: 299 if mresult:
300 narrowactions = {} 300 for f, actionsfortype in pycompat.iteritems(mresult.actions):
301 for m, actionsfortype in pycompat.iteritems(actions): 301 if not narrowmatch(f):
302 narrowactions[m] = [] 302 mresult.removefile(f)
303 for (f, args, msg) in actionsfortype:
304 if narrowmatch(f):
305 narrowactions[m].append((f, args, msg))
306 actions = narrowactions
307 else: 303 else:
308 # build provisional merged manifest up 304 # build provisional merged manifest up
309 pmmf = set(wmf) 305 pmmf = set(wmf)
310 306
311 if actions: 307 if mresult:
312 # KEEP and EXEC are no-op 308 # KEEP and EXEC are no-op
313 for m in ( 309 for f, args, msg in mresult.getactions(
314 mergestatemod.ACTION_ADD, 310 (
315 mergestatemod.ACTION_ADD_MODIFIED, 311 mergestatemod.ACTION_ADD,
316 mergestatemod.ACTION_FORGET, 312 mergestatemod.ACTION_ADD_MODIFIED,
317 mergestatemod.ACTION_GET, 313 mergestatemod.ACTION_FORGET,
318 mergestatemod.ACTION_CHANGED_DELETED, 314 mergestatemod.ACTION_GET,
319 mergestatemod.ACTION_DELETED_CHANGED, 315 mergestatemod.ACTION_CHANGED_DELETED,
316 mergestatemod.ACTION_DELETED_CHANGED,
317 )
320 ): 318 ):
321 for f, args, msg in actions[m]: 319 pmmf.add(f)
322 pmmf.add(f) 320 for f, args, msg in mresult.getactions([mergestatemod.ACTION_REMOVE]):
323 for f, args, msg in actions[mergestatemod.ACTION_REMOVE]:
324 pmmf.discard(f) 321 pmmf.discard(f)
325 for f, args, msg in actions[mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL]: 322 for f, args, msg in mresult.getactions(
323 [mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL]
324 ):
326 f2, flags = args 325 f2, flags = args
327 pmmf.discard(f2) 326 pmmf.discard(f2)
328 pmmf.add(f) 327 pmmf.add(f)
329 for f, args, msg in actions[mergestatemod.ACTION_LOCAL_DIR_RENAME_GET]: 328 for f, args, msg in mresult.getactions(
329 [mergestatemod.ACTION_LOCAL_DIR_RENAME_GET]
330 ):
330 pmmf.add(f) 331 pmmf.add(f)
331 for f, args, msg in actions[mergestatemod.ACTION_MERGE]: 332 for f, args, msg in mresult.getactions([mergestatemod.ACTION_MERGE]):
332 f1, f2, fa, move, anc = args 333 f1, f2, fa, move, anc = args
333 if move: 334 if move:
334 pmmf.discard(f1) 335 pmmf.discard(f1)
335 pmmf.add(f) 336 pmmf.add(f)
336 337
1958 b'prompt recreating', 1959 b'prompt recreating',
1959 ) 1960 )
1960 else: 1961 else:
1961 mresult.removefile(f) 1962 mresult.removefile(f)
1962 1963
1963 # Convert to dictionary-of-lists format
1964 actions = mresult.actionsdict
1965
1966 if not util.fscasesensitive(repo.path): 1964 if not util.fscasesensitive(repo.path):
1967 # check collision between files only in p2 for clean update 1965 # check collision between files only in p2 for clean update
1968 if not branchmerge and ( 1966 if not branchmerge and (
1969 force or not wc.dirty(missing=True, branch=False) 1967 force or not wc.dirty(missing=True, branch=False)
1970 ): 1968 ):
1971 _checkcollision(repo, p2.manifest(), None) 1969 _checkcollision(repo, p2.manifest(), None)
1972 else: 1970 else:
1973 _checkcollision(repo, wc.manifest(), actions) 1971 _checkcollision(repo, wc.manifest(), mresult)
1974 1972
1975 # divergent renames 1973 # divergent renames
1976 for f, fl in sorted(pycompat.iteritems(mresult.diverge)): 1974 for f, fl in sorted(pycompat.iteritems(mresult.diverge)):
1977 repo.ui.warn( 1975 repo.ui.warn(
1978 _( 1976 _(
2005 updatedirstate = updatedirstate and always and not wc.isinmemory() 2003 updatedirstate = updatedirstate and always and not wc.isinmemory()
2006 if updatedirstate: 2004 if updatedirstate:
2007 repo.hook(b'preupdate', throw=True, parent1=xp1, parent2=xp2) 2005 repo.hook(b'preupdate', throw=True, parent1=xp1, parent2=xp2)
2008 # note that we're in the middle of an update 2006 # note that we're in the middle of an update
2009 repo.vfs.write(b'updatestate', p2.hex()) 2007 repo.vfs.write(b'updatestate', p2.hex())
2008
2009 # Convert to dictionary-of-lists format
2010 actions = mresult.actionsdict
2010 2011
2011 _advertisefsmonitor( 2012 _advertisefsmonitor(
2012 repo, len(actions[mergestatemod.ACTION_GET]), p1.node() 2013 repo, len(actions[mergestatemod.ACTION_GET]), p1.node()
2013 ) 2014 )
2014 2015