##// END OF EJS Templates
engine: add `if True` to prepare for next patch...
engine: add `if True` to prepare for next patch This will help making next patch easier to read. Differential Revision: https://phab.mercurial-scm.org/D9774

File last commit:

r46375:5d65e04b default
r47096:ee9002b9 default
Show More
phases.py
936 lines | 31.2 KiB | text/x-python | PythonLexer
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
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>
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 This software may be used and distributed according to the terms
of the GNU General Public License version 2 or any later version.
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
---
This module implements most phase logic in mercurial.
Basic Concept
=============
Martin Geisler
phases: fix typos in docstrings
r16724 A 'changeset phase' is an indicator that tells us how a changeset is
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 manipulated and communicated. The details of each phase is described
below, here we describe the properties they have in common.
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 Like bookmarks, phases are not stored in history and thus are not
permanent and leave no audit trail.
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
Martin Geisler
phases: wrap docstrings at 70 characters
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.
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
These phases share a hierarchy of traits:
immutable shared
public: X X
draft: X
Pierre-Yves David
phases: update doc to mention secret phase
r15705 secret:
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
Martin Geisler
phases: fix typos in docstrings
r16724 Local commits are draft by default.
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
Martin Geisler
phases: fix typos in docstrings
r16724 Phase Movement and Exchange
===========================
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
Martin Geisler
phases: wrap docstrings at 70 characters
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.
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
A small list of fact/rules define the exchange of phase:
* old client never changes server states
* pull never changes server states
Martin Geisler
phases: fix typos in docstrings
r16724 * publish and old server changesets are seen as public by client
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 * any secret changeset seen in another repository is lowered to at
least draft
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 Here is the final table summing up the 49 possible use cases of phase
exchange:
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
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,
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 * X = not tracked (i.e., the old client or server has no internal
way of recording the phase.)
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
passive = only pushes
A cell here can be read like this:
Martin Geisler
phases: wrap docstrings at 70 characters
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)."
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659
Martin Geisler
phases: fix typos in docstrings
r16724 Note: old client behave as a publishing server with draft only content
Pierre-Yves David
phases: change publish behavior to only alter behavior when server....
r15659 - other people see it as public
- content is pushed as draft
"""
Pierre-Yves David
phases: Minimal first add.
r15417
Gregory Szorc
phases: use absolute_import
r25966 from __future__ import absolute_import
Matt Mackall
phases: handle errors other than ENOENT appropriately
r15419 import errno
Boris Feld
phases: move binary encoding into a reusable function...
r34320 import struct
Gregory Szorc
phases: use absolute_import
r25966
from .i18n import _
from .node import (
bin,
hex,
nullid,
nullrev,
short,
Rodrigo Damazio Bovendorp
phases: make the working directory consistently a draft...
r44456 wdirrev,
Gregory Szorc
phases: use absolute_import
r25966 )
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 from .pycompat import (
getattr,
setattr,
)
Gregory Szorc
phases: use absolute_import
r25966 from . import (
error,
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 pycompat,
Pulkit Goyal
requirements: introduce new requirements related module...
r45932 requirements,
Jun Wu
phases: add a getrevset method to phasecache...
r31016 smartset,
FUJIWARA Katsunori
phases: check HG_PENDING strictly...
r31053 txnutil,
Gregory Szorc
phases: emit phases to pushkey protocol in deterministic order...
r32000 util,
Gregory Szorc
phases: use absolute_import
r25966 )
Pierre-Yves David
phases: basic I/O logic...
r15418
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _fphasesentry = struct.Struct(b'>i20s')
Boris Feld
phases: move binary encoding into a reusable function...
r34320
Boris Feld
phases: add an internal phases...
r39333 # record phase index
public, draft, secret = range(3)
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 archived = 32 # non-continuous for compatibility
internal = 96 # non-continuous for compatibility
allphases = (public, draft, secret, archived, internal)
trackedphases = (draft, secret, archived, internal)
Boris Feld
phases: add an internal phases...
r39333 # record phase names
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cmdphasenames = [b'public', b'draft', b'secret'] # known to `hg phase` command
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 phasenames = dict(enumerate(cmdphasenames))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 phasenames[archived] = b'archived'
phasenames[internal] = b'internal'
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 # map phase name to phase number
phasenumber = {name: phase for phase, name in phasenames.items()}
# like phasenumber, but also include maps for the numeric and binary
# phase number to the phase number
phasenumber2 = phasenumber.copy()
phasenumber2.update({phase: phase for phase in phasenames})
phasenumber2.update({b'%i' % phase: phase for phase in phasenames})
Boris Feld
phases: add an internal phases...
r39333 # record phase property
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 mutablephases = (draft, secret, archived, internal)
remotehiddenphases = (secret, archived, internal)
localhiddenphases = (internal, archived)
Pierre-Yves David
phases: basic I/O logic...
r15418
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
phases: enforce internal phase support...
r39335 def supportinternal(repo):
"""True if the internal phase can be used on a repository"""
Pulkit Goyal
requirements: introduce new requirements related module...
r45932 return requirements.INTERNAL_PHASE_REQUIREMENT in repo.requirements
Boris Feld
phases: enforce internal phase support...
r39335
Augie Fackler
formatting: blacken the codebase...
r43346
Patrick Mezard
phases: introduce phasecache...
r16657 def _readroots(repo, phasedefaults=None):
Patrick Mezard
phases: stop modifying localrepo in readroots()...
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.
"""
Pierre-Yves David
clfilter: phases logic should be unfiltered...
r18002 repo = repo.unfiltered()
Patrick Mezard
phases: stop modifying localrepo in readroots()...
r16625 dirty = False
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 roots = {i: set() for i in allphases}
Pierre-Yves David
phases: basic I/O logic...
r15418 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f, pending = txnutil.trypending(repo.root, repo.svfs, b'phaseroots')
Pierre-Yves David
phases: basic I/O logic...
r15418 try:
for line in f:
Martin Geisler
phases: line.strip().split() == line.split()
r16588 phase, nh = line.split()
Pierre-Yves David
phases: basic I/O logic...
r15418 roots[int(phase)].add(bin(nh))
finally:
f.close()
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except IOError as inst:
Matt Mackall
phases: handle errors other than ENOENT appropriately
r15419 if inst.errno != errno.ENOENT:
raise
Patrick Mezard
phases: stop modifying localrepo in readroots()...
r16625 if phasedefaults:
for f in phasedefaults:
roots = f(repo, roots)
dirty = True
return roots, dirty
Pierre-Yves David
phases: basic I/O logic...
r15418
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
phases: move binary encoding into a reusable function...
r34320 def binaryencode(phasemapping):
"""encode a 'phase -> nodes' mapping into a binary stream
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 The revision lists are encoded as (phase, root) pairs.
Boris Feld
phases: move binary encoding into a reusable function...
r34320 """
binarydata = []
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 for phase, nodes in pycompat.iteritems(phasemapping):
Boris Feld
phases: move binary encoding into a reusable function...
r34320 for head in nodes:
binarydata.append(_fphasesentry.pack(phase, head))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(binarydata)
Boris Feld
phases: move binary encoding into a reusable function...
r34320
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
phases: move the binary decoding function in the phases module...
r34321 def binarydecode(stream):
"""decode a binary stream into a 'phase -> nodes' mapping
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 The (phase, root) pairs are turned back into a dictionary with
the phase as index and the aggregated roots of that phase as value."""
headsbyphase = {i: [] for i in allphases}
Boris Feld
phases: move the binary decoding function in the phases module...
r34321 entrysize = _fphasesentry.size
while True:
entry = stream.read(entrysize)
if len(entry) < entrysize:
if entry:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'bad phase-heads stream'))
Boris Feld
phases: move the binary decoding function in the phases module...
r34321 break
phase, node = _fphasesentry.unpack(entry)
headsbyphase[phase].append(node)
return headsbyphase
Augie Fackler
formatting: blacken the codebase...
r43346
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 def _sortedrange_insert(data, idx, rev, t):
merge_before = False
if idx:
r1, t1 = data[idx - 1]
merge_before = r1[-1] + 1 == rev and t1 == t
merge_after = False
if idx < len(data):
r2, t2 = data[idx]
merge_after = r2[0] == rev + 1 and t2 == t
if merge_before and merge_after:
data[idx - 1] = (pycompat.xrange(r1[0], r2[-1] + 1), t)
data.pop(idx)
elif merge_before:
data[idx - 1] = (pycompat.xrange(r1[0], rev + 1), t)
elif merge_after:
data[idx] = (pycompat.xrange(rev, r2[-1] + 1), t)
else:
data.insert(idx, (pycompat.xrange(rev, rev + 1), t))
def _sortedrange_split(data, idx, rev, t):
r1, t1 = data[idx]
if t == t1:
return
t = (t1[0], t[1])
if len(r1) == 1:
data.pop(idx)
_sortedrange_insert(data, idx, rev, t)
elif r1[0] == rev:
data[idx] = (pycompat.xrange(rev + 1, r1[-1] + 1), t1)
_sortedrange_insert(data, idx, rev, t)
elif r1[-1] == rev:
data[idx] = (pycompat.xrange(r1[0], rev), t1)
_sortedrange_insert(data, idx + 1, rev, t)
else:
data[idx : idx + 1] = [
(pycompat.xrange(r1[0], rev), t1),
(pycompat.xrange(rev, rev + 1), t),
(pycompat.xrange(rev + 1, r1[-1] + 1), t1),
]
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451 def _trackphasechange(data, rev, old, new):
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 """add a phase move to the <data> list of ranges
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451
If data is None, nothing happens.
"""
if data is None:
return
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036
# If data is empty, create a one-revision range and done
if not data:
data.insert(0, (pycompat.xrange(rev, rev + 1), (old, new)))
return
low = 0
high = len(data)
t = (old, new)
while low < high:
mid = (low + high) // 2
revs = data[mid][0]
Joerg Sonnenberger
phases: fix performance regression with Python 2...
r46127 revs_low = revs[0]
revs_high = revs[-1]
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036
Joerg Sonnenberger
phases: fix performance regression with Python 2...
r46127 if rev >= revs_low and rev <= revs_high:
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 _sortedrange_split(data, mid, rev, t)
return
Joerg Sonnenberger
phases: fix performance regression with Python 2...
r46127 if revs_low == rev + 1:
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 if mid and data[mid - 1][0][-1] == rev:
_sortedrange_split(data, mid - 1, rev, t)
else:
_sortedrange_insert(data, mid, rev, t)
return
Joerg Sonnenberger
phases: fix performance regression with Python 2...
r46127 if revs_high == rev - 1:
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 if mid + 1 < len(data) and data[mid + 1][0][0] == rev:
_sortedrange_split(data, mid + 1, rev, t)
else:
_sortedrange_insert(data, mid + 1, rev, t)
return
Joerg Sonnenberger
phases: fix performance regression with Python 2...
r46127 if revs_low > rev:
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 high = mid
else:
low = mid + 1
if low == len(data):
data.append((pycompat.xrange(rev, rev + 1), t))
return
r1, t1 = data[low]
if r1[0] > rev:
data.insert(low, (pycompat.xrange(rev, rev + 1), t))
else:
data.insert(low + 1, (pycompat.xrange(rev, rev + 1), t))
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451
Augie Fackler
formatting: blacken the codebase...
r43346
Patrick Mezard
phases: introduce phasecache...
r16657 class phasecache(object):
Patrick Mezard
phases: make advance/retractboundary() atomic...
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)
Yuya Nishihara
phases: initialize number of loaded revisions to 0...
r35458 self._loadedrevslen = 0
Laurent Charignon
phases: add set per phase in C phase computation...
r25190 self._phasesets = None
Idan Kamara
phases: make _filterunknown a member function of phasecache...
r18220 self.filterunknown(repo)
Angel Ezquerra
localrepo: remove all external users of localrepo.sopener...
r23878 self.opener = repo.svfs
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674 def hasnonpublicphases(self, repo):
"""detect if there are revisions with non-public phase"""
repo = repo.unfiltered()
cl = repo.changelog
if len(cl) >= self._loadedrevslen:
self.invalidate()
self.loadphaserevs(repo)
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 return any(
revs
for phase, revs in pycompat.iteritems(self.phaseroots)
if phase != public
)
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674
def nonpublicphaseroots(self, repo):
"""returns the roots of all non-public phases
The roots are not minimized, so if the secret revisions are
descendants of draft revisions, their roots will still be present.
"""
repo = repo.unfiltered()
cl = repo.changelog
if len(cl) >= self._loadedrevslen:
self.invalidate()
self.loadphaserevs(repo)
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 return set().union(
*[
revs
for phase, revs in pycompat.iteritems(self.phaseroots)
if phase != public
]
)
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674
Jun Wu
revset: use phasecache.getrevset to calculate public()...
r35331 def getrevset(self, repo, phases, subset=None):
Jun Wu
phases: add a getrevset method to phasecache...
r31016 """return a smartset for the given phases"""
Augie Fackler
formatting: blacken the codebase...
r43346 self.loadphaserevs(repo) # ensure phase's sets are loaded
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 phases = set(phases)
Rodrigo Damazio Bovendorp
phases: reduce code duplication in phasecache.getrevset...
r44521 publicphase = public in phases
Rodrigo Damazio Bovendorp
phases: make the working directory consistently a draft...
r44456
Rodrigo Damazio Bovendorp
phases: reduce code duplication in phasecache.getrevset...
r44521 if publicphase:
# In this case, phases keeps all the *other* phases.
phases = set(allphases).difference(phases)
if not phases:
return smartset.fullreposet(repo)
# fast path: _phasesets contains the interesting sets,
# might only need a union and post-filtering.
Rodrigo Damazio Bovendorp
phases: make phasecache._phasesets immutable...
r44522 revsneedscopy = False
Rodrigo Damazio Bovendorp
phases: reduce code duplication in phasecache.getrevset...
r44521 if len(phases) == 1:
[p] = phases
revs = self._phasesets[p]
Rodrigo Damazio Bovendorp
phases: make phasecache._phasesets immutable...
r44522 revsneedscopy = True # Don't modify _phasesets
Rodrigo Damazio Bovendorp
phases: reduce code duplication in phasecache.getrevset...
r44521 else:
# revs has the revisions in all *other* phases.
revs = set.union(*[self._phasesets[p] for p in phases])
def _addwdir(wdirsubset, wdirrevs):
if wdirrev in wdirsubset and repo[None].phase() in phases:
Rodrigo Damazio Bovendorp
phases: make phasecache._phasesets immutable...
r44522 if revsneedscopy:
wdirrevs = wdirrevs.copy()
Rodrigo Damazio Bovendorp
phases: reduce code duplication in phasecache.getrevset...
r44521 # The working dir would never be in the # cache, but it was in
# the subset being filtered for its phase (or filtered out,
# depending on publicphase), so add it to the output to be
# included (or filtered out).
wdirrevs.add(wdirrev)
return wdirrevs
if not publicphase:
Jun Wu
phases: add a getrevset method to phasecache...
r31016 if repo.changelog.filteredrevs:
revs = revs - repo.changelog.filteredrevs
Rodrigo Damazio Bovendorp
phases: make the working directory consistently a draft...
r44456
Jun Wu
revset: use phasecache.getrevset to calculate public()...
r35331 if subset is None:
return smartset.baseset(revs)
else:
Rodrigo Damazio Bovendorp
phases: reduce code duplication in phasecache.getrevset...
r44521 revs = _addwdir(subset, revs)
Jun Wu
revset: use phasecache.getrevset to calculate public()...
r35331 return subset & smartset.baseset(revs)
Jun Wu
phases: add a getrevset method to phasecache...
r31016 else:
Jun Wu
revset: use phasecache.getrevset to calculate public()...
r35331 if subset is None:
subset = smartset.fullreposet(repo)
Rodrigo Damazio Bovendorp
phases: make the working directory consistently a draft...
r44456
Rodrigo Damazio Bovendorp
phases: reduce code duplication in phasecache.getrevset...
r44521 revs = _addwdir(subset, revs)
Rodrigo Damazio Bovendorp
phases: make the working directory consistently a draft...
r44456
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 if not revs:
Jun Wu
revset: use phasecache.getrevset to calculate public()...
r35331 return subset
return subset.filter(lambda r: r not in revs)
Jun Wu
phases: add a getrevset method to phasecache...
r31016
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 def copy(self):
# Shallow copy meant to ensure isolation in
# advance/retractboundary(), nothing more.
Eric Sumner
bundlerepo: implement safe phasecache...
r23631 ph = self.__class__(None, None, _load=False)
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 ph.phaseroots = self.phaseroots.copy()
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 ph.dirty = self.dirty
ph.opener = self.opener
Yuya Nishihara
phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value...
r35457 ph._loadedrevslen = self._loadedrevslen
Pierre-Yves David
phase: also copy phase's sets when copying phase cache...
r25592 ph._phasesets = self._phasesets
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 return ph
def replace(self, phcache):
Pierre-Yves David
phase: document the replace method...
r25613 """replace all values in 'self' with content of phcache"""
Augie Fackler
formatting: blacken the codebase...
r43346 for a in (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'phaseroots',
b'dirty',
b'opener',
b'_loadedrevslen',
b'_phasesets',
Augie Fackler
formatting: blacken the codebase...
r43346 ):
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 setattr(self, a, getattr(phcache, a))
Patrick Mezard
phases: introduce phasecache...
r16657
Laurent Charignon
phases: make two functions private for phase computation
r24599 def _getphaserevsnative(self, repo):
Laurent Charignon
phase: default to C implementation for phase computation
r24444 repo = repo.unfiltered()
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 return repo.changelog.computephases(self.phaseroots)
Laurent Charignon
phase: default to C implementation for phase computation
r24444
Laurent Charignon
phases: make two functions private for phase computation
r24599 def _computephaserevspure(self, repo):
Laurent Charignon
phases: move pure phase computation in a function
r24519 repo = repo.unfiltered()
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 cl = repo.changelog
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 self._phasesets = {phase: set() for phase in allphases}
Boris Feld
phase: use `trackedphases` in `_getphaserevsnative`...
r39307 lowerroots = set()
for phase in reversed(trackedphases):
roots = pycompat.maplist(cl.rev, self.phaseroots[phase])
if roots:
ps = set(cl.descendants(roots))
for root in roots:
ps.add(root)
ps.difference_update(lowerroots)
lowerroots.update(ps)
self._phasesets[phase] = ps
Yuya Nishihara
phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value...
r35457 self._loadedrevslen = len(cl)
Laurent Charignon
phases: move pure phase computation in a function
r24519
Pierre-Yves David
phase: rename getphaserevs to loadphaserevs...
r25611 def loadphaserevs(self, repo):
"""ensure phase information is loaded in the object"""
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 if self._phasesets is None:
Laurent Charignon
phase: default to C implementation for phase computation
r24444 try:
Jun Wu
phases: remove experimental.nativephaseskillswitch...
r31152 res = self._getphaserevsnative(repo)
Yuya Nishihara
phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value...
r35457 self._loadedrevslen, self._phasesets = res
Laurent Charignon
phase: default to C implementation for phase computation
r24444 except AttributeError:
Laurent Charignon
phases: make two functions private for phase computation
r24599 self._computephaserevspure(repo)
Durham Goode
phases: move root phase assignment to it's own function...
r22894
Durham Goode
phases: add invalidate function...
r22893 def invalidate(self):
Yuya Nishihara
phases: initialize number of loaded revisions to 0...
r35458 self._loadedrevslen = 0
Pierre-Yves David
phase: invalidate the phase's set cache alongside the revs...
r25593 self._phasesets = None
Patrick Mezard
phases: introduce phasecache...
r16657
def phase(self, repo, rev):
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 # We need a repo argument here to be able to build _phasesets
Patrick Mezard
phases: introduce phasecache...
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
Durham Goode
rebase: fix rebase aborts when 'tip-1' is public (issue4082)...
r19984 if rev < nullrev:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise ValueError(_(b'cannot lookup negative revision'))
Yuya Nishihara
phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value...
r35457 if rev >= self._loadedrevslen:
Durham Goode
phases: add invalidate function...
r22893 self.invalidate()
Pierre-Yves David
phase: rename getphaserevs to loadphaserevs...
r25611 self.loadphaserevs(repo)
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 for phase in trackedphases:
if rev in self._phasesets[phase]:
return phase
return public
Patrick Mezard
phases: introduce phasecache...
r16657
def write(self):
if not self.dirty:
return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = self.opener(b'phaseroots', b'w', atomictemp=True, checkambig=True)
Patrick Mezard
phases: introduce phasecache...
r16657 try:
Pierre-Yves David
phase: extract the phaseroots serialization in a dedicated method...
r22079 self._write(f)
Patrick Mezard
phases: introduce phasecache...
r16657 finally:
f.close()
Pierre-Yves David
phase: extract the phaseroots serialization in a dedicated method...
r22079
def _write(self, fp):
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 for phase, roots in pycompat.iteritems(self.phaseroots):
Gregory Szorc
phases: write phaseroots deterministically...
r36470 for h in sorted(roots):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fp.write(b'%i %s\n' % (phase, hex(h)))
Patrick Mezard
phases: introduce phasecache...
r16657 self.dirty = False
Pierre-Yves David
phases: add a moveboundary function to move phases boundaries...
r15454
Pierre-Yves David
phase: attach phase to the transaction instead of the lock...
r22080 def _updateroots(self, phase, newroots, tr):
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 self.phaseroots[phase] = newroots
Durham Goode
phases: add invalidate function...
r22893 self.invalidate()
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 self.dirty = True
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 tr.addfilegenerator(b'phase', (b'phaseroots',), self._write)
tr.hookargs[b'phases_moved'] = b'1'
Pierre-Yves David
phase: attach phase to the transaction instead of the lock...
r22080
Joerg Sonnenberger
phases: convert registernew users to use revision sets...
r46375 def registernew(self, repo, tr, targetphase, revs):
Boris Feld
phases: add a 'registernew' method to set new phases...
r33453 repo = repo.unfiltered()
Joerg Sonnenberger
phases: convert registernew users to use revision sets...
r46375 self._retractboundary(repo, tr, targetphase, [], revs=revs)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if tr is not None and b'phases' in tr.changes:
phasetracking = tr.changes[b'phases']
Boris Feld
phases: add a 'registernew' method to set new phases...
r33453 phase = self.phase
Joerg Sonnenberger
phases: convert registernew users to use revision sets...
r46375 for rev in sorted(revs):
Boris Feld
phases: add a 'registernew' method to set new phases...
r33453 revphase = phase(repo, rev)
_trackphasechange(phasetracking, rev, None, revphase)
repo.invalidatevolatilesets()
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 def advanceboundary(
self, repo, tr, targetphase, nodes, revs=None, dryrun=None
):
Boris Feld
phases: extract the intermediate set of affected revs...
r33450 """Set all 'nodes' to phase 'targetphase'
Nodes with a phase lower than 'targetphase' are not affected.
Sushil khanchi
advanceboundary: add dryrun parameter...
r38218
If dryrun is True, no actions will be performed
Returns a set of revs whose phase is changed or should be changed
Boris Feld
phases: extract the intermediate set of affected revs...
r33450 """
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 # Be careful to preserve shallow-copied values: do not update
# phaseroots values, replace them.
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 if revs is None:
revs = []
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451 if tr is None:
phasetracking = None
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 phasetracking = tr.changes.get(b'phases')
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
Pierre-Yves David
clfilter: phases logic should be unfiltered...
r18002 repo = repo.unfiltered()
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 revs = [repo[n].rev() for n in nodes] + [r for r in revs]
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451
Augie Fackler
formatting: blacken the codebase...
r43346 changes = set() # set of revisions to be changed
delroots = [] # set of root deleted by this path
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 for phase in (phase for phase in allphases if phase > targetphase):
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 # filter nodes that are not in a compatible phase already
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 revs = [rev for rev in revs if self.phase(repo, rev) >= phase]
if not revs:
Augie Fackler
formatting: blacken the codebase...
r43346 break # no roots to move anymore
Boris Feld
phases: extract the intermediate set of affected revs...
r33450
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 olds = self.phaseroots[phase]
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 affected = repo.revs(b'%ln::%ld', olds, revs)
Sushil khanchi
advanceboundary: add dryrun parameter...
r38218 changes.update(affected)
if dryrun:
continue
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451 for r in affected:
Augie Fackler
formatting: blacken the codebase...
r43346 _trackphasechange(
phasetracking, r, self.phase(repo, r), targetphase
)
Boris Feld
phases: extract the intermediate set of affected revs...
r33450
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 roots = {
Augie Fackler
formatting: blacken the codebase...
r43346 ctx.node()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for ctx in repo.set(b'roots((%ln::) - %ld)', olds, affected)
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 }
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 if olds != roots:
Pierre-Yves David
phase: attach phase to the transaction instead of the lock...
r22080 self._updateroots(phase, roots, tr)
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 # some roots may need to be declared for lower phases
delroots.extend(olds - roots)
Sushil khanchi
advanceboundary: add dryrun parameter...
r38218 if not dryrun:
# declare deleted root in the target phase
if targetphase != 0:
self._retractboundary(repo, tr, targetphase, delroots)
repo.invalidatevolatilesets()
return changes
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
Pierre-Yves David
phase: add a transaction argument to retractboundary...
r22070 def retractboundary(self, repo, tr, targetphase, nodes):
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 oldroots = {
phase: revs
for phase, revs in pycompat.iteritems(self.phaseroots)
if phase <= targetphase
}
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458 if tr is None:
phasetracking = None
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 phasetracking = tr.changes.get(b'phases')
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458 repo = repo.unfiltered()
Augie Fackler
formatting: blacken the codebase...
r43346 if (
self._retractboundary(repo, tr, targetphase, nodes)
and phasetracking is not None
):
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458
# find the affected revisions
new = self.phaseroots[targetphase]
old = oldroots[targetphase]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 affected = set(repo.revs(b'(%ln::) - (%ln::)', new, old))
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458
# find the phase of the affected revision
Gregory Szorc
global: use pycompat.xrange()...
r38806 for phase in pycompat.xrange(targetphase, -1, -1):
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458 if phase:
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 roots = oldroots.get(phase, [])
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revs = set(repo.revs(b'%ln::%ld', roots, affected))
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458 affected -= revs
Augie Fackler
formatting: blacken the codebase...
r43346 else: # public phase
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458 revs = affected
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 for r in sorted(revs):
Boris Feld
phases: track phase changes from 'retractboundary'...
r33458 _trackphasechange(phasetracking, r, phase, targetphase)
Boris Feld
phases: extract the core of boundary retraction in '_retractboundary'...
r33452 repo.invalidatevolatilesets()
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 def _retractboundary(self, repo, tr, targetphase, nodes, revs=None):
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 # Be careful to preserve shallow-copied values: do not update
# phaseroots values, replace them.
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 if revs is None:
revs = []
Boris Feld
phase: add an archived phase...
r40463 if targetphase in (archived, internal) and not supportinternal(repo):
name = phasenames[targetphase]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = b'this repository does not support the %s phase' % name
Boris Feld
phases: enforce internal phase support...
r39335 raise error.ProgrammingError(msg)
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
Pierre-Yves David
clfilter: phases logic should be unfiltered...
r18002 repo = repo.unfiltered()
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521 torev = repo.changelog.rev
tonode = repo.changelog.node
currentroots = {torev(node) for node in self.phaseroots[targetphase]}
Boris Feld
phases: detect when boundaries has been actually retracted...
r33457 finalroots = oldroots = set(currentroots)
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 newroots = [torev(node) for node in nodes] + [r for r in revs]
Augie Fackler
formatting: blacken the codebase...
r43346 newroots = [
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521 rev for rev in newroots if self.phase(repo, rev) < targetphase
Augie Fackler
formatting: blacken the codebase...
r43346 ]
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 if newroots:
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521 if nullrev in newroots:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'cannot change null revision phase'))
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 currentroots.update(newroots)
Durham Goode
phase: improve retractboundary perf...
r26909
# Only compute new roots for revs above the roots that are being
# retracted.
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521 minnewroot = min(newroots)
aboveroots = [rev for rev in currentroots if rev >= minnewroot]
Yuya Nishihara
phases: remove useless lookup of repo[rev].rev() in _retractboundary...
r45526 updatedroots = repo.revs(b'roots(%ld::)', aboveroots)
Durham Goode
phase: improve retractboundary perf...
r26909
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521 finalroots = {rev for rev in currentroots if rev < minnewroot}
Yuya Nishihara
phases: remove useless lookup of repo[rev].rev() in _retractboundary...
r45526 finalroots.update(updatedroots)
Boris Feld
phases: detect when boundaries has been actually retracted...
r33457 if finalroots != oldroots:
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521 self._updateroots(
targetphase, {tonode(rev) for rev in finalroots}, tr
)
Boris Feld
phases: detect when boundaries has been actually retracted...
r33457 return True
return False
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
Idan Kamara
phases: make _filterunknown a member function of phasecache...
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
index: use `index.has_node` in `phases.filterunknown`...
r43939 has_node = repo.changelog.index.has_node # to filter unknown nodes
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 for phase, nodes in pycompat.iteritems(self.phaseroots):
index: use `index.has_node` in `phases.filterunknown`...
r43939 missing = sorted(node for node in nodes if not has_node(node))
Idan Kamara
phases: make _filterunknown a member function of phasecache...
r18220 if missing:
for mnode in missing:
repo.ui.debug(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'removing unknown node %s from %i-phase boundary\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % (short(mnode), phase)
)
Idan Kamara
phases: make _filterunknown a member function of phasecache...
r18220 nodes.symmetric_difference_update(missing)
filtered = True
if filtered:
self.dirty = True
Pierre-Yves David
destroyed: invalidate phraserevs cache in all case (issue3858)...
r18983 # filterunknown is called by repo.destroyed, we may have no changes in
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 # root but _phasesets contents is certainly invalid (or at least we
Mads Kiilerich
spelling: random spell checker fixes
r19951 # have not proper way to check that). related to issue 3858.
Pierre-Yves David
destroyed: invalidate phraserevs cache in all case (issue3858)...
r18983 #
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 # The other caller is __init__ that have no _phasesets initialized
Pierre-Yves David
destroyed: invalidate phraserevs cache in all case (issue3858)...
r18983 # anyway. If this change we should consider adding a dedicated
Mads Kiilerich
spelling: random spell checker fixes
r19951 # "destroyed" function to phasecache or a proper cache key mechanism
Pierre-Yves David
destroyed: invalidate phraserevs cache in all case (issue3858)...
r18983 # (see branchmap one)
Durham Goode
phases: add invalidate function...
r22893 self.invalidate()
Idan Kamara
phases: make _filterunknown a member function of phasecache...
r18220
Augie Fackler
formatting: blacken the codebase...
r43346
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 def advanceboundary(repo, tr, targetphase, nodes, revs=None, dryrun=None):
Pierre-Yves David
phases: add a moveboundary function to move phases boundaries...
r15454 """Add nodes to a phase changing other nodes phases if necessary.
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 This function move boundary *forward* this means that all nodes
are set in the target phase or kept in a *lower* phase.
Pierre-Yves David
phases: add a moveboundary function to move phases boundaries...
r15454
Sushil khanchi
advanceboundary: add dryrun parameter...
r38218 Simplify boundary to contains phase roots only.
If dryrun is True, no actions will be performed
Returns a set of revs whose phase is changed or should be changed
"""
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 if revs is None:
revs = []
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 phcache = repo._phasecache.copy()
Augie Fackler
formatting: blacken the codebase...
r43346 changes = phcache.advanceboundary(
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 repo, tr, targetphase, nodes, revs=revs, dryrun=dryrun
Augie Fackler
formatting: blacken the codebase...
r43346 )
Sushil khanchi
advanceboundary: add dryrun parameter...
r38218 if not dryrun:
repo._phasecache.replace(phcache)
return changes
Pierre-Yves David
phases: add retractboundary function to move boundary backward...
r15482
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
phase: add a transaction argument to retractboundary...
r22070 def retractboundary(repo, tr, targetphase, nodes):
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 """Set nodes back to a phase changing other nodes phases if
necessary.
Pierre-Yves David
phases: add retractboundary function to move boundary backward...
r15482
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 This function move boundary *backward* this means that all nodes
are set in the target phase or kept in a *higher* phase.
Pierre-Yves David
phases: add retractboundary function to move boundary backward...
r15482
Simplify boundary to contains phase roots only."""
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 phcache = repo._phasecache.copy()
Pierre-Yves David
phase: add a transaction argument to retractboundary...
r22070 phcache.retractboundary(repo, tr, targetphase, nodes)
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 repo._phasecache.replace(phcache)
Pierre-Yves David
phases: add basic pushkey support
r15648
Augie Fackler
formatting: blacken the codebase...
r43346
Joerg Sonnenberger
phases: convert registernew users to use revision sets...
r46375 def registernew(repo, tr, targetphase, revs):
Boris Feld
phases: add a 'registernew' method to set new phases...
r33453 """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()
Joerg Sonnenberger
phases: convert registernew users to use revision sets...
r46375 phcache.registernew(repo, tr, targetphase, revs)
Boris Feld
phases: add a 'registernew' method to set new phases...
r33453 repo._phasecache.replace(phcache)
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
phases: add basic pushkey support
r15648 def listphases(repo):
Martin Geisler
phases: fix typos in docstrings
r16724 """List phases root for serialization over pushkey"""
Gregory Szorc
phases: emit phases to pushkey protocol in deterministic order...
r32000 # Use ordered dictionary so behavior is deterministic.
keys = util.sortdict()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 value = b'%i' % draft
Boris Feld
phase: filter out non-draft item in "draft root"...
r34817 cl = repo.unfiltered().changelog
Patrick Mezard
phases: introduce phasecache...
r16657 for root in repo._phasecache.phaseroots[draft]:
Boris Feld
phase: filter out non-draft item in "draft root"...
r34817 if repo._phasecache.phase(repo, cl.rev(root)) <= draft:
keys[hex(root)] = value
Pierre-Yves David
phases: simplify phase exchange and movement over pushkey...
r15892
Matt Mackall
publishing: use new helper method
r25624 if repo.publishing():
Martin Geisler
phases: wrap docstrings at 70 characters
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
Pierre-Yves David
phases: add basic pushkey support
r15648 #
Martin Geisler
phases: wrap docstrings at 70 characters
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:
Pierre-Yves David
phases: add basic pushkey support
r15648 #
# 1) repo A push changeset X as draft to repo B
# 2) repo B make changeset X public
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 # 3) repo B push to repo A. X is not pushed but the data that
# X as now public should
Pierre-Yves David
phases: add basic pushkey support
r15648 #
Martin Geisler
phases: wrap docstrings at 70 characters
r16725 # The server can't handle it on it's own as it has no idea of
# client phase data.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 keys[b'publishing'] = b'True'
Pierre-Yves David
phases: add basic pushkey support
r15648 return keys
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
phases: add basic pushkey support
r15648 def pushphase(repo, nhex, oldphasestr, newphasestr):
timeless@mozdev.org
en-us: serialization
r17535 """List phases root for serialization over pushkey"""
Pierre-Yves David
clfilter: phases logic should be unfiltered...
r18002 repo = repo.unfiltered()
Bryan O'Sullivan
with: use context manager for lock in pushphase
r27861 with repo.lock():
Pierre-Yves David
phases: add basic pushkey support
r15648 currentphase = repo[nhex].phase()
Augie Fackler
formatting: blacken the codebase...
r43346 newphase = abs(int(newphasestr)) # let's avoid negative index surprise
oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise
Pierre-Yves David
phases: add basic pushkey support
r15648 if currentphase == oldphase and newphase < oldphase:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with repo.transaction(b'pushkey-phase') as tr:
Bryan O'Sullivan
with: use context manager for lock in pushphase
r27861 advanceboundary(repo, tr, newphase, [bin(nhex)])
Martin von Zweigbergk
pushkey: use False/True for return values from push functions...
r32822 return True
Matt Mackall
phases: don't complain if cset is already public on pushkey (issue3230)
r16051 elif currentphase == newphase:
# raced, but got correct result
Martin von Zweigbergk
pushkey: use False/True for return values from push functions...
r32822 return True
Pierre-Yves David
phases: add basic pushkey support
r15648 else:
Martin von Zweigbergk
pushkey: use False/True for return values from push functions...
r32822 return False
Pierre-Yves David
phases: add a function to compute heads from root
r15649
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
bundle: add config option to include phases...
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
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 headsbyphase = {i: [] for i in allphases}
Martin von Zweigbergk
bundle: add config option to include phases...
r33031 # No need to keep track of secret phase; any heads in the subset that
# are not mentioned are implicitly secret.
Boris Feld
phase: explicitly exclude secret phase and above...
r39308 for phase in allphases[:secret]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revset = b"heads(%%ln & %s())" % phasenames[phase]
Martin von Zweigbergk
bundle: add config option to include phases...
r33031 headsbyphase[phase] = [cl.node(r) for r in repo.revs(revset, subset)]
return headsbyphase
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
bundle2: only grab a transaction when 'phase-heads' affect the repository...
r34322 def updatephases(repo, trgetter, headsbyphase):
Martin von Zweigbergk
bundle: add config option to include phases...
r33031 """Updates the repo with the given phase heads"""
Joerg Sonnenberger
phases: updatephases should not skip internal phase...
r45676 # Now advance phase boundaries of all phases
Boris Feld
bundle2: only grab a transaction when 'phase-heads' affect the repository...
r34322 #
# run the update (and fetch transaction) only if there are actually things
# to update. This avoid creating empty transaction during no-op operation.
Joerg Sonnenberger
phases: updatephases should not skip internal phase...
r45676 for phase in allphases:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revset = b'%ln - _phase(%s)'
Boris Feld
phases: simplify revset in updatephases...
r39329 heads = [c.node() for c in repo.set(revset, headsbyphase[phase], phase)]
Boris Feld
bundle2: only grab a transaction when 'phase-heads' affect the repository...
r34322 if heads:
advanceboundary(repo, trgetter(), phase, heads)
Martin von Zweigbergk
bundle: add config option to include phases...
r33031
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
phases: add a function to compute heads from root
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
"""
Pierre-Yves David
clfilter: phases logic should be unfiltered...
r18002 repo = repo.unfiltered()
Pierre-Yves David
phases: add a function to compute heads from root
r15649 # build list from dictionary
Pierre-Yves David
phases: simplify phase exchange and movement over pushkey...
r15892 draftroots = []
index: use `index.has_node` in `analyzeremotephases`...
r43938 has_node = repo.changelog.index.has_node # to filter unknown nodes
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for nhex, phase in pycompat.iteritems(roots):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if nhex == b'publishing': # ignore data related to publish option
Pierre-Yves David
phases: add a function to compute heads from root
r15649 continue
node = bin(nhex)
phase = int(phase)
Gregory Szorc
phases: use constants for phase values...
r28174 if phase == public:
Pierre-Yves David
phases: simplify phase exchange and movement over pushkey...
r15892 if node != nullid:
Augie Fackler
formatting: blacken the codebase...
r43346 repo.ui.warn(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(
b'ignoring inconsistent public root'
b' from remote: %s\n'
)
Augie Fackler
formatting: blacken the codebase...
r43346 % nhex
)
Gregory Szorc
phases: use constants for phase values...
r28174 elif phase == draft:
index: use `index.has_node` in `analyzeremotephases`...
r43938 if has_node(node):
Pierre-Yves David
phases: simplify phase exchange and movement over pushkey...
r15892 draftroots.append(node)
else:
Augie Fackler
formatting: blacken the codebase...
r43346 repo.ui.warn(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'ignoring unexpected root from remote: %i %s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (phase, nhex)
)
Pierre-Yves David
phases: add a function to compute heads from root
r15649 # compute heads
Pierre-Yves David
phase: extracts heads computation logics from analyzeremotephases
r15954 publicheads = newheads(repo, subset, draftroots)
Pierre-Yves David
phases: simplify phase exchange and movement over pushkey...
r15892 return publicheads, draftroots
Pierre-Yves David
phases: add a function to compute heads from root
r15649
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
phase: gather remote phase information in a summary object...
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
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.publishing = remoteroots.get(b'publishing', False)
Boris Feld
phase: gather remote phase information in a summary object...
r34820
ana = analyzeremotephases(repo, remotesubset, remoteroots)
self.publicheads, self.draftroots = ana
# Get the list of all "heads" revs draft on remote
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 dheads = unfi.set(b'heads(%ln::%ln)', self.draftroots, remotesubset)
Boris Feld
phase: gather remote phase information in a summary object...
r34820 self.draftheads = [c.node() for c in dheads]
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
phase: extracts heads computation logics from analyzeremotephases
r15954 def newheads(repo, heads, roots):
"""compute new head of a subset minus another
* `heads`: define the first subset
Mads Kiilerich
fix wording and not-completely-trivial spelling errors and bad docstrings
r17425 * `roots`: define the second we subtract from the first"""
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 # prevent an import cycle
# phases > dagop > patch > copies > scmutil > obsolete > obsutil > phases
from . import dagop
repo = repo.unfiltered()
cl = repo.changelog
index: use `index.get_rev` in `phases.newheads`...
r43956 rev = cl.index.get_rev
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 if not roots:
return heads
Boris Feld
phases: fix `nullid` reference in newheads...
r39260 if not heads or heads == [nullid]:
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 return []
# The logic operated on revisions, convert arguments early for convenience
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 new_heads = {rev(n) for n in heads if n != nullid}
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 roots = [rev(n) for n in roots]
# compute the area we need to remove
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 affected_zone = repo.revs(b"(%ld::%ld)", roots, new_heads)
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 # heads in the area are no longer heads
new_heads.difference_update(affected_zone)
# revisions in the area have children outside of it,
# They might be new heads
Augie Fackler
formatting: blacken the codebase...
r43346 candidates = repo.revs(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"parents(%ld + (%ld and merge())) and not null", roots, affected_zone
Augie Fackler
formatting: blacken the codebase...
r43346 )
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 candidates -= affected_zone
if new_heads or candidates:
# remove candidate that are ancestors of other heads
new_heads.update(candidates)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 prunestart = repo.revs(b"parents(%ld) and not null", new_heads)
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 pruned = dagop.reachableroots(repo, candidates, prunestart)
new_heads.difference_update(pruned)
return pycompat.maplist(cl.node, sorted(new_heads))
Pierre-Yves David
phases: allow phase name in phases.new-commit settings...
r16030
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
phases: allow phase name in phases.new-commit settings...
r16030 def newcommitphase(ui):
"""helper to get the target phase of new commit
Handle all possible values for the phases.new-commit options.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 v = ui.config(b'phases', b'new-commit')
Pierre-Yves David
phases: allow phase name in phases.new-commit settings...
r16030 try:
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 return phasenumber2[v]
except KeyError:
raise error.ConfigError(
_(b"phases.new-commit: not a valid phase name ('%s')") % v
)
Pierre-Yves David
phases: allow phase name in phases.new-commit settings...
r16030
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
clfilter: introduce a `hassecret` function...
r17671 def hassecret(repo):
"""utility function that check if a repo have any secret changeset."""
Joerg Sonnenberger
phases: replace magic number by constant...
r45623 return bool(repo._phasecache.phaseroots[secret])
Boris Feld
phase: add a dedicated txnclose-phase hook...
r34711
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
phase: add a dedicated txnclose-phase hook...
r34711 def preparehookargs(node, old, new):
if old is None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 old = b''
Boris Feld
phase: add a dedicated txnclose-phase hook...
r34711 else:
Kevin Bullock
phases: pass phase names to hooks instead of internal values
r34877 old = phasenames[old]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return {b'node': node, b'oldphase': old, b'phase': phasenames[new]}