comparison mercurial/phases.py @ 38218:36ba5dba372d

advanceboundary: add dryrun parameter Added logic to find those csets whose phase will be changed (when running without --dryrun) while advancing boundary and return those csets. Differential Revision: https://phab.mercurial-scm.org/D3671
author Sushil khanchi <sushilkhanchi97@gmail.com>
date Wed, 30 May 2018 14:20:09 +0530
parents 4e790f0966fc
children 88efb7d6bcb6
comparison
equal deleted inserted replaced
38217:16f93a3b8b05 38218:36ba5dba372d
352 rev = torev(n) 352 rev = torev(n)
353 revphase = phase(repo, rev) 353 revphase = phase(repo, rev)
354 _trackphasechange(phasetracking, rev, None, revphase) 354 _trackphasechange(phasetracking, rev, None, revphase)
355 repo.invalidatevolatilesets() 355 repo.invalidatevolatilesets()
356 356
357 def advanceboundary(self, repo, tr, targetphase, nodes): 357 def advanceboundary(self, repo, tr, targetphase, nodes, dryrun=None):
358 """Set all 'nodes' to phase 'targetphase' 358 """Set all 'nodes' to phase 'targetphase'
359 359
360 Nodes with a phase lower than 'targetphase' are not affected. 360 Nodes with a phase lower than 'targetphase' are not affected.
361
362 If dryrun is True, no actions will be performed
363
364 Returns a set of revs whose phase is changed or should be changed
361 """ 365 """
362 # Be careful to preserve shallow-copied values: do not update 366 # Be careful to preserve shallow-copied values: do not update
363 # phaseroots values, replace them. 367 # phaseroots values, replace them.
364 if tr is None: 368 if tr is None:
365 phasetracking = None 369 phasetracking = None
366 else: 370 else:
367 phasetracking = tr.changes.get('phases') 371 phasetracking = tr.changes.get('phases')
368 372
369 repo = repo.unfiltered() 373 repo = repo.unfiltered()
370 374
375 changes = set() # set of revisions to be changed
371 delroots = [] # set of root deleted by this path 376 delroots = [] # set of root deleted by this path
372 for phase in xrange(targetphase + 1, len(allphases)): 377 for phase in xrange(targetphase + 1, len(allphases)):
373 # filter nodes that are not in a compatible phase already 378 # filter nodes that are not in a compatible phase already
374 nodes = [n for n in nodes 379 nodes = [n for n in nodes
375 if self.phase(repo, repo[n].rev()) >= phase] 380 if self.phase(repo, repo[n].rev()) >= phase]
377 break # no roots to move anymore 382 break # no roots to move anymore
378 383
379 olds = self.phaseroots[phase] 384 olds = self.phaseroots[phase]
380 385
381 affected = repo.revs('%ln::%ln', olds, nodes) 386 affected = repo.revs('%ln::%ln', olds, nodes)
387 changes.update(affected)
388 if dryrun:
389 continue
382 for r in affected: 390 for r in affected:
383 _trackphasechange(phasetracking, r, self.phase(repo, r), 391 _trackphasechange(phasetracking, r, self.phase(repo, r),
384 targetphase) 392 targetphase)
385 393
386 roots = set(ctx.node() for ctx in repo.set( 394 roots = set(ctx.node() for ctx in repo.set(
387 'roots((%ln::) - %ld)', olds, affected)) 395 'roots((%ln::) - %ld)', olds, affected))
388 if olds != roots: 396 if olds != roots:
389 self._updateroots(phase, roots, tr) 397 self._updateroots(phase, roots, tr)
390 # some roots may need to be declared for lower phases 398 # some roots may need to be declared for lower phases
391 delroots.extend(olds - roots) 399 delroots.extend(olds - roots)
392 # declare deleted root in the target phase 400 if not dryrun:
393 if targetphase != 0: 401 # declare deleted root in the target phase
394 self._retractboundary(repo, tr, targetphase, delroots) 402 if targetphase != 0:
395 repo.invalidatevolatilesets() 403 self._retractboundary(repo, tr, targetphase, delroots)
404 repo.invalidatevolatilesets()
405 return changes
396 406
397 def retractboundary(self, repo, tr, targetphase, nodes): 407 def retractboundary(self, repo, tr, targetphase, nodes):
398 oldroots = self.phaseroots[:targetphase + 1] 408 oldroots = self.phaseroots[:targetphase + 1]
399 if tr is None: 409 if tr is None:
400 phasetracking = None 410 phasetracking = None
478 # anyway. If this change we should consider adding a dedicated 488 # anyway. If this change we should consider adding a dedicated
479 # "destroyed" function to phasecache or a proper cache key mechanism 489 # "destroyed" function to phasecache or a proper cache key mechanism
480 # (see branchmap one) 490 # (see branchmap one)
481 self.invalidate() 491 self.invalidate()
482 492
483 def advanceboundary(repo, tr, targetphase, nodes): 493 def advanceboundary(repo, tr, targetphase, nodes, dryrun=None):
484 """Add nodes to a phase changing other nodes phases if necessary. 494 """Add nodes to a phase changing other nodes phases if necessary.
485 495
486 This function move boundary *forward* this means that all nodes 496 This function move boundary *forward* this means that all nodes
487 are set in the target phase or kept in a *lower* phase. 497 are set in the target phase or kept in a *lower* phase.
488 498
489 Simplify boundary to contains phase roots only.""" 499 Simplify boundary to contains phase roots only.
500
501 If dryrun is True, no actions will be performed
502
503 Returns a set of revs whose phase is changed or should be changed
504 """
490 phcache = repo._phasecache.copy() 505 phcache = repo._phasecache.copy()
491 phcache.advanceboundary(repo, tr, targetphase, nodes) 506 changes = phcache.advanceboundary(repo, tr, targetphase, nodes,
492 repo._phasecache.replace(phcache) 507 dryrun=dryrun)
508 if not dryrun:
509 repo._phasecache.replace(phcache)
510 return changes
493 511
494 def retractboundary(repo, tr, targetphase, nodes): 512 def retractboundary(repo, tr, targetphase, nodes):
495 """Set nodes back to a phase changing other nodes phases if 513 """Set nodes back to a phase changing other nodes phases if
496 necessary. 514 necessary.
497 515