##// END OF EJS Templates
branchcache: use update_disk to refresh 'served' and 'served.hidden'...
branchcache: use update_disk to refresh 'served' and 'served.hidden' The `update_disk` method is dedicated to this kind of usecase. Now that the writting patterns are more consistent, we can use it to warm these two important cache. I am dropping the first comment about "refreshing all the others" because it is false. If a branchmap already exist for "served", none of the subset will be updated.

File last commit:

r52317:3cee8706 default
r52389:79a7616a default
Show More
phases.py
1220 lines | 41.5 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
phases: large rework of advance boundary...
r52316 import heapq
Boris Feld
phases: move binary encoding into a reusable function...
r34320 import struct
pytype: import typing directly...
r52178 import typing
phases: always write with a repo...
r52297 import weakref
pytype: import typing directly...
r52178
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Set,
Tuple,
)
Gregory Szorc
phases: use absolute_import
r25966
from .i18n import _
from .node import (
bin,
hex,
nullrev,
short,
Rodrigo Damazio Bovendorp
phases: make the working directory consistently a draft...
r44456 wdirrev,
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
phases: keep internal state as rev-num instead of node-id...
r52299 Phaseroots = Dict[int, Set[int]]
phases: type annotation for `_phasesets`...
r52304 PhaseSets = Dict[int, Set[int]]
pytype: import typing directly...
r52178
if typing.TYPE_CHECKING:
Matt Harbison
typing: add some type annotations to mercurial/phases.py...
r47390 from . import (
localrepo,
ui as uimod,
)
pytype: import typing directly...
r52178 # keeps pyflakes happy
assert [uimod]
Matt Harbison
typing: add some type annotations to mercurial/phases.py...
r47390 Phasedefaults = List[
Callable[[localrepo.localrepository, Phaseroots], Phaseroots]
]
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
pytype: convert type comment for inline variable too...
r52181 public: int = 0
draft: int = 1
secret: int = 2
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)
revset: include all non-public phases in _notpublic...
r51201 not_public_phases = trackedphases
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)
unstable: do not consider internal phases when computing unstable...
r52017 relevant_mutable_phases = (draft, secret) # could be obsolete or unstable
Joerg Sonnenberger
phases: sparsify phase lists...
r45677 remotehiddenphases = (secret, archived, internal)
localhiddenphases = (internal, archived)
Pierre-Yves David
phases: basic I/O logic...
r15418
revset: add `_internal()` predicate...
r51210 all_internal_phases = tuple(p for p in allphases if p & internal)
# We do not want any internal content to exit the repository, ever.
no_bundle_phases = all_internal_phases
Augie Fackler
formatting: blacken the codebase...
r43346
pytype: move some type comment to proper annotation...
r52180 def supportinternal(repo: "localrepo.localrepository") -> bool:
Boris Feld
phases: enforce internal phase support...
r39335 """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
pytype: move some type comment to proper annotation...
r52180 def supportarchived(repo: "localrepo.localrepository") -> bool:
phase: introduce a dedicated function to check for the archived phase...
r50345 """True if the archived phase can be used on a repository"""
phase: introduce a dedicated requirement for the `archived` phase...
r50346 return requirements.ARCHIVED_PHASE_REQUIREMENT in repo.requirements
phase: introduce a dedicated function to check for the archived phase...
r50345
pytype: move some type comment to proper annotation...
r52180 def _readroots(
repo: "localrepo.localrepository",
phasedefaults: Optional["Phasedefaults"] = None,
) -> Tuple[Phaseroots, bool]:
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}
phases: keep internal state as rev-num instead of node-id...
r52299 to_rev = repo.changelog.index.get_rev
phases: do filtering at read time...
r52298 unknown_msg = b'removing unknown node %s from %i-phase boundary\n'
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:
phases: do filtering at read time...
r52298 str_phase, hex_node = line.split()
phase = int(str_phase)
node = bin(hex_node)
phases: keep internal state as rev-num instead of node-id...
r52299 rev = to_rev(node)
if rev is None:
phases: do filtering at read time...
r52298 repo.ui.debug(unknown_msg % (short(hex_node), phase))
dirty = True
else:
phases: keep internal state as rev-num instead of node-id...
r52299 roots[phase].add(rev)
Pierre-Yves David
phases: basic I/O logic...
r15418 finally:
f.close()
Manuel Jacob
py3: catch FileNotFoundError instead of checking errno == ENOENT
r50201 except FileNotFoundError:
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
pytype: move some type comment to proper annotation...
r52180 def binaryencode(phasemapping: Dict[int, List[bytes]]) -> bytes:
Boris Feld
phases: move binary encoding into a reusable function...
r34320 """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 = []
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for phase, nodes in phasemapping.items():
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
pytype: move some type comment to proper annotation...
r52180 def binarydecode(stream) -> Dict[int, List[bytes]]:
Boris Feld
phases: move the binary decoding function in the phases module...
r34321 """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:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data[idx - 1] = (range(r1[0], r2[-1] + 1), t)
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 data.pop(idx)
elif merge_before:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data[idx - 1] = (range(r1[0], rev + 1), t)
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 elif merge_after:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data[idx] = (range(rev, r2[-1] + 1), t)
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 else:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data.insert(idx, (range(rev, rev + 1), t))
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036
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:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data[idx] = (range(rev + 1, r1[-1] + 1), t1)
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 _sortedrange_insert(data, idx, rev, t)
elif r1[-1] == rev:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data[idx] = (range(r1[0], rev), t1)
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 _sortedrange_insert(data, idx + 1, rev, t)
else:
data[idx : idx + 1] = [
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 (range(r1[0], rev), t1),
(range(rev, rev + 1), t),
(range(rev + 1, r1[-1] + 1), t1),
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 ]
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:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data.insert(0, (range(rev, rev + 1), (old, new)))
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 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):
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data.append((range(rev, rev + 1), t))
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 return
r1, t1 = data[low]
if r1[0] > rev:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data.insert(low, (range(rev, rev + 1), t))
Joerg Sonnenberger
transactions: convert changes['phases'] to list of ranges...
r45036 else:
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 data.insert(low + 1, (range(rev, rev + 1), t))
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451
Augie Fackler
formatting: blacken the codebase...
r43346
phases: incrementally update the phase sets when reasonable...
r52312 # consider incrementaly updating the phase set the update set is not bigger
# than this size
#
# Be warned, this number is picked arbitrarily, without any benchmark. It
# should blindly pickup "small update"
INCREMENTAL_PHASE_SETS_UPDATE_MAX_UPDATE = 100
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class phasecache:
pytype: move some type comment to proper annotation...
r52180 def __init__(
self,
repo: "localrepo.localrepository",
phasedefaults: Optional["Phasedefaults"],
_load: bool = True,
):
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 if _load:
# Cheap trick to allow shallow-copy without copy module
phases: do filtering at read time...
r52298 loaded = _readroots(repo, phasedefaults)
self._phaseroots: Phaseroots = loaded[0]
self.dirty: bool = loaded[1]
Yuya Nishihara
phases: initialize number of loaded revisions to 0...
r35458 self._loadedrevslen = 0
phases: type annotation for `_phasesets`...
r52304 self._phasesets: PhaseSets = None
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
pytype: move some type comment to proper annotation...
r52180 def hasnonpublicphases(self, repo: "localrepo.localrepository") -> bool:
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674 """detect if there are revisions with non-public phase"""
phases: drop set building in `hasnonpublicphases`...
r52309 # XXX deprecate the unused repo argument
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 return any(
phases: mark `phasecache.phaseroots` private...
r52296 revs for phase, revs in self._phaseroots.items() if phase != public
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 )
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674
pytype: move some type comment to proper annotation...
r52180 def nonpublicphaseroots(
self, repo: "localrepo.localrepository"
phases: keep internal state as rev-num instead of node-id...
r52299 ) -> Set[int]:
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674 """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()
phases: gather the logic for phasesets update in a single method...
r52308 self._ensure_phase_sets(repo)
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 return set().union(
*[
revs
phases: mark `phasecache.phaseroots` private...
r52296 for phase, revs in self._phaseroots.items()
Joerg Sonnenberger
phases: sparsify phaseroots and phasesets...
r45691 if phase != public
]
)
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674
pytype: move some type comment to proper annotation...
r52180 def getrevset(
self,
repo: "localrepo.localrepository",
phases: Iterable[int],
subset: Optional[Any] = None,
) -> Any:
Matt Harbison
typing: add some type annotations to mercurial/phases.py...
r47390 # TODO: finish typing this
Jun Wu
phases: add a getrevset method to phasecache...
r31016 """return a smartset for the given phases"""
phases: pass an unfiltered repository to _ensure_phase_sets...
r52310 self._ensure_phase_sets(repo.unfiltered())
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)
phases: mark `phasecache.phaseroots` private...
r52296 ph._phaseroots = self._phaseroots.copy()
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 ph.dirty = self.dirty
Yuya Nishihara
phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value...
r35457 ph._loadedrevslen = self._loadedrevslen
phasees: properly shallow caopy the phase sets dictionary...
r52311 if self._phasesets is None:
ph._phasesets = None
else:
ph._phasesets = self._phasesets.copy()
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 (
phases: mark `phasecache.phaseroots` private...
r52296 '_phaseroots',
safehasattr: pass attribute name as string instead of bytes...
r51485 'dirty',
'_loadedrevslen',
'_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()
phases: mark `phasecache.phaseroots` private...
r52296 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):
phases: keep internal state as rev-num instead of node-id...
r52299 roots = self._phaseroots[phase]
Boris Feld
phase: use `trackedphases` in `_getphaserevsnative`...
r39307 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
phases: gather the logic for phasesets update in a single method...
r52308 def _ensure_phase_sets(self, repo: "localrepo.localrepository") -> None:
phases: incrementally update the phase sets when reasonable...
r52312 """ensure phase information is loaded in the object"""
assert repo.filtername is None
update = -1
cl = repo.changelog
cl_size = len(cl)
Joerg Sonnenberger
phases: drop the list with phase of each rev, always comput phase sets...
r35310 if self._phasesets is None:
phases: incrementally update the phase sets when reasonable...
r52312 update = 0
else:
if cl_size > self._loadedrevslen:
# check if an incremental update is worth it.
# note we need a tradeoff here because the whole logic is not
# stored and implemented in native code nd datastructure.
# Otherwise the incremental update woul always be a win.
missing = cl_size - self._loadedrevslen
if missing <= INCREMENTAL_PHASE_SETS_UPDATE_MAX_UPDATE:
update = self._loadedrevslen
else:
update = 0
if update == 0:
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)
phases: gather the logic for phasesets update in a single method...
r52308 assert self._loadedrevslen == len(repo.changelog)
phases: incrementally update the phase sets when reasonable...
r52312 elif update > 0:
# good candidate for native code
assert update == self._loadedrevslen
if self.hasnonpublicphases(repo):
start = self._loadedrevslen
get_phase = self.phase
rev_phases = [0] * missing
parents = cl.parentrevs
sets = {phase: set() for phase in self._phasesets}
for phase, roots in self._phaseroots.items():
# XXX should really store the max somewhere
for r in roots:
if r >= start:
rev_phases[r - start] = phase
for rev in range(start, cl_size):
phase = rev_phases[rev - start]
p1, p2 = parents(rev)
if p1 == nullrev:
p1_phase = public
elif p1 >= start:
p1_phase = rev_phases[p1 - start]
else:
p1_phase = max(phase, get_phase(repo, p1))
if p2 == nullrev:
p2_phase = public
elif p2 >= start:
p2_phase = rev_phases[p2 - start]
else:
p2_phase = max(phase, get_phase(repo, p2))
phase = max(phase, p1_phase, p2_phase)
if phase > public:
rev_phases[rev - start] = phase
sets[phase].add(rev)
# Be careful to preserve shallow-copied values: do not update
# phaseroots values, replace them.
for phase, extra in sets.items():
if extra:
self._phasesets[phase] = self._phasesets[phase] | extra
self._loadedrevslen = cl_size
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
pytype: move some type comment to proper annotation...
r52180 def phase(self, repo: "localrepo.localrepository", rev: int) -> int:
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'))
phases: gather the logic for phasesets update in a single method...
r52308 # double check self._loadedrevslen to avoid an extra method call as
# python is slow for that.
Yuya Nishihara
phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value...
r35457 if rev >= self._loadedrevslen:
phases: pass an unfiltered repository to _ensure_phase_sets...
r52310 self._ensure_phase_sets(repo.unfiltered())
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
phases: always write with a repo...
r52297 def write(self, repo):
Patrick Mezard
phases: introduce phasecache...
r16657 if not self.dirty:
return
phases: always write with a repo...
r52297 f = repo.svfs(b'phaseroots', b'w', atomictemp=True, checkambig=True)
Patrick Mezard
phases: introduce phasecache...
r16657 try:
phases: always write with a repo...
r52297 self._write(repo.unfiltered(), f)
Patrick Mezard
phases: introduce phasecache...
r16657 finally:
f.close()
Pierre-Yves David
phase: extract the phaseroots serialization in a dedicated method...
r22079
phases: always write with a repo...
r52297 def _write(self, repo, fp):
assert repo.filtername is None
phases: keep internal state as rev-num instead of node-id...
r52299 to_node = repo.changelog.node
phases: mark `phasecache.phaseroots` private...
r52296 for phase, roots in self._phaseroots.items():
phases: keep internal state as rev-num instead of node-id...
r52299 for r in sorted(roots):
h = to_node(r)
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
phases: invalidate the phases set less often on retract boundary...
r52313 def _updateroots(self, repo, phase, newroots, tr, invalidate=True):
phases: mark `phasecache.phaseroots` private...
r52296 self._phaseroots[phase] = newroots
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 self.dirty = True
phases: invalidate the phases set less often on retract boundary...
r52313 if invalidate:
self.invalidate()
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
phases: always write with a repo...
r52297 assert repo.filtername is None
wrepo = weakref.ref(repo)
def tr_write(fp):
repo = wrepo()
assert repo is not None
self._write(repo, fp)
tr.addfilegenerator(b'phase', (b'phaseroots',), tr_write)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 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(
phases: keep internal state as rev-num instead of node-id...
r52299 self, repo, tr, targetphase, nodes=None, revs=None, dryrun=None
Joerg Sonnenberger
phases: allow registration and boundary advancement with revision sets...
r46374 ):
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 """
phases: fast path public phase advance when everything is public...
r52301 if targetphase == public and not self.hasnonpublicphases(repo):
return set()
phases: apply similar early filtering to advanceboundary...
r52315 repo = repo.unfiltered()
cl = repo.changelog
torev = cl.index.rev
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658 # Be careful to preserve shallow-copied values: do not update
# phaseroots values, replace them.
phases: apply similar early filtering to advanceboundary...
r52315 new_revs = set()
if revs is not None:
new_revs.update(revs)
if nodes is not None:
new_revs.update(torev(node) for node in nodes)
if not new_revs: # bail out early to avoid the loadphaserevs call
return (
set()
) # note: why do people call advanceboundary with nothing?
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
phases: large rework of advance boundary...
r52316 affectable_phases = sorted(
p for p in allphases if p > targetphase and self._phaseroots[p]
)
# filter revision already in the right phases
candidates = new_revs
new_revs = set()
phases: apply similar early filtering to advanceboundary...
r52315 self._ensure_phase_sets(repo)
phases: large rework of advance boundary...
r52316 for phase in affectable_phases:
found = candidates & self._phasesets[phase]
new_revs |= found
candidates -= found
if not candidates:
break
phases: apply similar early filtering to advanceboundary...
r52315 if not new_revs:
return set()
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451
phases: apply similar early filtering to advanceboundary...
r52315 # search for affected high phase changesets and roots
phases: large rework of advance boundary...
r52316 push = heapq.heappush
pop = heapq.heappop
parents = cl.parentrevs
get_phase = self.phase
changed = {} # set of revisions to be changed
# set of root deleted by this path
delroots = set()
new_roots = {p: set() for p in affectable_phases}
new_target_roots = set()
# revision to walk down
revs = [-r for r in new_revs]
heapq.heapify(revs)
while revs:
current = -pop(revs)
current_phase = get_phase(repo, current)
changed[current] = current_phase
p1, p2 = parents(current)
if p1 == nullrev:
p1_phase = public
else:
p1_phase = get_phase(repo, p1)
if p2 == nullrev:
p2_phase = public
else:
p2_phase = get_phase(repo, p2)
# do we have a root ?
if current_phase != p1_phase and current_phase != p2_phase:
# do not record phase, because we could have "duplicated"
# roots, were one root is shadowed by the very same roots of an
# higher phases
delroots.add(current)
# schedule a walk down if needed
if p1_phase > targetphase:
push(revs, -p1)
if p2_phase > targetphase:
push(revs, -p2)
if p1_phase < targetphase and p2_phase < targetphase:
new_target_roots.add(current)
Boris Feld
phases: track phase movements in 'advanceboundary'...
r33451
phases: large rework of advance boundary...
r52316 # the last iteration was done with the smallest value
min_current = current
# do we have unwalked children that might be new roots
if (min_current + len(changed)) < len(cl):
for r in range(min_current, len(cl)):
if r in changed:
continue
phase = get_phase(repo, r)
if phase <= targetphase:
continue
p1, p2 = parents(r)
if not (p1 in changed or p2 in changed):
continue # not affected
if p1 != nullrev and p1 not in changed:
p1_phase = get_phase(repo, p1)
if p1_phase == phase:
continue # not a root
if p2 != nullrev and p2 not in changed:
p2_phase = get_phase(repo, p2)
if p2_phase == phase:
continue # not a root
new_roots[phase].add(r)
Boris Feld
phases: extract the intermediate set of affected revs...
r33450
phases: large rework of advance boundary...
r52316 # apply the changes
Sushil khanchi
advanceboundary: add dryrun parameter...
r38218 if not dryrun:
phases: large rework of advance boundary...
r52316 for r, p in changed.items():
_trackphasechange(phasetracking, r, p, targetphase)
phases: directly update the phase sets in advanceboundary...
r52317 if targetphase > public:
self._phasesets[targetphase].update(changed)
phases: large rework of advance boundary...
r52316 for phase in affectable_phases:
roots = self._phaseroots[phase]
removed = roots & delroots
if removed or new_roots[phase]:
phases: directly update the phase sets in advanceboundary...
r52317 self._phasesets[phase].difference_update(changed)
phases: large rework of advance boundary...
r52316 # Be careful to preserve shallow-copied values: do not
# update phaseroots values, replace them.
final_roots = roots - delroots | new_roots[phase]
phases: directly update the phase sets in advanceboundary...
r52317 self._updateroots(
repo, phase, final_roots, tr, invalidate=False
)
phases: large rework of advance boundary...
r52316 if new_target_roots:
# Thanks for previous filtering, we can't replace existing
# roots
new_target_roots |= self._phaseroots[targetphase]
phases: directly update the phase sets in advanceboundary...
r52317 self._updateroots(
repo, targetphase, new_target_roots, tr, invalidate=False
)
Sushil khanchi
advanceboundary: add dryrun parameter...
r38218 repo.invalidatevolatilesets()
phases: large rework of advance boundary...
r52316 return changed
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):
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()
phases: keep internal state as rev-num instead of node-id...
r52299 retracted = self._retractboundary(repo, tr, targetphase, nodes)
if retracted and phasetracking is not None:
phases: leverage the collected information to record phase update...
r52303 for r, old_phase in sorted(retracted.items()):
_trackphasechange(phasetracking, r, old_phase, targetphase)
Boris Feld
phases: extract the core of boundary retraction in '_retractboundary'...
r33452 repo.invalidatevolatilesets()
phases: keep internal state as rev-num instead of node-id...
r52299 def _retractboundary(self, repo, tr, targetphase, nodes=None, revs=None):
phases: fast path retract of public phase...
r52300 if targetphase == public:
phases: large rewrite on retract boundary...
r52302 return {}
phase: introduce a dedicated function to check for the archived phase...
r50345 if (
targetphase == internal
and not supportinternal(repo)
or targetphase == archived
and not supportarchived(repo)
):
Boris Feld
phase: add an archived phase...
r40463 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)
phases: large rewrite on retract boundary...
r52302 assert repo.filtername is None
cl = repo.changelog
torev = cl.index.rev
new_revs = set()
if revs is not None:
new_revs.update(revs)
if nodes is not None:
new_revs.update(torev(node) for node in nodes)
if not new_revs: # bail out early to avoid the loadphaserevs call
return {} # note: why do people call retractboundary with nothing ?
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
phases: large rewrite on retract boundary...
r52302 if nullrev in new_revs:
raise error.Abort(_(b'cannot change null revision phase'))
phases: filter revision that are already in the right phase...
r52314 # Filter revision that are already in the right phase
self._ensure_phase_sets(repo)
for phase, revs in self._phasesets.items():
if phase >= targetphase:
new_revs -= revs
if not new_revs: # all revisions already in the right phases
return {}
phases: large rewrite on retract boundary...
r52302 # Compute change in phase roots by walking the graph
#
# note: If we had a cheap parent → children mapping we could do
# something even cheaper/more-bounded
#
# The idea would be to walk from item in new_revs stopping at
# descendant with phases >= target_phase.
#
# 1) This detect new_revs that are not new_roots (either already >=
# target_phase or reachable though another new_revs
# 2) This detect replaced current_roots as we reach them
# 3) This can avoid walking to the tip if we retract over a small
# branch.
#
# So instead, we do a variation of this, we walk from the smaller new
# revision to the tip to avoid missing any potential children.
#
# The following code would be a good candidate for native code… if only
# we could knew the phase of a changeset efficiently in native code.
parents = cl.parentrevs
phase = self.phase
new_roots = set() # roots added by this phases
changed_revs = {} # revision affected by this call
replaced_roots = set() # older roots replaced by this call
phases: keep internal state as rev-num instead of node-id...
r52299 currentroots = self._phaseroots[targetphase]
phases: large rewrite on retract boundary...
r52302 start = min(new_revs)
end = len(cl)
rev_phases = [None] * (end - start)
for r in range(start, end):
Joerg Sonnenberger
phases: improve performance of _retractboundary...
r45521
phases: large rewrite on retract boundary...
r52302 # gather information about the current_rev
r_phase = phase(repo, r)
p_phase = None # phase inherited from parents
p1, p2 = parents(r)
if p1 >= start:
p1_phase = rev_phases[p1 - start]
if p1_phase is not None:
p_phase = p1_phase
if p2 >= start:
p2_phase = rev_phases[p2 - start]
if p2_phase is not None:
if p_phase is not None:
p_phase = max(p_phase, p2_phase)
else:
p_phase = p2_phase
Durham Goode
phase: improve retractboundary perf...
r26909
phases: large rewrite on retract boundary...
r52302 # assess the situation
if r in new_revs and r_phase < targetphase:
if p_phase is None or p_phase < targetphase:
new_roots.add(r)
rev_phases[r - start] = targetphase
changed_revs[r] = r_phase
elif p_phase is None:
rev_phases[r - start] = r_phase
else:
if p_phase > r_phase:
rev_phases[r - start] = p_phase
else:
rev_phases[r - start] = r_phase
if p_phase == targetphase:
if p_phase > r_phase:
changed_revs[r] = r_phase
elif r in currentroots:
replaced_roots.add(r)
phases: invalidate the phases set less often on retract boundary...
r52313 sets = self._phasesets
sets[targetphase].update(changed_revs)
for r, old in changed_revs.items():
if old > public:
sets[old].discard(r)
Durham Goode
phase: improve retractboundary perf...
r26909
phases: large rewrite on retract boundary...
r52302 if new_roots:
assert changed_revs
phases: invalidate the phases set less often on retract boundary...
r52313
phases: large rewrite on retract boundary...
r52302 final_roots = new_roots | currentroots - replaced_roots
phases: invalidate the phases set less often on retract boundary...
r52313 self._updateroots(
repo,
targetphase,
final_roots,
tr,
invalidate=False,
)
phases: large rewrite on retract boundary...
r52302 if targetphase > 1:
retracted = set(changed_revs)
for lower_phase in range(1, targetphase):
lower_roots = self._phaseroots.get(lower_phase)
if lower_roots is None:
continue
if lower_roots & retracted:
simpler_roots = lower_roots - retracted
phases: invalidate the phases set less often on retract boundary...
r52313 self._updateroots(
repo,
lower_phase,
simpler_roots,
tr,
invalidate=False,
)
phases: large rewrite on retract boundary...
r52302 return changed_revs
else:
assert not changed_revs
assert not replaced_roots
return {}
Patrick Mezard
phases: make advance/retractboundary() atomic...
r16658
phases: explicitly filter stripped revision at strip time...
r52294 def register_strip(
self,
phases: keep internal state as rev-num instead of node-id...
r52299 repo,
phases: explicitly filter stripped revision at strip time...
r52294 tr,
strip_rev: int,
):
"""announce a strip to the phase cache
Any roots higher than the stripped revision should be dropped.
"""
phases: keep internal state as rev-num instead of node-id...
r52299 for targetphase, roots in list(self._phaseroots.items()):
filtered = {r for r in roots if r >= strip_rev}
phases: explicitly filter stripped revision at strip time...
r52294 if filtered:
phases: keep internal state as rev-num instead of node-id...
r52299 self._updateroots(repo, targetphase, roots - filtered, tr)
phases: explicitly filter stripped revision at strip time...
r52294 self.invalidate()
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
pytype: move some type comment to proper annotation...
r52180 def listphases(repo: "localrepo.localrepository") -> Dict[bytes, bytes]:
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
phases: keep internal state as rev-num instead of node-id...
r52299 to_node = cl.node
phases: mark `phasecache.phaseroots` private...
r52296 for root in repo._phasecache._phaseroots[draft]:
phases: keep internal state as rev-num instead of node-id...
r52299 if repo._phasecache.phase(repo, root) <= draft:
keys[hex(to_node(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
pytype: move some type comment to proper annotation...
r52180 def pushphase(
repo: "localrepo.localrepository",
nhex: bytes,
oldphasestr: bytes,
newphasestr: bytes,
) -> bool:
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}
Jason R. Coombs , Pierre-Yves David pierre-yves.david@octobus.net
bundle: include required phases when saving a bundle (issue6794)...
r51206 for phase in allphases:
revset = b"heads(%%ln & _phase(%d))" % 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
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for nhex, phase in roots.items():
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:
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 if node != repo.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
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class remotephasessummary:
Boris Feld
phase: gather remote phase information in a summary object...
r34820 """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
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 if not heads or heads == [repo.nullid]:
Boris Feld
remotephase: avoid full changelog iteration (issue5964)...
r39182 return []
# The logic operated on revisions, convert arguments early for convenience
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 new_heads = {rev(n) for n in heads if n != repo.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
pytype: move some type comment to proper annotation...
r52180 def newcommitphase(ui: "uimod.ui") -> int:
Pierre-Yves David
phases: allow phase name in phases.new-commit settings...
r16030 """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
pytype: move some type comment to proper annotation...
r52180 def hassecret(repo: "localrepo.localrepository") -> bool:
Pierre-Yves David
clfilter: introduce a `hassecret` function...
r17671 """utility function that check if a repo have any secret changeset."""
phases: mark `phasecache.phaseroots` private...
r52296 return bool(repo._phasecache._phaseroots[secret])
Boris Feld
phase: add a dedicated txnclose-phase hook...
r34711
Augie Fackler
formatting: blacken the codebase...
r43346
pytype: move some type comment to proper annotation...
r52180 def preparehookargs(
node: bytes,
old: Optional[int],
new: Optional[int],
) -> Dict[bytes, bytes]:
Boris Feld
phase: add a dedicated txnclose-phase hook...
r34711 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]}