comparison mercurial/scmutil.py @ 38432:05b7dd11918e

cleanupnodes: preserve phase of parents of new nodes As Yuya noted in the review of D3818, passing in targetphase=phases.draft would result in advancing the phase boundary of a secret-phase parent. We never pass targetphase=phases.draft so far, but it's a bug waiting to happen. I tried to refactor it so max(parentphase, X) happened in one place, but I couldn't come up with good variables names and I ended up with a "newphase = max(newphase, parentphase)" line, which made the whole block not look any better to me. Differential Revision: https://phab.mercurial-scm.org/D3824
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 21 Jun 2018 08:22:11 -0700
parents 32fba6fe893d
children 1cac2e8c7624
comparison
equal deleted inserted replaced
38431:d6686f864a70 38432:05b7dd11918e
840 newphases = {} 840 newphases = {}
841 def phase(ctx): 841 def phase(ctx):
842 return newphases.get(ctx.node(), ctx.phase()) 842 return newphases.get(ctx.node(), ctx.phase())
843 for newnode in allnewnodes: 843 for newnode in allnewnodes:
844 ctx = unfi[newnode] 844 ctx = unfi[newnode]
845 parentphase = max(phase(p) for p in ctx.parents())
845 if targetphase is None: 846 if targetphase is None:
846 oldphase = max(unfi[oldnode].phase() 847 oldphase = max(unfi[oldnode].phase()
847 for oldnode in precursors[newnode]) 848 for oldnode in precursors[newnode])
848 parentphase = max(phase(p) for p in ctx.parents())
849 newphase = max(oldphase, parentphase) 849 newphase = max(oldphase, parentphase)
850 else: 850 else:
851 newphase = targetphase 851 newphase = max(targetphase, parentphase)
852 newphases[newnode] = newphase 852 newphases[newnode] = newphase
853 if newphase > ctx.phase(): 853 if newphase > ctx.phase():
854 toretract.setdefault(newphase, []).append(newnode) 854 toretract.setdefault(newphase, []).append(newnode)
855 elif newphase < ctx.phase(): 855 elif newphase < ctx.phase():
856 toadvance.setdefault(newphase, []).append(newnode) 856 toadvance.setdefault(newphase, []).append(newnode)