phases.py
666 lines
| 23.2 KiB
| text/x-python
|
PythonLexer
/ mercurial / phases.py
|
r15659 | """ Mercurial phases support code | ||
--- | ||||
Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org> | ||||
Logilab SA <contact@logilab.fr> | ||||
Augie Fackler <durin42@gmail.com> | ||||
|
r16725 | This software may be used and distributed according to the terms | ||
of the GNU General Public License version 2 or any later version. | ||||
|
r15659 | |||
--- | ||||
This module implements most phase logic in mercurial. | ||||
Basic Concept | ||||
============= | ||||
|
r16724 | A 'changeset phase' is an indicator that tells us how a changeset is | ||
|
r16725 | manipulated and communicated. The details of each phase is described | ||
below, here we describe the properties they have in common. | ||||
|
r15659 | |||
|
r16725 | Like bookmarks, phases are not stored in history and thus are not | ||
permanent and leave no audit trail. | ||||
|
r15659 | |||
|
r16725 | First, no changeset can be in two phases at once. Phases are ordered, | ||
so they can be considered from lowest to highest. The default, lowest | ||||
phase is 'public' - this is the normal phase of existing changesets. A | ||||
child changeset can not be in a lower phase than its parents. | ||||
|
r15659 | |||
These phases share a hierarchy of traits: | ||||
immutable shared | ||||
public: X X | ||||
draft: X | ||||
|
r15705 | secret: | ||
|
r15659 | |||
|
r16724 | Local commits are draft by default. | ||
|
r15659 | |||
|
r16724 | Phase Movement and Exchange | ||
=========================== | ||||
|
r15659 | |||
|
r16725 | Phase data is exchanged by pushkey on pull and push. Some servers have | ||
a publish option set, we call such a server a "publishing server". | ||||
Pushing a draft changeset to a publishing server changes the phase to | ||||
public. | ||||
|
r15659 | |||
A small list of fact/rules define the exchange of phase: | ||||
* old client never changes server states | ||||
* pull never changes server states | ||||
|
r16724 | * publish and old server changesets are seen as public by client | ||
|
r16725 | * any secret changeset seen in another repository is lowered to at | ||
least draft | ||||
|
r15659 | |||
|
r16725 | Here is the final table summing up the 49 possible use cases of phase | ||
exchange: | ||||
|
r15659 | |||
server | ||||
old publish non-publish | ||||
N X N D P N D P | ||||
old client | ||||
pull | ||||
N - X/X - X/D X/P - X/D X/P | ||||
X - X/X - X/D X/P - X/D X/P | ||||
push | ||||
X X/X X/X X/P X/P X/P X/D X/D X/P | ||||
new client | ||||
pull | ||||
N - P/X - P/D P/P - D/D P/P | ||||
D - P/X - P/D P/P - D/D P/P | ||||
P - P/X - P/D P/P - P/D P/P | ||||
push | ||||
D P/X P/X P/P P/P P/P D/D D/D P/P | ||||
P P/X P/X P/P P/P P/P P/P P/P P/P | ||||
Legend: | ||||
A/B = final state on client / state on server | ||||
* N = new/not present, | ||||
* P = public, | ||||
* D = draft, | ||||
|
r16725 | * X = not tracked (i.e., the old client or server has no internal | ||
way of recording the phase.) | ||||
|
r15659 | |||
passive = only pushes | ||||
A cell here can be read like this: | ||||
|
r16725 | "When a new client pushes a draft changeset (D) to a publishing | ||
server where it's not present (N), it's marked public on both | ||||
sides (P/P)." | ||||
|
r15659 | |||
|
r16724 | Note: old client behave as a publishing server with draft only content | ||
|
r15659 | - other people see it as public | ||
- content is pushed as draft | ||||
""" | ||||
|
r15417 | |||
|
r25966 | from __future__ import absolute_import | ||
|
r15419 | import errno | ||
|
r34320 | import struct | ||
|
r25966 | |||
from .i18n import _ | ||||
from .node import ( | ||||
bin, | ||||
hex, | ||||
nullid, | ||||
nullrev, | ||||
short, | ||||
) | ||||
from . import ( | ||||
error, | ||||
|
r31016 | smartset, | ||
|
r31053 | txnutil, | ||
|
r32000 | util, | ||
|
r25966 | ) | ||
|
r15418 | |||
|
r34320 | _fphasesentry = struct.Struct('>i20s') | ||
|
r15818 | allphases = public, draft, secret = range(3) | ||
|
r15417 | trackedphases = allphases[1:] | ||
|
r15821 | phasenames = ['public', 'draft', 'secret'] | ||
|
r15418 | |||
|
r16657 | def _readroots(repo, phasedefaults=None): | ||
|
r16625 | """Read phase roots from disk | ||
phasedefaults is a list of fn(repo, roots) callable, which are | ||||
executed if the phase roots file does not exist. When phases are | ||||
being initialized on an existing repository, this could be used to | ||||
set selected changesets phase to something else than public. | ||||
Return (roots, dirty) where dirty is true if roots differ from | ||||
what is being stored. | ||||
""" | ||||
|
r18002 | repo = repo.unfiltered() | ||
|
r16625 | dirty = False | ||
|
r15418 | roots = [set() for i in allphases] | ||
try: | ||||
|
r31053 | f, pending = txnutil.trypending(repo.root, repo.svfs, 'phaseroots') | ||
|
r15418 | try: | ||
for line in f: | ||||
|
r16588 | phase, nh = line.split() | ||
|
r15418 | roots[int(phase)].add(bin(nh)) | ||
finally: | ||||
f.close() | ||||
|
r25660 | except IOError as inst: | ||
|
r15419 | if inst.errno != errno.ENOENT: | ||
raise | ||||
|
r16625 | if phasedefaults: | ||
for f in phasedefaults: | ||||
roots = f(repo, roots) | ||||
dirty = True | ||||
return roots, dirty | ||||
|
r15418 | |||
|
r34320 | def binaryencode(phasemapping): | ||
"""encode a 'phase -> nodes' mapping into a binary stream | ||||
Since phases are integer the mapping is actually a python list: | ||||
[[PUBLIC_HEADS], [DRAFTS_HEADS], [SECRET_HEADS]] | ||||
""" | ||||
binarydata = [] | ||||
for phase, nodes in enumerate(phasemapping): | ||||
for head in nodes: | ||||
binarydata.append(_fphasesentry.pack(phase, head)) | ||||
return ''.join(binarydata) | ||||
|
r34321 | def binarydecode(stream): | ||
"""decode a binary stream into a 'phase -> nodes' mapping | ||||
Since phases are integer the mapping is actually a python list.""" | ||||
headsbyphase = [[] for i in allphases] | ||||
entrysize = _fphasesentry.size | ||||
while True: | ||||
entry = stream.read(entrysize) | ||||
if len(entry) < entrysize: | ||||
if entry: | ||||
raise error.Abort(_('bad phase-heads stream')) | ||||
break | ||||
phase, node = _fphasesentry.unpack(entry) | ||||
headsbyphase[phase].append(node) | ||||
return headsbyphase | ||||
|
r33451 | def _trackphasechange(data, rev, old, new): | ||
"""add a phase move the <data> dictionnary | ||||
If data is None, nothing happens. | ||||
""" | ||||
if data is None: | ||||
return | ||||
existing = data.get(rev) | ||||
if existing is not None: | ||||
old = existing[0] | ||||
data[rev] = (old, new) | ||||
|
r16657 | class phasecache(object): | ||
|
r16658 | def __init__(self, repo, phasedefaults, _load=True): | ||
if _load: | ||||
# Cheap trick to allow shallow-copy without copy module | ||||
self.phaseroots, self.dirty = _readroots(repo, phasedefaults) | ||||
|
r18220 | self._phaserevs = None | ||
|
r25190 | self._phasesets = None | ||
|
r18220 | self.filterunknown(repo) | ||
|
r23878 | self.opener = repo.svfs | ||
|
r16658 | |||
|
r31016 | def getrevset(self, repo, phases): | ||
"""return a smartset for the given phases""" | ||||
self.loadphaserevs(repo) # ensure phase's sets are loaded | ||||
if self._phasesets and all(self._phasesets[p] is not None | ||||
for p in phases): | ||||
# fast path - use _phasesets | ||||
revs = self._phasesets[phases[0]] | ||||
if len(phases) > 1: | ||||
revs = revs.copy() # only copy when needed | ||||
for p in phases[1:]: | ||||
revs.update(self._phasesets[p]) | ||||
if repo.changelog.filteredrevs: | ||||
revs = revs - repo.changelog.filteredrevs | ||||
return smartset.baseset(revs) | ||||
else: | ||||
# slow path - enumerate all revisions | ||||
phase = self.phase | ||||
revs = (r for r in repo if phase(repo, r) in phases) | ||||
return smartset.generatorset(revs, iterasc=True) | ||||
|
r16658 | def copy(self): | ||
# Shallow copy meant to ensure isolation in | ||||
# advance/retractboundary(), nothing more. | ||||
|
r23631 | ph = self.__class__(None, None, _load=False) | ||
|
r16658 | ph.phaseroots = self.phaseroots[:] | ||
ph.dirty = self.dirty | ||||
ph.opener = self.opener | ||||
ph._phaserevs = self._phaserevs | ||||
|
r25592 | ph._phasesets = self._phasesets | ||
|
r16658 | return ph | ||
def replace(self, phcache): | ||||
|
r25613 | """replace all values in 'self' with content of phcache""" | ||
|
r25614 | for a in ('phaseroots', 'dirty', 'opener', '_phaserevs', '_phasesets'): | ||
|
r16658 | setattr(self, a, getattr(phcache, a)) | ||
|
r16657 | |||
|
r24599 | def _getphaserevsnative(self, repo): | ||
|
r24444 | repo = repo.unfiltered() | ||
nativeroots = [] | ||||
for phase in trackedphases: | ||||
nativeroots.append(map(repo.changelog.rev, self.phaseroots[phase])) | ||||
|
r25527 | return repo.changelog.computephases(nativeroots) | ||
|
r24444 | |||
|
r24599 | def _computephaserevspure(self, repo): | ||
|
r24519 | repo = repo.unfiltered() | ||
revs = [public] * len(repo.changelog) | ||||
self._phaserevs = revs | ||||
self._populatephaseroots(repo) | ||||
for phase in trackedphases: | ||||
|
r31342 | roots = list(map(repo.changelog.rev, self.phaseroots[phase])) | ||
|
r24519 | if roots: | ||
for rev in roots: | ||||
revs[rev] = phase | ||||
for rev in repo.changelog.descendants(roots): | ||||
revs[rev] = phase | ||||
|
r25611 | def loadphaserevs(self, repo): | ||
"""ensure phase information is loaded in the object""" | ||||
|
r22893 | if self._phaserevs is None: | ||
|
r24444 | try: | ||
|
r31152 | res = self._getphaserevsnative(repo) | ||
self._phaserevs, self._phasesets = res | ||||
|
r24444 | except AttributeError: | ||
|
r24599 | self._computephaserevspure(repo) | ||
|
r22894 | |||
|
r22893 | def invalidate(self): | ||
self._phaserevs = None | ||||
|
r25593 | self._phasesets = None | ||
|
r16657 | |||
|
r22894 | def _populatephaseroots(self, repo): | ||
"""Fills the _phaserevs cache with phases for the roots. | ||||
""" | ||||
cl = repo.changelog | ||||
phaserevs = self._phaserevs | ||||
for phase in trackedphases: | ||||
roots = map(cl.rev, self.phaseroots[phase]) | ||||
for root in roots: | ||||
phaserevs[root] = phase | ||||
|
r16657 | def phase(self, repo, rev): | ||
|
r17424 | # We need a repo argument here to be able to build _phaserevs | ||
|
r16657 | # if necessary. The repository instance is not stored in | ||
# phasecache to avoid reference cycles. The changelog instance | ||||
# is not stored because it is a filecache() property and can | ||||
# be replaced without us being notified. | ||||
if rev == nullrev: | ||||
return public | ||||
|
r19984 | if rev < nullrev: | ||
raise ValueError(_('cannot lookup negative revision')) | ||||
|
r16657 | if self._phaserevs is None or rev >= len(self._phaserevs): | ||
|
r22893 | self.invalidate() | ||
|
r25611 | self.loadphaserevs(repo) | ||
|
r16657 | return self._phaserevs[rev] | ||
def write(self): | ||||
if not self.dirty: | ||||
return | ||||
|
r29303 | f = self.opener('phaseroots', 'w', atomictemp=True, checkambig=True) | ||
|
r16657 | try: | ||
|
r22079 | self._write(f) | ||
|
r16657 | finally: | ||
f.close() | ||||
|
r22079 | |||
def _write(self, fp): | ||||
for phase, roots in enumerate(self.phaseroots): | ||||
for h in roots: | ||||
fp.write('%i %s\n' % (phase, hex(h))) | ||||
|
r16657 | self.dirty = False | ||
|
r15454 | |||
|
r22080 | def _updateroots(self, phase, newroots, tr): | ||
|
r16658 | self.phaseroots[phase] = newroots | ||
|
r22893 | self.invalidate() | ||
|
r16658 | self.dirty = True | ||
|
r22080 | tr.addfilegenerator('phase', ('phaseroots',), self._write) | ||
|
r22940 | tr.hookargs['phases_moved'] = '1' | ||
|
r22080 | |||
|
r33453 | def registernew(self, repo, tr, targetphase, nodes): | ||
repo = repo.unfiltered() | ||||
self._retractboundary(repo, tr, targetphase, nodes) | ||||
if tr is not None and 'phases' in tr.changes: | ||||
phasetracking = tr.changes['phases'] | ||||
torev = repo.changelog.rev | ||||
phase = self.phase | ||||
for n in nodes: | ||||
rev = torev(n) | ||||
revphase = phase(repo, rev) | ||||
_trackphasechange(phasetracking, rev, None, revphase) | ||||
repo.invalidatevolatilesets() | ||||
|
r22069 | def advanceboundary(self, repo, tr, targetphase, nodes): | ||
|
r33450 | """Set all 'nodes' to phase 'targetphase' | ||
Nodes with a phase lower than 'targetphase' are not affected. | ||||
""" | ||||
|
r16658 | # Be careful to preserve shallow-copied values: do not update | ||
# phaseroots values, replace them. | ||||
|
r33451 | if tr is None: | ||
phasetracking = None | ||||
else: | ||||
phasetracking = tr.changes.get('phases') | ||||
|
r16658 | |||
|
r18002 | repo = repo.unfiltered() | ||
|
r33451 | |||
|
r16658 | delroots = [] # set of root deleted by this path | ||
for phase in xrange(targetphase + 1, len(allphases)): | ||||
# filter nodes that are not in a compatible phase already | ||||
nodes = [n for n in nodes | ||||
if self.phase(repo, repo[n].rev()) >= phase] | ||||
if not nodes: | ||||
break # no roots to move anymore | ||||
|
r33450 | |||
|
r16658 | olds = self.phaseroots[phase] | ||
|
r33451 | |||
|
r33450 | affected = repo.revs('%ln::%ln', olds, nodes) | ||
|
r33451 | for r in affected: | ||
_trackphasechange(phasetracking, r, self.phase(repo, r), | ||||
targetphase) | ||||
|
r33450 | |||
|
r16658 | roots = set(ctx.node() for ctx in repo.set( | ||
|
r33450 | 'roots((%ln::) - %ld)', olds, affected)) | ||
|
r16658 | if olds != roots: | ||
|
r22080 | self._updateroots(phase, roots, tr) | ||
|
r16658 | # some roots may need to be declared for lower phases | ||
delroots.extend(olds - roots) | ||||
|
r33449 | # declare deleted root in the target phase | ||
if targetphase != 0: | ||||
|
r33452 | self._retractboundary(repo, tr, targetphase, delroots) | ||
|
r18105 | repo.invalidatevolatilesets() | ||
|
r16658 | |||
|
r22070 | def retractboundary(self, repo, tr, targetphase, nodes): | ||
|
r33458 | oldroots = self.phaseroots[:targetphase + 1] | ||
if tr is None: | ||||
phasetracking = None | ||||
else: | ||||
phasetracking = tr.changes.get('phases') | ||||
repo = repo.unfiltered() | ||||
if (self._retractboundary(repo, tr, targetphase, nodes) | ||||
and phasetracking is not None): | ||||
# find the affected revisions | ||||
new = self.phaseroots[targetphase] | ||||
old = oldroots[targetphase] | ||||
affected = set(repo.revs('(%ln::) - (%ln::)', new, old)) | ||||
# find the phase of the affected revision | ||||
for phase in xrange(targetphase, -1, -1): | ||||
if phase: | ||||
roots = oldroots[phase] | ||||
revs = set(repo.revs('%ln::%ld', roots, affected)) | ||||
affected -= revs | ||||
else: # public phase | ||||
revs = affected | ||||
for r in revs: | ||||
_trackphasechange(phasetracking, r, phase, targetphase) | ||||
|
r33452 | repo.invalidatevolatilesets() | ||
def _retractboundary(self, repo, tr, targetphase, nodes): | ||||
|
r16658 | # Be careful to preserve shallow-copied values: do not update | ||
# phaseroots values, replace them. | ||||
|
r18002 | repo = repo.unfiltered() | ||
|
r16658 | currentroots = self.phaseroots[targetphase] | ||
|
r33457 | finalroots = oldroots = set(currentroots) | ||
|
r16658 | newroots = [n for n in nodes | ||
if self.phase(repo, repo[n].rev()) < targetphase] | ||||
if newroots: | ||||
|
r33452 | |||
|
r16659 | if nullid in newroots: | ||
|
r26587 | raise error.Abort(_('cannot change null revision phase')) | ||
|
r16658 | currentroots = currentroots.copy() | ||
currentroots.update(newroots) | ||||
|
r26909 | |||
# Only compute new roots for revs above the roots that are being | ||||
# retracted. | ||||
minnewroot = min(repo[n].rev() for n in newroots) | ||||
aboveroots = [n for n in currentroots | ||||
if repo[n].rev() >= minnewroot] | ||||
updatedroots = repo.set('roots(%ln::)', aboveroots) | ||||
finalroots = set(n for n in currentroots if repo[n].rev() < | ||||
minnewroot) | ||||
finalroots.update(ctx.node() for ctx in updatedroots) | ||||
|
r33457 | if finalroots != oldroots: | ||
|
r26909 | self._updateroots(targetphase, finalroots, tr) | ||
|
r33457 | return True | ||
return False | ||||
|
r16658 | |||
|
r18220 | def filterunknown(self, repo): | ||
"""remove unknown nodes from the phase boundary | ||||
Nothing is lost as unknown nodes only hold data for their descendants. | ||||
""" | ||||
filtered = False | ||||
nodemap = repo.changelog.nodemap # to filter unknown nodes | ||||
for phase, nodes in enumerate(self.phaseroots): | ||||
|
r20550 | missing = sorted(node for node in nodes if node not in nodemap) | ||
|
r18220 | if missing: | ||
for mnode in missing: | ||||
repo.ui.debug( | ||||
'removing unknown node %s from %i-phase boundary\n' | ||||
% (short(mnode), phase)) | ||||
nodes.symmetric_difference_update(missing) | ||||
filtered = True | ||||
if filtered: | ||||
self.dirty = True | ||||
|
r18983 | # filterunknown is called by repo.destroyed, we may have no changes in | ||
|
r19951 | # root but phaserevs contents is certainly invalid (or at least we | ||
# have not proper way to check that). related to issue 3858. | ||||
|
r18983 | # | ||
# The other caller is __init__ that have no _phaserevs initialized | ||||
# anyway. If this change we should consider adding a dedicated | ||||
|
r19951 | # "destroyed" function to phasecache or a proper cache key mechanism | ||
|
r18983 | # (see branchmap one) | ||
|
r22893 | self.invalidate() | ||
|
r18220 | |||
|
r22069 | def advanceboundary(repo, tr, targetphase, nodes): | ||
|
r15454 | """Add nodes to a phase changing other nodes phases if necessary. | ||
|
r16725 | This function move boundary *forward* this means that all nodes | ||
are set in the target phase or kept in a *lower* phase. | ||||
|
r15454 | |||
|
r15482 | Simplify boundary to contains phase roots only.""" | ||
|
r16658 | phcache = repo._phasecache.copy() | ||
|
r22069 | phcache.advanceboundary(repo, tr, targetphase, nodes) | ||
|
r16658 | repo._phasecache.replace(phcache) | ||
|
r15482 | |||
|
r22070 | def retractboundary(repo, tr, targetphase, nodes): | ||
|
r16725 | """Set nodes back to a phase changing other nodes phases if | ||
necessary. | ||||
|
r15482 | |||
|
r16725 | This function move boundary *backward* this means that all nodes | ||
are set in the target phase or kept in a *higher* phase. | ||||
|
r15482 | |||
Simplify boundary to contains phase roots only.""" | ||||
|
r16658 | phcache = repo._phasecache.copy() | ||
|
r22070 | phcache.retractboundary(repo, tr, targetphase, nodes) | ||
|
r16658 | repo._phasecache.replace(phcache) | ||
|
r15648 | |||
|
r33453 | def registernew(repo, tr, targetphase, nodes): | ||
"""register a new revision and its phase | ||||
Code adding revisions to the repository should use this function to | ||||
set new changeset in their target phase (or higher). | ||||
""" | ||||
phcache = repo._phasecache.copy() | ||||
phcache.registernew(repo, tr, targetphase, nodes) | ||||
repo._phasecache.replace(phcache) | ||||
|
r15648 | def listphases(repo): | ||
|
r16724 | """List phases root for serialization over pushkey""" | ||
|
r32000 | # Use ordered dictionary so behavior is deterministic. | ||
keys = util.sortdict() | ||||
|
r15892 | value = '%i' % draft | ||
|
r34817 | cl = repo.unfiltered().changelog | ||
|
r16657 | for root in repo._phasecache.phaseroots[draft]: | ||
|
r34817 | if repo._phasecache.phase(repo, cl.rev(root)) <= draft: | ||
keys[hex(root)] = value | ||||
|
r15892 | |||
|
r25624 | if repo.publishing(): | ||
|
r16725 | # Add an extra data to let remote know we are a publishing | ||
# repo. Publishing repo can't just pretend they are old repo. | ||||
# When pushing to a publishing repo, the client still need to | ||||
# push phase boundary | ||||
|
r15648 | # | ||
|
r16725 | # Push do not only push changeset. It also push phase data. | ||
# New phase data may apply to common changeset which won't be | ||||
# push (as they are common). Here is a very simple example: | ||||
|
r15648 | # | ||
# 1) repo A push changeset X as draft to repo B | ||||
# 2) repo B make changeset X public | ||||
|
r16725 | # 3) repo B push to repo A. X is not pushed but the data that | ||
# X as now public should | ||||
|
r15648 | # | ||
|
r16725 | # The server can't handle it on it's own as it has no idea of | ||
# client phase data. | ||||
|
r15648 | keys['publishing'] = 'True' | ||
return keys | ||||
def pushphase(repo, nhex, oldphasestr, newphasestr): | ||||
|
r17535 | """List phases root for serialization over pushkey""" | ||
|
r18002 | repo = repo.unfiltered() | ||
|
r27861 | with repo.lock(): | ||
|
r15648 | currentphase = repo[nhex].phase() | ||
newphase = abs(int(newphasestr)) # let's avoid negative index surprise | ||||
oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise | ||||
if currentphase == oldphase and newphase < oldphase: | ||||
|
r27874 | with repo.transaction('pushkey-phase') as tr: | ||
|
r27861 | advanceboundary(repo, tr, newphase, [bin(nhex)]) | ||
|
r32822 | return True | ||
|
r16051 | elif currentphase == newphase: | ||
# raced, but got correct result | ||||
|
r32822 | return True | ||
|
r15648 | else: | ||
|
r32822 | return False | ||
|
r15649 | |||
|
r33031 | def subsetphaseheads(repo, subset): | ||
"""Finds the phase heads for a subset of a history | ||||
Returns a list indexed by phase number where each item is a list of phase | ||||
head nodes. | ||||
""" | ||||
cl = repo.changelog | ||||
headsbyphase = [[] for i in allphases] | ||||
# No need to keep track of secret phase; any heads in the subset that | ||||
# are not mentioned are implicitly secret. | ||||
for phase in allphases[:-1]: | ||||
revset = "heads(%%ln & %s())" % phasenames[phase] | ||||
headsbyphase[phase] = [cl.node(r) for r in repo.revs(revset, subset)] | ||||
return headsbyphase | ||||
|
r34322 | def updatephases(repo, trgetter, headsbyphase): | ||
|
r33031 | """Updates the repo with the given phase heads""" | ||
# Now advance phase boundaries of all but secret phase | ||||
|
r34322 | # | ||
# run the update (and fetch transaction) only if there are actually things | ||||
# to update. This avoid creating empty transaction during no-op operation. | ||||
|
r33031 | for phase in allphases[:-1]: | ||
|
r34322 | revset = '%%ln - %s()' % phasenames[phase] | ||
heads = [c.node() for c in repo.set(revset, headsbyphase[phase])] | ||||
if heads: | ||||
advanceboundary(repo, trgetter(), phase, heads) | ||||
|
r33031 | |||
|
r15649 | def analyzeremotephases(repo, subset, roots): | ||
"""Compute phases heads and root in a subset of node from root dict | ||||
* subset is heads of the subset | ||||
* roots is {<nodeid> => phase} mapping. key and value are string. | ||||
Accept unknown element input | ||||
""" | ||||
|
r18002 | repo = repo.unfiltered() | ||
|
r15649 | # build list from dictionary | ||
|
r15892 | draftroots = [] | ||
|
r15902 | nodemap = repo.changelog.nodemap # to filter unknown nodes | ||
|
r15649 | for nhex, phase in roots.iteritems(): | ||
if nhex == 'publishing': # ignore data related to publish option | ||||
continue | ||||
node = bin(nhex) | ||||
phase = int(phase) | ||||
|
r28174 | if phase == public: | ||
|
r15892 | if node != nullid: | ||
|
r15953 | repo.ui.warn(_('ignoring inconsistent public root' | ||
' from remote: %s\n') % nhex) | ||||
|
r28174 | elif phase == draft: | ||
|
r15902 | if node in nodemap: | ||
|
r15892 | draftroots.append(node) | ||
else: | ||||
|
r15953 | repo.ui.warn(_('ignoring unexpected root from remote: %i %s\n') | ||
% (phase, nhex)) | ||||
|
r15649 | # compute heads | ||
|
r15954 | publicheads = newheads(repo, subset, draftroots) | ||
|
r15892 | return publicheads, draftroots | ||
|
r15649 | |||
|
r34820 | class remotephasessummary(object): | ||
"""summarize phase information on the remote side | ||||
:publishing: True is the remote is publishing | ||||
:publicheads: list of remote public phase heads (nodes) | ||||
:draftheads: list of remote draft phase heads (nodes) | ||||
:draftroots: list of remote draft phase root (nodes) | ||||
""" | ||||
def __init__(self, repo, remotesubset, remoteroots): | ||||
unfi = repo.unfiltered() | ||||
self._allremoteroots = remoteroots | ||||
self.publishing = remoteroots.get('publishing', False) | ||||
ana = analyzeremotephases(repo, remotesubset, remoteroots) | ||||
self.publicheads, self.draftroots = ana | ||||
# Get the list of all "heads" revs draft on remote | ||||
dheads = unfi.set('heads(%ln::%ln)', self.draftroots, remotesubset) | ||||
self.draftheads = [c.node() for c in dheads] | ||||
|
r15954 | def newheads(repo, heads, roots): | ||
"""compute new head of a subset minus another | ||||
* `heads`: define the first subset | ||||
|
r17425 | * `roots`: define the second we subtract from the first""" | ||
|
r18002 | repo = repo.unfiltered() | ||
|
r15954 | revset = repo.set('heads((%ln + parents(%ln)) - (%ln::%ln))', | ||
heads, roots, roots, heads) | ||||
return [c.node() for c in revset] | ||||
|
r16030 | |||
def newcommitphase(ui): | ||||
"""helper to get the target phase of new commit | ||||
Handle all possible values for the phases.new-commit options. | ||||
""" | ||||
|
r34564 | v = ui.config('phases', 'new-commit') | ||
|
r16030 | try: | ||
return phasenames.index(v) | ||||
except ValueError: | ||||
try: | ||||
return int(v) | ||||
except ValueError: | ||||
msg = _("phases.new-commit: not a valid phase name ('%s')") | ||||
raise error.ConfigError(msg % v) | ||||
|
r17671 | def hassecret(repo): | ||
"""utility function that check if a repo have any secret changeset.""" | ||||
return bool(repo._phasecache.phaseroots[2]) | ||||
|
r34711 | |||
def preparehookargs(node, old, new): | ||||
if old is None: | ||||
old = '' | ||||
else: | ||||
|
r34877 | old = phasenames[old] | ||
|
r34711 | return {'node': node, | ||
'oldphase': old, | ||||
|
r34877 | 'phase': phasenames[new]} | ||