mercurial/phases.py
changeset 33451 e44d54260c32
parent 33450 d017f1d37378
child 33452 7b25a56366cf
equal deleted inserted replaced
33450:d017f1d37378 33451:e44d54260c32
   152             for f in phasedefaults:
   152             for f in phasedefaults:
   153                 roots = f(repo, roots)
   153                 roots = f(repo, roots)
   154         dirty = True
   154         dirty = True
   155     return roots, dirty
   155     return roots, dirty
   156 
   156 
       
   157 def _trackphasechange(data, rev, old, new):
       
   158     """add a phase move the <data> dictionnary
       
   159 
       
   160     If data is None, nothing happens.
       
   161     """
       
   162     if data is None:
       
   163         return
       
   164     existing = data.get(rev)
       
   165     if existing is not None:
       
   166         old = existing[0]
       
   167     data[rev] = (old, new)
       
   168 
   157 class phasecache(object):
   169 class phasecache(object):
   158     def __init__(self, repo, phasedefaults, _load=True):
   170     def __init__(self, repo, phasedefaults, _load=True):
   159         if _load:
   171         if _load:
   160             # Cheap trick to allow shallow-copy without copy module
   172             # Cheap trick to allow shallow-copy without copy module
   161             self.phaseroots, self.dirty = _readroots(repo, phasedefaults)
   173             self.phaseroots, self.dirty = _readroots(repo, phasedefaults)
   287 
   299 
   288         Nodes with a phase lower than 'targetphase' are not affected.
   300         Nodes with a phase lower than 'targetphase' are not affected.
   289         """
   301         """
   290         # Be careful to preserve shallow-copied values: do not update
   302         # Be careful to preserve shallow-copied values: do not update
   291         # phaseroots values, replace them.
   303         # phaseroots values, replace them.
       
   304         if tr is None:
       
   305             phasetracking = None
       
   306         else:
       
   307             phasetracking = tr.changes.get('phases')
   292 
   308 
   293         repo = repo.unfiltered()
   309         repo = repo.unfiltered()
       
   310 
   294         delroots = [] # set of root deleted by this path
   311         delroots = [] # set of root deleted by this path
   295         for phase in xrange(targetphase + 1, len(allphases)):
   312         for phase in xrange(targetphase + 1, len(allphases)):
   296             # filter nodes that are not in a compatible phase already
   313             # filter nodes that are not in a compatible phase already
   297             nodes = [n for n in nodes
   314             nodes = [n for n in nodes
   298                      if self.phase(repo, repo[n].rev()) >= phase]
   315                      if self.phase(repo, repo[n].rev()) >= phase]
   299             if not nodes:
   316             if not nodes:
   300                 break # no roots to move anymore
   317                 break # no roots to move anymore
   301 
   318 
   302             olds = self.phaseroots[phase]
   319             olds = self.phaseroots[phase]
       
   320 
   303             affected = repo.revs('%ln::%ln', olds, nodes)
   321             affected = repo.revs('%ln::%ln', olds, nodes)
       
   322             for r in affected:
       
   323                 _trackphasechange(phasetracking, r, self.phase(repo, r),
       
   324                                   targetphase)
   304 
   325 
   305             roots = set(ctx.node() for ctx in repo.set(
   326             roots = set(ctx.node() for ctx in repo.set(
   306                     'roots((%ln::) - %ld)', olds, affected))
   327                     'roots((%ln::) - %ld)', olds, affected))
   307             if olds != roots:
   328             if olds != roots:
   308                 self._updateroots(phase, roots, tr)
   329                 self._updateroots(phase, roots, tr)