exchange.py
2699 lines
| 100.3 KiB
| text/x-python
|
PythonLexer
/ mercurial / exchange.py
Mads Kiilerich
|
r21024 | # exchange.py - utility to exchange data between repos. | ||
Pierre-Yves David
|
r20345 | # | ||
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
Gregory Szorc
|
r27523 | from __future__ import absolute_import | ||
Boris Feld
|
r34323 | import collections | ||
Augie Fackler
|
r29341 | import hashlib | ||
Gregory Szorc
|
r27523 | |||
from .i18n import _ | ||||
from .node import ( | ||||
Boris Feld
|
r35260 | bin, | ||
Gregory Szorc
|
r27523 | hex, | ||
nullid, | ||||
Gregory Szorc
|
r38827 | nullrev, | ||
Gregory Szorc
|
r27523 | ) | ||
Boris Feld
|
r37181 | from .thirdparty import ( | ||
attr, | ||||
) | ||||
Gregory Szorc
|
r27523 | from . import ( | ||
bookmarks as bookmod, | ||||
bundle2, | ||||
changegroup, | ||||
discovery, | ||||
error, | ||||
Gregory Szorc
|
r39665 | exchangev2, | ||
Gregory Szorc
|
r27523 | lock as lockmod, | ||
Pulkit Goyal
|
r35348 | logexchange, | ||
Gregory Szorc
|
r38826 | narrowspec, | ||
Gregory Szorc
|
r27523 | obsolete, | ||
phases, | ||||
pushkey, | ||||
Pulkit Goyal
|
r32896 | pycompat, | ||
Martin von Zweigbergk
|
r38871 | repository, | ||
Gregory Szorc
|
r27523 | scmutil, | ||
sslutil, | ||||
streamclone, | ||||
url as urlmod, | ||||
util, | ||||
Pulkit Goyal
|
r40527 | wireprototypes, | ||
Gregory Szorc
|
r27523 | ) | ||
Yuya Nishihara
|
r37102 | from .utils import ( | ||
stringutil, | ||||
) | ||||
Pierre-Yves David
|
r20345 | |||
timeless
|
r28883 | urlerr = util.urlerr | ||
urlreq = util.urlreq | ||||
Gregory Szorc
|
r38825 | _NARROWACL_SECTION = 'narrowhgacl' | ||
Gregory Szorc
|
r26640 | # Maps bundle version human names to changegroup versions. | ||
_bundlespeccgversions = {'v1': '01', | ||||
'v2': '02', | ||||
Gregory Szorc
|
r26756 | 'packed1': 's1', | ||
Gregory Szorc
|
r26640 | 'bundle2': '02', #legacy | ||
} | ||||
Boris Feld
|
r37182 | # Maps bundle version with content opts to choose which part to bundle | ||
_bundlespeccontentopts = { | ||||
'v1': { | ||||
'changegroup': True, | ||||
'cg.version': '01', | ||||
'obsolescence': False, | ||||
'phases': False, | ||||
'tagsfnodescache': False, | ||||
'revbranchcache': False | ||||
}, | ||||
'v2': { | ||||
'changegroup': True, | ||||
'cg.version': '02', | ||||
'obsolescence': False, | ||||
'phases': False, | ||||
'tagsfnodescache': True, | ||||
'revbranchcache': True | ||||
}, | ||||
'packed1' : { | ||||
'cg.version': 's1' | ||||
} | ||||
} | ||||
_bundlespeccontentopts['bundle2'] = _bundlespeccontentopts['v2'] | ||||
Boris Feld
|
r37185 | _bundlespecvariants = {"streamv2": {"changegroup": False, "streamv2": True, | ||
"tagsfnodescache": False, | ||||
"revbranchcache": False}} | ||||
Gregory Szorc
|
r31473 | # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE. | ||
Martin von Zweigbergk
|
r32291 | _bundlespecv1compengines = {'gzip', 'bzip2', 'none'} | ||
Gregory Szorc
|
r31473 | |||
Boris Feld
|
r37181 | @attr.s | ||
class bundlespec(object): | ||||
compression = attr.ib() | ||||
Joerg Sonnenberger
|
r37786 | wirecompression = attr.ib() | ||
Boris Feld
|
r37181 | version = attr.ib() | ||
Joerg Sonnenberger
|
r37786 | wireversion = attr.ib() | ||
Boris Feld
|
r37181 | params = attr.ib() | ||
Boris Feld
|
r37182 | contentopts = attr.ib() | ||
Boris Feld
|
r37181 | |||
Joerg Sonnenberger
|
r37786 | def parsebundlespec(repo, spec, strict=True): | ||
Gregory Szorc
|
r26640 | """Parse a bundle string specification into parts. | ||
Bundle specifications denote a well-defined bundle/exchange format. | ||||
The content of a given specification should not change over time in | ||||
order to ensure that bundles produced by a newer version of Mercurial are | ||||
readable from an older version. | ||||
The string currently has the form: | ||||
Gregory Szorc
|
r26639 | |||
Gregory Szorc
|
r26759 | <compression>-<type>[;<parameter0>[;<parameter1>]] | ||
Gregory Szorc
|
r26640 | |||
Where <compression> is one of the supported compression formats | ||||
Gregory Szorc
|
r26759 | and <type> is (currently) a version string. A ";" can follow the type and | ||
Mads Kiilerich
|
r30332 | all text afterwards is interpreted as URI encoded, ";" delimited key=value | ||
Gregory Szorc
|
r26759 | pairs. | ||
Gregory Szorc
|
r26639 | |||
Gregory Szorc
|
r26640 | If ``strict`` is True (the default) <compression> is required. Otherwise, | ||
it is optional. | ||||
Gregory Szorc
|
r26639 | |||
Boris Feld
|
r37181 | Returns a bundlespec object of (compression, version, parameters). | ||
Compression will be ``None`` if not in strict mode and a compression isn't | ||||
defined. | ||||
Gregory Szorc
|
r26639 | |||
Gregory Szorc
|
r26640 | An ``InvalidBundleSpecification`` is raised when the specification is | ||
not syntactically well formed. | ||||
An ``UnsupportedBundleSpecification`` is raised when the compression or | ||||
bundle type/version is not recognized. | ||||
Gregory Szorc
|
r26639 | |||
Gregory Szorc
|
r26640 | Note: this function will likely eventually return a more complex data | ||
structure, including bundle2 part information. | ||||
Gregory Szorc
|
r26639 | """ | ||
Gregory Szorc
|
r26759 | def parseparams(s): | ||
if ';' not in s: | ||||
return s, {} | ||||
params = {} | ||||
version, paramstr = s.split(';', 1) | ||||
for p in paramstr.split(';'): | ||||
if '=' not in p: | ||||
raise error.InvalidBundleSpecification( | ||||
_('invalid bundle specification: ' | ||||
'missing "=" in parameter: %s') % p) | ||||
key, value = p.split('=', 1) | ||||
timeless
|
r28883 | key = urlreq.unquote(key) | ||
value = urlreq.unquote(value) | ||||
Gregory Szorc
|
r26759 | params[key] = value | ||
return version, params | ||||
Gregory Szorc
|
r26640 | if strict and '-' not in spec: | ||
raise error.InvalidBundleSpecification( | ||||
_('invalid bundle specification; ' | ||||
'must be prefixed with compression: %s') % spec) | ||||
Gregory Szorc
|
r26639 | |||
if '-' in spec: | ||||
Gregory Szorc
|
r26640 | compression, version = spec.split('-', 1) | ||
Gregory Szorc
|
r26639 | |||
Gregory Szorc
|
r30440 | if compression not in util.compengines.supportedbundlenames: | ||
Gregory Szorc
|
r26640 | raise error.UnsupportedBundleSpecification( | ||
_('%s compression is not supported') % compression) | ||||
Gregory Szorc
|
r26759 | version, params = parseparams(version) | ||
Gregory Szorc
|
r26640 | if version not in _bundlespeccgversions: | ||
raise error.UnsupportedBundleSpecification( | ||||
_('%s is not a recognized bundle version') % version) | ||||
Gregory Szorc
|
r26639 | else: | ||
Gregory Szorc
|
r26640 | # Value could be just the compression or just the version, in which | ||
# case some defaults are assumed (but only when not in strict mode). | ||||
assert not strict | ||||
Gregory Szorc
|
r26639 | |||
Gregory Szorc
|
r26759 | spec, params = parseparams(spec) | ||
Gregory Szorc
|
r30440 | if spec in util.compengines.supportedbundlenames: | ||
Gregory Szorc
|
r26640 | compression = spec | ||
version = 'v1' | ||||
Gregory Szorc
|
r31474 | # Generaldelta repos require v2. | ||
Gregory Szorc
|
r26640 | if 'generaldelta' in repo.requirements: | ||
version = 'v2' | ||||
Gregory Szorc
|
r31474 | # Modern compression engines require v2. | ||
if compression not in _bundlespecv1compengines: | ||||
version = 'v2' | ||||
Gregory Szorc
|
r26640 | elif spec in _bundlespeccgversions: | ||
Gregory Szorc
|
r26756 | if spec == 'packed1': | ||
compression = 'none' | ||||
else: | ||||
compression = 'bzip2' | ||||
Gregory Szorc
|
r26640 | version = spec | ||
else: | ||||
raise error.UnsupportedBundleSpecification( | ||||
_('%s is not a recognized bundle specification') % spec) | ||||
Gregory Szorc
|
r26639 | |||
Gregory Szorc
|
r31473 | # Bundle version 1 only supports a known set of compression engines. | ||
if version == 'v1' and compression not in _bundlespecv1compengines: | ||||
raise error.UnsupportedBundleSpecification( | ||||
_('compression engine %s is not supported on v1 bundles') % | ||||
compression) | ||||
Gregory Szorc
|
r26760 | # The specification for packed1 can optionally declare the data formats | ||
# required to apply it. If we see this metadata, compare against what the | ||||
# repo supports and error if the bundle isn't compatible. | ||||
if version == 'packed1' and 'requirements' in params: | ||||
requirements = set(params['requirements'].split(',')) | ||||
missingreqs = requirements - repo.supportedformats | ||||
if missingreqs: | ||||
raise error.UnsupportedBundleSpecification( | ||||
_('missing support for repository features: %s') % | ||||
', '.join(sorted(missingreqs))) | ||||
Boris Feld
|
r37182 | # Compute contentopts based on the version | ||
contentopts = _bundlespeccontentopts.get(version, {}).copy() | ||||
Boris Feld
|
r37185 | # Process the variants | ||
if "stream" in params and params["stream"] == "v2": | ||||
variant = _bundlespecvariants["streamv2"] | ||||
contentopts.update(variant) | ||||
Joerg Sonnenberger
|
r37786 | engine = util.compengines.forbundlename(compression) | ||
compression, wirecompression = engine.bundletype() | ||||
wireversion = _bundlespeccgversions[version] | ||||
Boris Feld
|
r37181 | |||
Joerg Sonnenberger
|
r37786 | return bundlespec(compression, wirecompression, version, wireversion, | ||
params, contentopts) | ||||
Gregory Szorc
|
r26639 | |||
Pierre-Yves David
|
r21064 | def readbundle(ui, fh, fname, vfs=None): | ||
Pierre-Yves David
|
r21065 | header = changegroup.readexactly(fh, 4) | ||
Pierre-Yves David
|
r21063 | |||
Pierre-Yves David
|
r21065 | alg = None | ||
Pierre-Yves David
|
r21063 | if not fname: | ||
fname = "stream" | ||||
if not header.startswith('HG') and header.startswith('\0'): | ||||
fh = changegroup.headerlessfixup(fh, header) | ||||
Pierre-Yves David
|
r21065 | header = "HG10" | ||
alg = 'UN' | ||||
Pierre-Yves David
|
r21063 | elif vfs: | ||
fname = vfs.join(fname) | ||||
Pierre-Yves David
|
r21065 | magic, version = header[0:2], header[2:4] | ||
Pierre-Yves David
|
r21063 | |||
if magic != 'HG': | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('%s: not a Mercurial bundle') % fname) | ||
Pierre-Yves David
|
r21065 | if version == '10': | ||
if alg is None: | ||||
alg = changegroup.readexactly(fh, 2) | ||||
Sune Foldager
|
r22390 | return changegroup.cg1unpacker(fh, alg) | ||
Pierre-Yves David
|
r24649 | elif version.startswith('2'): | ||
Pierre-Yves David
|
r25640 | return bundle2.getunbundler(ui, fh, magicstring=magic + version) | ||
Gregory Szorc
|
r26756 | elif version == 'S1': | ||
return streamclone.streamcloneapplier(fh) | ||||
Pierre-Yves David
|
r21065 | else: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('%s: unknown bundle version %s') % (fname, version)) | ||
Pierre-Yves David
|
r21063 | |||
Gregory Szorc
|
r27883 | def getbundlespec(ui, fh): | ||
"""Infer the bundlespec from a bundle file handle. | ||||
The input file handle is seeked and the original seek position is not | ||||
restored. | ||||
""" | ||||
def speccompression(alg): | ||||
Gregory Szorc
|
r30440 | try: | ||
return util.compengines.forbundletype(alg).bundletype()[0] | ||||
except KeyError: | ||||
return None | ||||
Gregory Szorc
|
r27883 | |||
b = readbundle(ui, fh, None) | ||||
if isinstance(b, changegroup.cg1unpacker): | ||||
alg = b._type | ||||
if alg == '_truncatedBZ': | ||||
alg = 'BZ' | ||||
comp = speccompression(alg) | ||||
if not comp: | ||||
raise error.Abort(_('unknown compression algorithm: %s') % alg) | ||||
return '%s-v1' % comp | ||||
elif isinstance(b, bundle2.unbundle20): | ||||
if 'Compression' in b.params: | ||||
comp = speccompression(b.params['Compression']) | ||||
if not comp: | ||||
raise error.Abort(_('unknown compression algorithm: %s') % comp) | ||||
else: | ||||
comp = 'none' | ||||
version = None | ||||
for part in b.iterparts(): | ||||
if part.type == 'changegroup': | ||||
version = part.params['version'] | ||||
if version in ('01', '02'): | ||||
version = 'v2' | ||||
else: | ||||
raise error.Abort(_('changegroup version %s does not have ' | ||||
'a known bundlespec') % version, | ||||
hint=_('try upgrading your Mercurial ' | ||||
'client')) | ||||
Boris Feld
|
r37185 | elif part.type == 'stream2' and version is None: | ||
# A stream2 part requires to be part of a v2 bundle | ||||
version = "v2" | ||||
requirements = urlreq.unquote(part.params['requirements']) | ||||
splitted = requirements.split() | ||||
params = bundle2._formatrequirementsparams(splitted) | ||||
return 'none-v2;stream=v2;%s' % params | ||||
Gregory Szorc
|
r27883 | |||
if not version: | ||||
raise error.Abort(_('could not identify changegroup version in ' | ||||
'bundle')) | ||||
return '%s-%s' % (comp, version) | ||||
elif isinstance(b, streamclone.streamcloneapplier): | ||||
requirements = streamclone.readbundle1header(fh)[2] | ||||
Boris Feld
|
r37184 | formatted = bundle2._formatrequirementsparams(requirements) | ||
return 'none-packed1;%s' % formatted | ||||
Gregory Szorc
|
r27883 | else: | ||
raise error.Abort(_('unknown bundle type: %s') % b) | ||||
Pierre-Yves David
|
r29808 | def _computeoutgoing(repo, heads, common): | ||
"""Computes which revs are outgoing given a set of common | ||||
and a set of heads. | ||||
This is a separate function so extensions can have access to | ||||
the logic. | ||||
Returns a discovery.outgoing object. | ||||
""" | ||||
cl = repo.changelog | ||||
if common: | ||||
hasnode = cl.hasnode | ||||
common = [n for n in common if hasnode(n)] | ||||
else: | ||||
common = [nullid] | ||||
if not heads: | ||||
heads = cl.heads() | ||||
return discovery.outgoing(repo, common, heads) | ||||
r40803 | def _checkpublish(pushop): | |||
repo = pushop.repo | ||||
ui = repo.ui | ||||
behavior = ui.config('experimental', 'auto-publish') | ||||
if pushop.publish or behavior not in ('warn', 'confirm', 'abort'): | ||||
return | ||||
remotephases = listkeys(pushop.remote, 'phases') | ||||
if not remotephases.get('publishing', False): | ||||
return | ||||
if pushop.revs is None: | ||||
published = repo.filtered('served').revs('not public()') | ||||
else: | ||||
published = repo.revs('::%ln - public()', pushop.revs) | ||||
if published: | ||||
if behavior == 'warn': | ||||
ui.warn(_('%i changesets about to be published\n') | ||||
% len(published)) | ||||
elif behavior == 'confirm': | ||||
if ui.promptchoice(_('push and publish %i changesets (yn)?' | ||||
'$$ &Yes $$ &No') % len(published)): | ||||
raise error.Abort(_('user quit')) | ||||
elif behavior == 'abort': | ||||
msg = _('push would publish %i changesets') % len(published) | ||||
hint = _("use --publish or adjust 'experimental.auto-publish'" | ||||
" config") | ||||
raise error.Abort(msg, hint=hint) | ||||
Pierre-Yves David
|
r29682 | def _forcebundle1(op): | ||
"""return true if a pull/push must use bundle1 | ||||
Pierre-Yves David
|
r24650 | |||
Pierre-Yves David
|
r29683 | This function is used to allow testing of the older bundle version""" | ||
ui = op.repo.ui | ||||
Mads Kiilerich
|
r30332 | # The goal is this config is to allow developer to choose the bundle | ||
Pierre-Yves David
|
r29683 | # version used during exchanged. This is especially handy during test. | ||
# Value is a list of bundle version to be picked from, highest version | ||||
# should be used. | ||||
# | ||||
# developer config: devel.legacy.exchange | ||||
exchange = ui.configlist('devel', 'legacy.exchange') | ||||
Pierre-Yves David
|
r29689 | forcebundle1 = 'bundle2' not in exchange and 'bundle1' in exchange | ||
Pierre-Yves David
|
r29683 | return forcebundle1 or not op.remote.capable('bundle2') | ||
Pierre-Yves David
|
r24650 | |||
Pierre-Yves David
|
r20346 | class pushoperation(object): | ||
"""A object that represent a single push operation | ||||
Nathan Goldbaum
|
r28456 | Its purpose is to carry push related state and very common operations. | ||
Pierre-Yves David
|
r20346 | |||
Nathan Goldbaum
|
r28456 | A new pushoperation should be created at the beginning of each push and | ||
discarded afterward. | ||||
Pierre-Yves David
|
r20346 | """ | ||
Pierre-Yves David
|
r22623 | def __init__(self, repo, remote, force=False, revs=None, newbranch=False, | ||
r40722 | bookmarks=(), publish=False, pushvars=None): | |||
Pierre-Yves David
|
r20346 | # repo we push from | ||
self.repo = repo | ||||
Pierre-Yves David
|
r20347 | self.ui = repo.ui | ||
Pierre-Yves David
|
r20348 | # repo we push to | ||
self.remote = remote | ||||
Pierre-Yves David
|
r20349 | # force option provided | ||
self.force = force | ||||
Pierre-Yves David
|
r20350 | # revs to be pushed (None is "all") | ||
self.revs = revs | ||||
Pierre-Yves David
|
r22623 | # bookmark explicitly pushed | ||
self.bookmarks = bookmarks | ||||
Pierre-Yves David
|
r20351 | # allow push of new branch | ||
self.newbranch = newbranch | ||||
Pierre-Yves David
|
r21901 | # step already performed | ||
# (used to check what steps have been already performed through bundle2) | ||||
self.stepsdone = set() | ||||
Pierre-Yves David
|
r22615 | # Integer version of the changegroup push result | ||
Pierre-Yves David
|
r20439 | # - None means nothing to push | ||
# - 0 means HTTP error | ||||
# - 1 means we pushed and remote head count is unchanged *or* | ||||
# we have outgoing changesets but refused to push | ||||
# - other values as described by addchangegroup() | ||||
Pierre-Yves David
|
r22615 | self.cgresult = None | ||
Pierre-Yves David
|
r22624 | # Boolean value for the bookmark push | ||
self.bkresult = None | ||||
Mads Kiilerich
|
r21024 | # discover.outgoing object (contains common and outgoing data) | ||
Pierre-Yves David
|
r20440 | self.outgoing = None | ||
r32709 | # all remote topological heads before the push | |||
Pierre-Yves David
|
r20462 | self.remoteheads = None | ||
r32709 | # Details of the remote branch pre and post push | |||
# | ||||
# mapping: {'branch': ([remoteheads], | ||||
# [newheads], | ||||
# [unsyncedheads], | ||||
# [discardedheads])} | ||||
# - branch: the branch name | ||||
# - remoteheads: the list of remote heads known locally | ||||
# None if the branch is new | ||||
# - newheads: the new remote heads (known locally) with outgoing pushed | ||||
# - unsyncedheads: the list of remote heads unknown locally. | ||||
# - discardedheads: the list of remote heads made obsolete by the push | ||||
self.pushbranchmap = None | ||||
Pierre-Yves David
|
r20464 | # testable as a boolean indicating if any nodes are missing locally. | ||
self.incoming = None | ||||
Boris Feld
|
r34820 | # summary of the remote phase situation | ||
self.remotephases = None | ||||
Pierre-Yves David
|
r22019 | # phases changes that must be pushed along side the changesets | ||
self.outdatedphases = None | ||||
# phases changes that must be pushed if changeset push fails | ||||
self.fallbackoutdatedphases = None | ||||
Pierre-Yves David
|
r22034 | # outgoing obsmarkers | ||
Pierre-Yves David
|
r22035 | self.outobsmarkers = set() | ||
Pierre-Yves David
|
r22239 | # outgoing bookmarks | ||
self.outbookmarks = [] | ||||
Eric Sumner
|
r23437 | # transaction manager | ||
self.trmanager = None | ||||
Pierre-Yves David
|
r25485 | # map { pushkey partid -> callback handling failure} | ||
# used to handle exception from mandatory pushkey part failure | ||||
self.pkfailcb = {} | ||||
Jun Wu
|
r33886 | # an iterable of pushvars or None | ||
self.pushvars = pushvars | ||||
r40722 | # publish pushed changesets | |||
self.publish = publish | ||||
Pierre-Yves David
|
r20346 | |||
Pierre-Yves David
|
r22014 | @util.propertycache | ||
def futureheads(self): | ||||
"""future remote heads if the changeset push succeeds""" | ||||
return self.outgoing.missingheads | ||||
Pierre-Yves David
|
r22015 | @util.propertycache | ||
def fallbackheads(self): | ||||
"""future remote heads if the changeset push fails""" | ||||
if self.revs is None: | ||||
# not target to push, all common are relevant | ||||
return self.outgoing.commonheads | ||||
unfi = self.repo.unfiltered() | ||||
# I want cheads = heads(::missingheads and ::commonheads) | ||||
# (missingheads is revs with secret changeset filtered out) | ||||
# | ||||
# This can be expressed as: | ||||
# cheads = ( (missingheads and ::commonheads) | ||||
# + (commonheads and ::missingheads))" | ||||
# ) | ||||
# | ||||
# while trying to push we already computed the following: | ||||
# common = (::commonheads) | ||||
# missing = ((commonheads::missingheads) - commonheads) | ||||
# | ||||
# We can pick: | ||||
# * missingheads part of common (::commonheads) | ||||
Durham Goode
|
r26184 | common = self.outgoing.common | ||
Pierre-Yves David
|
r22015 | nm = self.repo.changelog.nodemap | ||
cheads = [node for node in self.revs if nm[node] in common] | ||||
# and | ||||
# * commonheads parents on missing | ||||
revset = unfi.set('%ln and parents(roots(%ln))', | ||||
self.outgoing.commonheads, | ||||
self.outgoing.missing) | ||||
cheads.extend(c.node() for c in revset) | ||||
return cheads | ||||
Pierre-Yves David
|
r22016 | @property | ||
def commonheads(self): | ||||
"""set of all common heads after changeset bundle push""" | ||||
Pierre-Yves David
|
r22615 | if self.cgresult: | ||
Pierre-Yves David
|
r22016 | return self.futureheads | ||
else: | ||||
return self.fallbackheads | ||||
Pierre-Yves David
|
r22015 | |||
Pierre-Yves David
|
r22650 | # mapping of message used when pushing bookmark | ||
bookmsgmap = {'update': (_("updating bookmark %s\n"), | ||||
_('updating bookmark %s failed!\n')), | ||||
'export': (_("exporting bookmark %s\n"), | ||||
_('exporting bookmark %s failed!\n')), | ||||
'delete': (_("deleting remote bookmark %s\n"), | ||||
_('deleting remote bookmark %s failed!\n')), | ||||
} | ||||
Sean Farley
|
r26729 | def push(repo, remote, force=False, revs=None, newbranch=False, bookmarks=(), | ||
r40722 | publish=False, opargs=None): | |||
Pierre-Yves David
|
r20345 | '''Push outgoing changesets (limited by revs) from a local | ||
repository to remote. Return an integer: | ||||
- None means nothing to push | ||||
- 0 means HTTP error | ||||
- 1 means we pushed and remote head count is unchanged *or* | ||||
we have outgoing changesets but refused to push | ||||
- other values as described by addchangegroup() | ||||
''' | ||||
Sean Farley
|
r26729 | if opargs is None: | ||
opargs = {} | ||||
pushop = pushoperation(repo, remote, force, revs, newbranch, bookmarks, | ||||
r40722 | publish, **pycompat.strkwargs(opargs)) | |||
Pierre-Yves David
|
r20348 | if pushop.remote.local(): | ||
missing = (set(pushop.repo.requirements) | ||||
- pushop.remote.local().supported) | ||||
Pierre-Yves David
|
r20345 | if missing: | ||
msg = _("required features are not" | ||||
" supported in the destination:" | ||||
" %s") % (', '.join(sorted(missing))) | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg) | ||
Pierre-Yves David
|
r20345 | |||
Pierre-Yves David
|
r20348 | if not pushop.remote.canpush(): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("destination does not support push")) | ||
Gregory Szorc
|
r33667 | |||
if not pushop.remote.capable('unbundle'): | ||||
raise error.Abort(_('cannot push: destination does not support the ' | ||||
'unbundle wire protocol command')) | ||||
Martin von Zweigbergk
|
r33788 | # get lock as we might write phase data | ||
wlock = lock = None | ||||
Pierre-Yves David
|
r20345 | try: | ||
Pierre-Yves David
|
r24754 | # bundle2 push may receive a reply bundle touching bookmarks or other | ||
# things requiring the wlock. Take it now to ensure proper ordering. | ||||
maypushback = pushop.ui.configbool('experimental', 'bundle2.pushback') | ||||
Pierre-Yves David
|
r29682 | if (not _forcebundle1(pushop)) and maypushback: | ||
Martin von Zweigbergk
|
r33788 | wlock = pushop.repo.wlock() | ||
lock = pushop.repo.lock() | ||||
Martin von Zweigbergk
|
r33789 | pushop.trmanager = transactionmanager(pushop.repo, | ||
'push-response', | ||||
pushop.remote.url()) | ||||
Yuya Nishihara
|
r38111 | except error.LockUnavailable as err: | ||
Pierre-Yves David
|
r20345 | # source repo cannot be locked. | ||
# We do not abort the push, but just disable the local phase | ||||
# synchronisation. | ||||
Matt Harbison
|
r39947 | msg = ('cannot lock source repository: %s\n' | ||
% stringutil.forcebytestr(err)) | ||||
Pierre-Yves David
|
r20347 | pushop.ui.debug(msg) | ||
Martin von Zweigbergk
|
r33789 | |||
Martin von Zweigbergk
|
r33791 | with wlock or util.nullcontextmanager(), \ | ||
lock or util.nullcontextmanager(), \ | ||||
pushop.trmanager or util.nullcontextmanager(): | ||||
Pierre-Yves David
|
r20924 | pushop.repo.checkpush(pushop) | ||
r40803 | _checkpublish(pushop) | |||
Gregory Szorc
|
r33667 | _pushdiscovery(pushop) | ||
if not _forcebundle1(pushop): | ||||
_pushbundle2(pushop) | ||||
_pushchangeset(pushop) | ||||
_pushsyncphase(pushop) | ||||
_pushobsolete(pushop) | ||||
_pushbookmark(pushop) | ||||
Pulkit Goyal
|
r38634 | if repo.ui.configbool('experimental', 'remotenames'): | ||
logexchange.pullremotenames(repo, remote) | ||||
Pierre-Yves David
|
r22616 | return pushop | ||
Pierre-Yves David
|
r20352 | |||
Pierre-Yves David
|
r22018 | # list of steps to perform discovery before push | ||
pushdiscoveryorder = [] | ||||
# Mapping between step name and function | ||||
# | ||||
# This exists to help extensions wrap steps if necessary | ||||
pushdiscoverymapping = {} | ||||
def pushdiscovery(stepname): | ||||
"""decorator for function performing discovery before push | ||||
The function is added to the step -> function mapping and appended to the | ||||
list of steps. Beware that decorated function will be added in order (this | ||||
may matter). | ||||
You can only use this decorator for a new step, if you want to wrap a step | ||||
from an extension, change the pushdiscovery dictionary directly.""" | ||||
def dec(func): | ||||
assert stepname not in pushdiscoverymapping | ||||
pushdiscoverymapping[stepname] = func | ||||
pushdiscoveryorder.append(stepname) | ||||
return func | ||||
return dec | ||||
Pierre-Yves David
|
r20466 | def _pushdiscovery(pushop): | ||
Pierre-Yves David
|
r22018 | """Run all discovery steps""" | ||
for stepname in pushdiscoveryorder: | ||||
step = pushdiscoverymapping[stepname] | ||||
step(pushop) | ||||
@pushdiscovery('changeset') | ||||
def _pushdiscoverychangeset(pushop): | ||||
"""discover the changeset that need to be pushed""" | ||||
Pierre-Yves David
|
r20466 | fci = discovery.findcommonincoming | ||
Boris Feld
|
r35306 | if pushop.revs: | ||
commoninc = fci(pushop.repo, pushop.remote, force=pushop.force, | ||||
ancestorsof=pushop.revs) | ||||
else: | ||||
commoninc = fci(pushop.repo, pushop.remote, force=pushop.force) | ||||
Pierre-Yves David
|
r20466 | common, inc, remoteheads = commoninc | ||
fco = discovery.findcommonoutgoing | ||||
Pierre-Yves David
|
r23848 | outgoing = fco(pushop.repo, pushop.remote, onlyheads=pushop.revs, | ||
Pierre-Yves David
|
r20466 | commoninc=commoninc, force=pushop.force) | ||
pushop.outgoing = outgoing | ||||
pushop.remoteheads = remoteheads | ||||
pushop.incoming = inc | ||||
Pierre-Yves David
|
r22019 | @pushdiscovery('phase') | ||
def _pushdiscoveryphase(pushop): | ||||
"""discover the phase that needs to be pushed | ||||
(computed for both success and failure case for changesets push)""" | ||||
outgoing = pushop.outgoing | ||||
unfi = pushop.repo.unfiltered() | ||||
Gregory Szorc
|
r37775 | remotephases = listkeys(pushop.remote, 'phases') | ||
Jun Wu
|
r33499 | if (pushop.ui.configbool('ui', '_usedassubrepo') | ||
Pierre-Yves David
|
r25337 | and remotephases # server supports phases | ||
and not pushop.outgoing.missing # no changesets to be pushed | ||||
Boris Feld
|
r34819 | and remotephases.get('publishing', False)): | ||
Pierre-Yves David
|
r25337 | # When: | ||
# - this is a subrepo push | ||||
# - and remote support phase | ||||
# - and no changeset are to be pushed | ||||
# - and remote is publishing | ||||
Boris Feld
|
r34818 | # We may be in issue 3781 case! | ||
Pierre-Yves David
|
r25337 | # We drop the possible phase synchronisation done by | ||
# courtesy to publish changesets possibly locally draft | ||||
# on the remote. | ||||
Boris Feld
|
r34819 | pushop.outdatedphases = [] | ||
pushop.fallbackoutdatedphases = [] | ||||
return | ||||
Boris Feld
|
r34820 | |||
pushop.remotephases = phases.remotephasessummary(pushop.repo, | ||||
pushop.fallbackheads, | ||||
remotephases) | ||||
droots = pushop.remotephases.draftroots | ||||
Pierre-Yves David
|
r22019 | extracond = '' | ||
Boris Feld
|
r34820 | if not pushop.remotephases.publishing: | ||
Pierre-Yves David
|
r22019 | extracond = ' and public()' | ||
revset = 'heads((%%ln::%%ln) %s)' % extracond | ||||
# Get the list of all revs draft on remote by public here. | ||||
# XXX Beware that revset break if droots is not strictly | ||||
# XXX root we may want to ensure it is but it is costly | ||||
fallback = list(unfi.set(revset, droots, pushop.fallbackheads)) | ||||
r40722 | if not pushop.remotephases.publishing and pushop.publish: | |||
future = list(unfi.set('%ln and (not public() or %ln::)', | ||||
pushop.futureheads, droots)) | ||||
elif not outgoing.missing: | ||||
Pierre-Yves David
|
r22019 | future = fallback | ||
else: | ||||
# adds changeset we are going to push as draft | ||||
# | ||||
Mads Kiilerich
|
r23139 | # should not be necessary for publishing server, but because of an | ||
Pierre-Yves David
|
r22019 | # issue fixed in xxxxx we have to do it anyway. | ||
fdroots = list(unfi.set('roots(%ln + %ln::)', | ||||
outgoing.missing, droots)) | ||||
fdroots = [f.node() for f in fdroots] | ||||
future = list(unfi.set(revset, fdroots, pushop.futureheads)) | ||||
pushop.outdatedphases = future | ||||
pushop.fallbackoutdatedphases = fallback | ||||
Pierre-Yves David
|
r22035 | @pushdiscovery('obsmarker') | ||
def _pushdiscoveryobsmarkers(pushop): | ||||
Gregory Szorc
|
r37775 | if not obsolete.isenabled(pushop.repo, obsolete.exchangeopt): | ||
return | ||||
if not pushop.repo.obsstore: | ||||
return | ||||
if 'obsolete' not in listkeys(pushop.remote, 'namespaces'): | ||||
return | ||||
repo = pushop.repo | ||||
# very naive computation, that can be quite expensive on big repo. | ||||
# However: evolution is currently slow on them anyway. | ||||
nodes = (c.node() for c in repo.set('::%ln', pushop.futureheads)) | ||||
pushop.outobsmarkers = pushop.repo.obsstore.relevantmarkers(nodes) | ||||
Pierre-Yves David
|
r22035 | |||
Pierre-Yves David
|
r22239 | @pushdiscovery('bookmarks') | ||
def _pushdiscoverybookmarks(pushop): | ||||
ui = pushop.ui | ||||
repo = pushop.repo.unfiltered() | ||||
remote = pushop.remote | ||||
ui.debug("checking for updated bookmarks\n") | ||||
ancestors = () | ||||
if pushop.revs: | ||||
Yuya Nishihara
|
r38623 | revnums = pycompat.maplist(repo.changelog.rev, pushop.revs) | ||
Pierre-Yves David
|
r22239 | ancestors = repo.changelog.ancestors(revnums, inclusive=True) | ||
Gregory Szorc
|
r37775 | |||
remotebookmark = listkeys(remote, 'bookmarks') | ||||
Pierre-Yves David
|
r22239 | |||
liscju
|
r28182 | explicit = set([repo._bookmarks.expandname(bookmark) | ||
for bookmark in pushop.bookmarks]) | ||||
Pierre-Yves David
|
r22651 | |||
Stanislau Hlebik
|
r30583 | remotebookmark = bookmod.unhexlifybookmarks(remotebookmark) | ||
comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark) | ||||
def safehex(x): | ||||
if x is None: | ||||
return x | ||||
return hex(x) | ||||
def hexifycompbookmarks(bookmarks): | ||||
Boris Feld
|
r36955 | return [(b, safehex(scid), safehex(dcid)) | ||
for (b, scid, dcid) in bookmarks] | ||||
Stanislau Hlebik
|
r30583 | |||
comp = [hexifycompbookmarks(marks) for marks in comp] | ||||
Boris Feld
|
r36956 | return _processcompared(pushop, ancestors, explicit, remotebookmark, comp) | ||
def _processcompared(pushop, pushed, explicit, remotebms, comp): | ||||
"""take decision on bookmark to pull from the remote bookmark | ||||
Exist to help extensions who want to alter this behavior. | ||||
""" | ||||
Gregory Szorc
|
r23081 | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp | ||
Stanislau Hlebik
|
r30583 | |||
Boris Feld
|
r36956 | repo = pushop.repo | ||
Pierre-Yves David
|
r22239 | for b, scid, dcid in advsrc: | ||
Pierre-Yves David
|
r22651 | if b in explicit: | ||
explicit.remove(b) | ||||
Boris Feld
|
r36956 | if not pushed or repo[scid].rev() in pushed: | ||
Pierre-Yves David
|
r22239 | pushop.outbookmarks.append((b, dcid, scid)) | ||
Pierre-Yves David
|
r22651 | # search added bookmark | ||
for b, scid, dcid in addsrc: | ||||
if b in explicit: | ||||
explicit.remove(b) | ||||
pushop.outbookmarks.append((b, '', scid)) | ||||
# search for overwritten bookmark | ||||
Stanislau Hlebik
|
r30583 | for b, scid, dcid in list(advdst) + list(diverge) + list(differ): | ||
Pierre-Yves David
|
r22651 | if b in explicit: | ||
explicit.remove(b) | ||||
pushop.outbookmarks.append((b, dcid, scid)) | ||||
# search for bookmark to delete | ||||
for b, scid, dcid in adddst: | ||||
if b in explicit: | ||||
explicit.remove(b) | ||||
# treat as "deleted locally" | ||||
pushop.outbookmarks.append((b, dcid, '')) | ||||
Gregory Szorc
|
r23082 | # identical bookmarks shouldn't get reported | ||
for b, scid, dcid in same: | ||||
if b in explicit: | ||||
explicit.remove(b) | ||||
Pierre-Yves David
|
r22651 | |||
if explicit: | ||||
explicit = sorted(explicit) | ||||
# we should probably list all of them | ||||
Boris Feld
|
r36956 | pushop.ui.warn(_('bookmark %s does not exist on the local ' | ||
'or remote repository!\n') % explicit[0]) | ||||
Pierre-Yves David
|
r22651 | pushop.bkresult = 2 | ||
pushop.outbookmarks.sort() | ||||
Pierre-Yves David
|
r22239 | |||
Pierre-Yves David
|
r20465 | def _pushcheckoutgoing(pushop): | ||
outgoing = pushop.outgoing | ||||
unfi = pushop.repo.unfiltered() | ||||
if not outgoing.missing: | ||||
# nothing to push | ||||
scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded) | ||||
return False | ||||
# something to push | ||||
if not pushop.force: | ||||
# if repo.obsstore == False --> no obsolete | ||||
# then, save the iteration | ||||
if unfi.obsstore: | ||||
# this message are here for 80 char limit reason | ||||
mso = _("push includes obsolete changeset: %s!") | ||||
Boris Feld
|
r33652 | mspd = _("push includes phase-divergent changeset: %s!") | ||
Boris Feld
|
r33651 | mscd = _("push includes content-divergent changeset: %s!") | ||
Boris Feld
|
r33632 | mst = {"orphan": _("push includes orphan changeset: %s!"), | ||
Boris Feld
|
r33652 | "phase-divergent": mspd, | ||
Boris Feld
|
r33651 | "content-divergent": mscd} | ||
Pierre-Yves David
|
r20465 | # If we are to push if there is at least one | ||
# obsolete or unstable changeset in missing, at | ||||
# least one of the missinghead will be obsolete or | ||||
# unstable. So checking heads only is ok | ||||
for node in outgoing.missingheads: | ||||
ctx = unfi[node] | ||||
if ctx.obsolete(): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(mso % ctx) | ||
Boris Feld
|
r33696 | elif ctx.isunstable(): | ||
Boris Feld
|
r33692 | # TODO print more than one instability in the abort | ||
# message | ||||
raise error.Abort(mst[ctx.instabilities()[0]] % ctx) | ||||
Matt Mackall
|
r25836 | |||
Ryan McElroy
|
r26935 | discovery.checkheads(pushop) | ||
Pierre-Yves David
|
r20465 | return True | ||
Pierre-Yves David
|
r22017 | # List of names of steps to perform for an outgoing bundle2, order matters. | ||
b2partsgenorder = [] | ||||
# Mapping between step name and function | ||||
# | ||||
# This exists to help extensions wrap steps if necessary | ||||
b2partsgenmapping = {} | ||||
Pierre-Yves David
|
r24731 | def b2partsgenerator(stepname, idx=None): | ||
Pierre-Yves David
|
r22017 | """decorator for function generating bundle2 part | ||
The function is added to the step -> function mapping and appended to the | ||||
list of steps. Beware that decorated functions will be added in order | ||||
(this may matter). | ||||
You can only use this decorator for new steps, if you want to wrap a step | ||||
from an extension, attack the b2partsgenmapping dictionary directly.""" | ||||
def dec(func): | ||||
assert stepname not in b2partsgenmapping | ||||
b2partsgenmapping[stepname] = func | ||||
Pierre-Yves David
|
r24731 | if idx is None: | ||
b2partsgenorder.append(stepname) | ||||
else: | ||||
b2partsgenorder.insert(idx, stepname) | ||||
Pierre-Yves David
|
r22017 | return func | ||
return dec | ||||
Ryan McElroy
|
r26428 | def _pushb2ctxcheckheads(pushop, bundler): | ||
"""Generate race condition checking parts | ||||
Mads Kiilerich
|
r26781 | Exists as an independent function to aid extensions | ||
Ryan McElroy
|
r26428 | """ | ||
r32709 | # * 'force' do not check for push race, | |||
# * if we don't push anything, there are nothing to check. | ||||
if not pushop.force and pushop.outgoing.missingheads: | ||||
allowunrelated = 'related' in bundler.capabilities.get('checkheads', ()) | ||||
r33133 | emptyremote = pushop.pushbranchmap is None | |||
if not allowunrelated or emptyremote: | ||||
r32709 | bundler.newpart('check:heads', data=iter(pushop.remoteheads)) | |||
else: | ||||
affected = set() | ||||
for branch, heads in pushop.pushbranchmap.iteritems(): | ||||
remoteheads, newheads, unsyncedheads, discardedheads = heads | ||||
if remoteheads is not None: | ||||
remote = set(remoteheads) | ||||
affected |= set(discardedheads) & remote | ||||
affected |= remote - set(newheads) | ||||
if affected: | ||||
data = iter(sorted(affected)) | ||||
bundler.newpart('check:updated-heads', data=data) | ||||
Ryan McElroy
|
r26428 | |||
Boris Feld
|
r34822 | def _pushing(pushop): | ||
"""return True if we are pushing anything""" | ||||
return bool(pushop.outgoing.missing | ||||
or pushop.outdatedphases | ||||
or pushop.outobsmarkers | ||||
or pushop.outbookmarks) | ||||
Boris Feld
|
r35260 | @b2partsgenerator('check-bookmarks') | ||
def _pushb2checkbookmarks(pushop, bundler): | ||||
"""insert bookmark move checking""" | ||||
if not _pushing(pushop) or pushop.force: | ||||
return | ||||
b2caps = bundle2.bundle2caps(pushop.remote) | ||||
hasbookmarkcheck = 'bookmarks' in b2caps | ||||
if not (pushop.outbookmarks and hasbookmarkcheck): | ||||
return | ||||
data = [] | ||||
for book, old, new in pushop.outbookmarks: | ||||
old = bin(old) | ||||
data.append((book, old)) | ||||
checkdata = bookmod.binaryencode(data) | ||||
bundler.newpart('check:bookmarks', data=checkdata) | ||||
Boris Feld
|
r34822 | @b2partsgenerator('check-phases') | ||
def _pushb2checkphases(pushop, bundler): | ||||
"""insert phase move checking""" | ||||
if not _pushing(pushop) or pushop.force: | ||||
return | ||||
b2caps = bundle2.bundle2caps(pushop.remote) | ||||
hasphaseheads = 'heads' in b2caps.get('phases', ()) | ||||
if pushop.remotephases is not None and hasphaseheads: | ||||
# check that the remote phase has not changed | ||||
checks = [[] for p in phases.allphases] | ||||
checks[phases.public].extend(pushop.remotephases.publicheads) | ||||
checks[phases.draft].extend(pushop.remotephases.draftroots) | ||||
if any(checks): | ||||
for nodes in checks: | ||||
nodes.sort() | ||||
checkdata = phases.binaryencode(checks) | ||||
bundler.newpart('check:phases', data=checkdata) | ||||
Pierre-Yves David
|
r22017 | @b2partsgenerator('changeset') | ||
Pierre-Yves David
|
r21899 | def _pushb2ctx(pushop, bundler): | ||
"""handle changegroup push through bundle2 | ||||
Pierre-Yves David
|
r22615 | addchangegroup result is stored in the ``pushop.cgresult`` attribute. | ||
Pierre-Yves David
|
r21899 | """ | ||
Pierre-Yves David
|
r21902 | if 'changesets' in pushop.stepsdone: | ||
return | ||||
pushop.stepsdone.add('changesets') | ||||
Pierre-Yves David
|
r21899 | # Send known heads to the server for race detection. | ||
Pierre-Yves David
|
r21903 | if not _pushcheckoutgoing(pushop): | ||
return | ||||
Mads Kiilerich
|
r28876 | pushop.repo.prepushoutgoinghooks(pushop) | ||
Ryan McElroy
|
r26428 | |||
_pushb2ctxcheckheads(pushop, bundler) | ||||
Pierre-Yves David
|
r23180 | b2caps = bundle2.bundle2caps(pushop.remote) | ||
Martin von Zweigbergk
|
r28668 | version = '01' | ||
Pierre-Yves David
|
r24686 | cgversions = b2caps.get('changegroup') | ||
Martin von Zweigbergk
|
r28668 | if cgversions: # 3.1 and 3.2 ship with an empty value | ||
Martin von Zweigbergk
|
r27751 | cgversions = [v for v in cgversions | ||
Martin von Zweigbergk
|
r27953 | if v in changegroup.supportedoutgoingversions( | ||
pushop.repo)] | ||||
Pierre-Yves David
|
r23180 | if not cgversions: | ||
raise ValueError(_('no common changegroup version')) | ||||
version = max(cgversions) | ||||
Durham Goode
|
r34100 | cgstream = changegroup.makestream(pushop.repo, pushop.outgoing, version, | ||
'push') | ||||
cgpart = bundler.newpart('changegroup', data=cgstream) | ||||
Martin von Zweigbergk
|
r28668 | if cgversions: | ||
Pierre-Yves David
|
r23180 | cgpart.addparam('version', version) | ||
Martin von Zweigbergk
|
r27938 | if 'treemanifest' in pushop.repo.requirements: | ||
cgpart.addparam('treemanifest', '1') | ||||
Pierre-Yves David
|
r21899 | def handlereply(op): | ||
Mads Kiilerich
|
r23139 | """extract addchangegroup returns from server reply""" | ||
Pierre-Yves David
|
r21899 | cgreplies = op.records.getreplies(cgpart.id) | ||
assert len(cgreplies['changegroup']) == 1 | ||||
Pierre-Yves David
|
r22615 | pushop.cgresult = cgreplies['changegroup'][0]['return'] | ||
Pierre-Yves David
|
r21899 | return handlereply | ||
Pierre-Yves David
|
r22020 | @b2partsgenerator('phase') | ||
def _pushb2phases(pushop, bundler): | ||||
"""handle phase push through bundle2""" | ||||
if 'phases' in pushop.stepsdone: | ||||
return | ||||
b2caps = bundle2.bundle2caps(pushop.remote) | ||||
Boris Feld
|
r34837 | ui = pushop.repo.ui | ||
legacyphase = 'phases' in ui.configlist('devel', 'legacy.exchange') | ||||
haspushkey = 'pushkey' in b2caps | ||||
hasphaseheads = 'heads' in b2caps.get('phases', ()) | ||||
if hasphaseheads and not legacyphase: | ||||
Boris Feld
|
r34911 | return _pushb2phaseheads(pushop, bundler) | ||
Boris Feld
|
r34837 | elif haspushkey: | ||
Boris Feld
|
r34911 | return _pushb2phasespushkey(pushop, bundler) | ||
Boris Feld
|
r34823 | |||
Boris Feld
|
r34837 | def _pushb2phaseheads(pushop, bundler): | ||
"""push phase information through a bundle2 - binary part""" | ||||
pushop.stepsdone.add('phases') | ||||
if pushop.outdatedphases: | ||||
updates = [[] for p in phases.allphases] | ||||
updates[0].extend(h.node() for h in pushop.outdatedphases) | ||||
phasedata = phases.binaryencode(updates) | ||||
bundler.newpart('phase-heads', data=phasedata) | ||||
Boris Feld
|
r34823 | def _pushb2phasespushkey(pushop, bundler): | ||
"""push phase information through a bundle2 - pushkey part""" | ||||
Pierre-Yves David
|
r22020 | pushop.stepsdone.add('phases') | ||
part2node = [] | ||||
Pierre-Yves David
|
r25502 | |||
def handlefailure(pushop, exc): | ||||
targetid = int(exc.partid) | ||||
for partid, node in part2node: | ||||
if partid == targetid: | ||||
raise error.Abort(_('updating %s to public failed') % node) | ||||
Pierre-Yves David
|
r22020 | enc = pushkey.encode | ||
for newremotehead in pushop.outdatedphases: | ||||
Pierre-Yves David
|
r25502 | part = bundler.newpart('pushkey') | ||
Pierre-Yves David
|
r22020 | part.addparam('namespace', enc('phases')) | ||
part.addparam('key', enc(newremotehead.hex())) | ||||
Augie Fackler
|
r34200 | part.addparam('old', enc('%d' % phases.draft)) | ||
part.addparam('new', enc('%d' % phases.public)) | ||||
Pierre-Yves David
|
r22020 | part2node.append((part.id, newremotehead)) | ||
Pierre-Yves David
|
r25502 | pushop.pkfailcb[part.id] = handlefailure | ||
Pierre-Yves David
|
r22020 | def handlereply(op): | ||
for partid, node in part2node: | ||||
partrep = op.records.getreplies(partid) | ||||
results = partrep['pushkey'] | ||||
assert len(results) <= 1 | ||||
msg = None | ||||
if not results: | ||||
msg = _('server ignored update of %s to public!\n') % node | ||||
elif not int(results[0]['return']): | ||||
msg = _('updating %s to public failed!\n') % node | ||||
if msg is not None: | ||||
pushop.ui.warn(msg) | ||||
return handlereply | ||||
Pierre-Yves David
|
r21904 | |||
Pierre-Yves David
|
r22347 | @b2partsgenerator('obsmarkers') | ||
def _pushb2obsmarkers(pushop, bundler): | ||||
if 'obsmarkers' in pushop.stepsdone: | ||||
return | ||||
remoteversions = bundle2.obsmarkersversion(bundler.capabilities) | ||||
if obsolete.commonversion(remoteversions) is None: | ||||
return | ||||
pushop.stepsdone.add('obsmarkers') | ||||
if pushop.outobsmarkers: | ||||
Pierre-Yves David
|
r25118 | markers = sorted(pushop.outobsmarkers) | ||
r32515 | bundle2.buildobsmarkerspart(bundler, markers) | |||
Pierre-Yves David
|
r22347 | |||
Pierre-Yves David
|
r22242 | @b2partsgenerator('bookmarks') | ||
def _pushb2bookmarks(pushop, bundler): | ||||
Martin von Zweigbergk
|
r25895 | """handle bookmark push through bundle2""" | ||
Pierre-Yves David
|
r22242 | if 'bookmarks' in pushop.stepsdone: | ||
return | ||||
b2caps = bundle2.bundle2caps(pushop.remote) | ||||
Boris Feld
|
r35265 | |||
legacy = pushop.repo.ui.configlist('devel', 'legacy.exchange') | ||||
legacybooks = 'bookmarks' in legacy | ||||
if not legacybooks and 'bookmarks' in b2caps: | ||||
return _pushb2bookmarkspart(pushop, bundler) | ||||
elif 'pushkey' in b2caps: | ||||
Boris Feld
|
r35263 | return _pushb2bookmarkspushkey(pushop, bundler) | ||
Boris Feld
|
r35265 | def _bmaction(old, new): | ||
"""small utility for bookmark pushing""" | ||||
if not old: | ||||
return 'export' | ||||
elif not new: | ||||
return 'delete' | ||||
return 'update' | ||||
def _pushb2bookmarkspart(pushop, bundler): | ||||
pushop.stepsdone.add('bookmarks') | ||||
if not pushop.outbookmarks: | ||||
return | ||||
allactions = [] | ||||
data = [] | ||||
for book, old, new in pushop.outbookmarks: | ||||
new = bin(new) | ||||
data.append((book, new)) | ||||
allactions.append((book, _bmaction(old, new))) | ||||
checkdata = bookmod.binaryencode(data) | ||||
bundler.newpart('bookmarks', data=checkdata) | ||||
def handlereply(op): | ||||
ui = pushop.ui | ||||
# if success | ||||
for book, action in allactions: | ||||
ui.status(bookmsgmap[action][0] % book) | ||||
return handlereply | ||||
Boris Feld
|
r35263 | def _pushb2bookmarkspushkey(pushop, bundler): | ||
Pierre-Yves David
|
r22242 | pushop.stepsdone.add('bookmarks') | ||
part2book = [] | ||||
enc = pushkey.encode | ||||
Pierre-Yves David
|
r25501 | |||
def handlefailure(pushop, exc): | ||||
targetid = int(exc.partid) | ||||
for partid, book, action in part2book: | ||||
if partid == targetid: | ||||
raise error.Abort(bookmsgmap[action][1].rstrip() % book) | ||||
# we should not be called for part we did not generated | ||||
assert False | ||||
Pierre-Yves David
|
r22242 | for book, old, new in pushop.outbookmarks: | ||
Pierre-Yves David
|
r25501 | part = bundler.newpart('pushkey') | ||
Pierre-Yves David
|
r22242 | part.addparam('namespace', enc('bookmarks')) | ||
part.addparam('key', enc(book)) | ||||
part.addparam('old', enc(old)) | ||||
part.addparam('new', enc(new)) | ||||
Pierre-Yves David
|
r22650 | action = 'update' | ||
if not old: | ||||
action = 'export' | ||||
elif not new: | ||||
action = 'delete' | ||||
part2book.append((part.id, book, action)) | ||||
Pierre-Yves David
|
r25501 | pushop.pkfailcb[part.id] = handlefailure | ||
Pierre-Yves David
|
r22650 | |||
Pierre-Yves David
|
r22242 | def handlereply(op): | ||
Pierre-Yves David
|
r22650 | ui = pushop.ui | ||
for partid, book, action in part2book: | ||||
Pierre-Yves David
|
r22242 | partrep = op.records.getreplies(partid) | ||
results = partrep['pushkey'] | ||||
assert len(results) <= 1 | ||||
if not results: | ||||
pushop.ui.warn(_('server ignored bookmark %s update\n') % book) | ||||
else: | ||||
ret = int(results[0]['return']) | ||||
if ret: | ||||
Pierre-Yves David
|
r22650 | ui.status(bookmsgmap[action][0] % book) | ||
Pierre-Yves David
|
r22242 | else: | ||
Pierre-Yves David
|
r22650 | ui.warn(bookmsgmap[action][1] % book) | ||
Pierre-Yves David
|
r22649 | if pushop.bkresult is not None: | ||
pushop.bkresult = 1 | ||||
Pierre-Yves David
|
r22242 | return handlereply | ||
Pulkit Goyal
|
r33656 | @b2partsgenerator('pushvars', idx=0) | ||
def _getbundlesendvars(pushop, bundler): | ||||
'''send shellvars via bundle2''' | ||||
Jun Wu
|
r33886 | pushvars = pushop.pushvars | ||
if pushvars: | ||||
shellvars = {} | ||||
for raw in pushvars: | ||||
if '=' not in raw: | ||||
msg = ("unable to parse variable '%s', should follow " | ||||
"'KEY=VALUE' or 'KEY=' format") | ||||
raise error.Abort(msg % raw) | ||||
k, v = raw.split('=', 1) | ||||
shellvars[k] = v | ||||
Pulkit Goyal
|
r33656 | part = bundler.newpart('pushvars') | ||
Jun Wu
|
r33886 | for key, value in shellvars.iteritems(): | ||
Pulkit Goyal
|
r33656 | part.addparam(key, value, mandatory=False) | ||
Pierre-Yves David
|
r22242 | |||
Pierre-Yves David
|
r21061 | def _pushbundle2(pushop): | ||
"""push data to the remote using bundle2 | ||||
The only currently supported type of data is changegroup but this will | ||||
evolve in the future.""" | ||||
Pierre-Yves David
|
r21644 | bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote)) | ||
Eric Sumner
|
r23439 | pushback = (pushop.trmanager | ||
and pushop.ui.configbool('experimental', 'bundle2.pushback')) | ||||
Pierre-Yves David
|
r21142 | # create reply capability | ||
Eric Sumner
|
r23439 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo, | ||
Gregory Szorc
|
r35801 | allowpushback=pushback, | ||
role='client')) | ||||
Pierre-Yves David
|
r24686 | bundler.newpart('replycaps', data=capsblob) | ||
Pierre-Yves David
|
r21904 | replyhandlers = [] | ||
Pierre-Yves David
|
r22017 | for partgenname in b2partsgenorder: | ||
partgen = b2partsgenmapping[partgenname] | ||||
Pierre-Yves David
|
r21904 | ret = partgen(pushop, bundler) | ||
Pierre-Yves David
|
r21941 | if callable(ret): | ||
replyhandlers.append(ret) | ||||
Pierre-Yves David
|
r21904 | # do not push if nothing to push | ||
Pierre-Yves David
|
r21903 | if bundler.nbparts <= 1: | ||
return | ||||
Pierre-Yves David
|
r21061 | stream = util.chunkbuffer(bundler.getchunks()) | ||
Pierre-Yves David
|
r21182 | try: | ||
Pierre-Yves David
|
r25485 | try: | ||
Gregory Szorc
|
r37664 | with pushop.remote.commandexecutor() as e: | ||
reply = e.callcommand('unbundle', { | ||||
'bundle': stream, | ||||
'heads': ['force'], | ||||
'url': pushop.remote.url(), | ||||
}).result() | ||||
Gregory Szorc
|
r25660 | except error.BundleValueError as exc: | ||
liscju
|
r29389 | raise error.Abort(_('missing support for %s') % exc) | ||
Pierre-Yves David
|
r25485 | try: | ||
trgetter = None | ||||
if pushback: | ||||
trgetter = pushop.trmanager.transaction | ||||
op = bundle2.processbundle(pushop.repo, reply, trgetter) | ||||
Gregory Szorc
|
r25660 | except error.BundleValueError as exc: | ||
liscju
|
r29389 | raise error.Abort(_('missing support for %s') % exc) | ||
Gregory Szorc
|
r26829 | except bundle2.AbortFromPart as exc: | ||
pushop.ui.status(_('remote: %s\n') % exc) | ||||
Pierre-Yves David
|
r30908 | if exc.hint is not None: | ||
pushop.ui.status(_('remote: %s\n') % ('(%s)' % exc.hint)) | ||||
raise error.Abort(_('push failed on remote')) | ||||
Gregory Szorc
|
r25660 | except error.PushkeyFailed as exc: | ||
Pierre-Yves David
|
r25485 | partid = int(exc.partid) | ||
if partid not in pushop.pkfailcb: | ||||
raise | ||||
pushop.pkfailcb[partid](pushop, exc) | ||||
Pierre-Yves David
|
r21904 | for rephand in replyhandlers: | ||
rephand(op) | ||||
Pierre-Yves David
|
r21061 | |||
Pierre-Yves David
|
r20463 | def _pushchangeset(pushop): | ||
"""Make the actual push of changeset bundle to remote repo""" | ||||
Pierre-Yves David
|
r21902 | if 'changesets' in pushop.stepsdone: | ||
return | ||||
pushop.stepsdone.add('changesets') | ||||
Pierre-Yves David
|
r21903 | if not _pushcheckoutgoing(pushop): | ||
return | ||||
Gregory Szorc
|
r33667 | |||
# Should have verified this in push(). | ||||
assert pushop.remote.capable('unbundle') | ||||
Mads Kiilerich
|
r28876 | pushop.repo.prepushoutgoinghooks(pushop) | ||
Pierre-Yves David
|
r20463 | outgoing = pushop.outgoing | ||
# TODO: get bundlecaps from remote | ||||
bundlecaps = None | ||||
# create a changegroup from local | ||||
if pushop.revs is None and not (outgoing.excluded | ||||
or pushop.repo.changelog.filteredrevs): | ||||
# push everything, | ||||
# use the fast path, no race possible on push | ||||
Durham Goode
|
r34098 | cg = changegroup.makechangegroup(pushop.repo, outgoing, '01', 'push', | ||
fastpath=True, bundlecaps=bundlecaps) | ||||
Pierre-Yves David
|
r20463 | else: | ||
Durham Goode
|
r34103 | cg = changegroup.makechangegroup(pushop.repo, outgoing, '01', | ||
'push', bundlecaps=bundlecaps) | ||||
Pierre-Yves David
|
r20463 | |||
# apply changegroup to remote | ||||
Gregory Szorc
|
r33667 | # local repo finds heads on server, finds out what | ||
# revs it must push. once revs transferred, if server | ||||
# finds it has different heads (someone else won | ||||
# commit/push race), server aborts. | ||||
if pushop.force: | ||||
remoteheads = ['force'] | ||||
Pierre-Yves David
|
r20463 | else: | ||
Gregory Szorc
|
r33667 | remoteheads = pushop.remoteheads | ||
# ssh: return remote's addchangegroup() | ||||
# http: return remote's addchangegroup() or 0 for error | ||||
pushop.cgresult = pushop.remote.unbundle(cg, remoteheads, | ||||
pushop.repo.url()) | ||||
Pierre-Yves David
|
r20463 | |||
Pierre-Yves David
|
r20441 | def _pushsyncphase(pushop): | ||
Mads Kiilerich
|
r21024 | """synchronise phase information locally and remotely""" | ||
Pierre-Yves David
|
r20468 | cheads = pushop.commonheads | ||
Pierre-Yves David
|
r20441 | # even when we don't push, exchanging phase data is useful | ||
Gregory Szorc
|
r37775 | remotephases = listkeys(pushop.remote, 'phases') | ||
Jun Wu
|
r33499 | if (pushop.ui.configbool('ui', '_usedassubrepo') | ||
Pierre-Yves David
|
r20441 | and remotephases # server supports phases | ||
Pierre-Yves David
|
r22615 | and pushop.cgresult is None # nothing was pushed | ||
Pierre-Yves David
|
r20441 | and remotephases.get('publishing', False)): | ||
# When: | ||||
# - this is a subrepo push | ||||
# - and remote support phase | ||||
# - and no changeset was pushed | ||||
# - and remote is publishing | ||||
# We may be in issue 3871 case! | ||||
# We drop the possible phase synchronisation done by | ||||
# courtesy to publish changesets possibly locally draft | ||||
# on the remote. | ||||
remotephases = {'publishing': 'True'} | ||||
Pierre-Yves David
|
r21012 | if not remotephases: # old server or public only reply from non-publishing | ||
Pierre-Yves David
|
r20441 | _localphasemove(pushop, cheads) | ||
# don't push any phase data as there is nothing to push | ||||
else: | ||||
ana = phases.analyzeremotephases(pushop.repo, cheads, | ||||
remotephases) | ||||
pheads, droots = ana | ||||
### Apply remote phase on local | ||||
if remotephases.get('publishing', False): | ||||
_localphasemove(pushop, cheads) | ||||
else: # publish = False | ||||
_localphasemove(pushop, pheads) | ||||
_localphasemove(pushop, cheads, phases.draft) | ||||
### Apply local phase on remote | ||||
Pierre-Yves David
|
r22615 | if pushop.cgresult: | ||
Pierre-Yves David
|
r22020 | if 'phases' in pushop.stepsdone: | ||
# phases already pushed though bundle2 | ||||
return | ||||
Pierre-Yves David
|
r22019 | outdated = pushop.outdatedphases | ||
else: | ||||
outdated = pushop.fallbackoutdatedphases | ||||
Pierre-Yves David
|
r22020 | pushop.stepsdone.add('phases') | ||
Pierre-Yves David
|
r22019 | # filter heads already turned public by the push | ||
outdated = [c for c in outdated if c.node() not in pheads] | ||||
Pierre-Yves David
|
r23376 | # fallback to independent pushkey command | ||
for newremotehead in outdated: | ||||
Gregory Szorc
|
r37665 | with pushop.remote.commandexecutor() as e: | ||
r = e.callcommand('pushkey', { | ||||
'namespace': 'phases', | ||||
'key': newremotehead.hex(), | ||||
'old': '%d' % phases.draft, | ||||
'new': '%d' % phases.public | ||||
}).result() | ||||
Pierre-Yves David
|
r23376 | if not r: | ||
pushop.ui.warn(_('updating %s to public failed!\n') | ||||
% newremotehead) | ||||
Pierre-Yves David
|
r20441 | |||
Pierre-Yves David
|
r20438 | def _localphasemove(pushop, nodes, phase=phases.public): | ||
"""move <nodes> to <phase> in the local source repo""" | ||||
Eric Sumner
|
r23437 | if pushop.trmanager: | ||
phases.advanceboundary(pushop.repo, | ||||
pushop.trmanager.transaction(), | ||||
phase, | ||||
nodes) | ||||
Pierre-Yves David
|
r20438 | else: | ||
# repo is not locked, do not change any phases! | ||||
# Informs the user that phases should have been moved when | ||||
# applicable. | ||||
actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()] | ||||
phasestr = phases.phasenames[phase] | ||||
if actualmoves: | ||||
pushop.ui.status(_('cannot lock source repo, skipping ' | ||||
'local %s phase update\n') % phasestr) | ||||
Pierre-Yves David
|
r20433 | def _pushobsolete(pushop): | ||
Pierre-Yves David
|
r20434 | """utility function to push obsolete markers to a remote""" | ||
Pierre-Yves David
|
r22036 | if 'obsmarkers' in pushop.stepsdone: | ||
return | ||||
Pierre-Yves David
|
r20433 | repo = pushop.repo | ||
remote = pushop.remote | ||||
Pierre-Yves David
|
r22036 | pushop.stepsdone.add('obsmarkers') | ||
Pierre-Yves David
|
r22350 | if pushop.outobsmarkers: | ||
Pierre-Yves David
|
r25559 | pushop.ui.debug('try to push obsolete markers to remote\n') | ||
Pierre-Yves David
|
r20432 | rslts = [] | ||
Pierre-Yves David
|
r25118 | remotedata = obsolete._pushkeyescape(sorted(pushop.outobsmarkers)) | ||
Pierre-Yves David
|
r20432 | for key in sorted(remotedata, reverse=True): | ||
# reverse sort to ensure we end with dump0 | ||||
data = remotedata[key] | ||||
rslts.append(remote.pushkey('obsolete', key, '', data)) | ||||
if [r for r in rslts if not r]: | ||||
msg = _('failed to push some obsolete markers!\n') | ||||
repo.ui.warn(msg) | ||||
Pierre-Yves David
|
r20431 | def _pushbookmark(pushop): | ||
Pierre-Yves David
|
r20352 | """Update bookmark position on remote""" | ||
Pierre-Yves David
|
r22615 | if pushop.cgresult == 0 or 'bookmarks' in pushop.stepsdone: | ||
Pierre-Yves David
|
r22228 | return | ||
Pierre-Yves David
|
r22240 | pushop.stepsdone.add('bookmarks') | ||
Pierre-Yves David
|
r20431 | ui = pushop.ui | ||
remote = pushop.remote | ||||
Pierre-Yves David
|
r22650 | |||
Pierre-Yves David
|
r22239 | for b, old, new in pushop.outbookmarks: | ||
Pierre-Yves David
|
r22650 | action = 'update' | ||
if not old: | ||||
action = 'export' | ||||
elif not new: | ||||
action = 'delete' | ||||
Gregory Szorc
|
r37665 | |||
with remote.commandexecutor() as e: | ||||
r = e.callcommand('pushkey', { | ||||
'namespace': 'bookmarks', | ||||
'key': b, | ||||
'old': old, | ||||
'new': new, | ||||
}).result() | ||||
if r: | ||||
Pierre-Yves David
|
r22650 | ui.status(bookmsgmap[action][0] % b) | ||
Pierre-Yves David
|
r20352 | else: | ||
Pierre-Yves David
|
r22650 | ui.warn(bookmsgmap[action][1] % b) | ||
# discovery can have set the value form invalid entry | ||||
if pushop.bkresult is not None: | ||||
pushop.bkresult = 1 | ||||
Pierre-Yves David
|
r20469 | |||
Pierre-Yves David
|
r20472 | class pulloperation(object): | ||
"""A object that represent a single pull operation | ||||
Mike Edgar
|
r23219 | It purpose is to carry pull related state and very common operation. | ||
Pierre-Yves David
|
r20472 | |||
Mads Kiilerich
|
r21024 | A new should be created at the beginning of each pull and discarded | ||
Pierre-Yves David
|
r20472 | afterward. | ||
""" | ||||
Pierre-Yves David
|
r25446 | def __init__(self, repo, remote, heads=None, force=False, bookmarks=(), | ||
Gregory Szorc
|
r39589 | remotebookmarks=None, streamclonerequested=None, | ||
Gregory Szorc
|
r40367 | includepats=None, excludepats=None, depth=None): | ||
Siddharth Agarwal
|
r20596 | # repo we pull into | ||
Pierre-Yves David
|
r20472 | self.repo = repo | ||
Siddharth Agarwal
|
r20596 | # repo we pull from | ||
Pierre-Yves David
|
r20473 | self.remote = remote | ||
Pierre-Yves David
|
r20474 | # revision we try to pull (None is "all") | ||
self.heads = heads | ||||
Pierre-Yves David
|
r22654 | # bookmark pulled explicitly | ||
liscju
|
r29376 | self.explicitbookmarks = [repo._bookmarks.expandname(bookmark) | ||
for bookmark in bookmarks] | ||||
Pierre-Yves David
|
r20475 | # do we force pull? | ||
self.force = force | ||||
Gregory Szorc
|
r26448 | # whether a streaming clone was requested | ||
self.streamclonerequested = streamclonerequested | ||||
Eric Sumner
|
r23436 | # transaction manager | ||
self.trmanager = None | ||||
Pierre-Yves David
|
r20487 | # set of common changeset between local and remote before pull | ||
self.common = None | ||||
# set of pulled head | ||||
self.rheads = None | ||||
Mads Kiilerich
|
r21024 | # list of missing changeset to fetch remotely | ||
Pierre-Yves David
|
r20488 | self.fetch = None | ||
Pierre-Yves David
|
r22654 | # remote bookmarks data | ||
Pierre-Yves David
|
r25446 | self.remotebookmarks = remotebookmarks | ||
Mads Kiilerich
|
r21024 | # result of changegroup pulling (used as return code by pull) | ||
Pierre-Yves David
|
r20898 | self.cgresult = None | ||
Pierre-Yves David
|
r22937 | # list of step already done | ||
self.stepsdone = set() | ||||
Gregory Szorc
|
r26689 | # Whether we attempted a clone from pre-generated bundles. | ||
self.clonebundleattempted = False | ||||
Gregory Szorc
|
r39589 | # Set of file patterns to include. | ||
self.includepats = includepats | ||||
# Set of file patterns to exclude. | ||||
self.excludepats = excludepats | ||||
Gregory Szorc
|
r40367 | # Number of ancestor changesets to pull from each pulled head. | ||
self.depth = depth | ||||
Pierre-Yves David
|
r20487 | |||
@util.propertycache | ||||
def pulledsubset(self): | ||||
"""heads of the set of changeset target by the pull""" | ||||
# compute target subset | ||||
if self.heads is None: | ||||
# We pulled every thing possible | ||||
# sync on everything common | ||||
Pierre-Yves David
|
r20878 | c = set(self.common) | ||
ret = list(self.common) | ||||
for n in self.rheads: | ||||
if n not in c: | ||||
ret.append(n) | ||||
return ret | ||||
Pierre-Yves David
|
r20487 | else: | ||
# We pulled a specific subset | ||||
# sync on this subset | ||||
return self.heads | ||||
Pierre-Yves David
|
r20477 | |||
Gregory Szorc
|
r26464 | @util.propertycache | ||
Gregory Szorc
|
r26465 | def canusebundle2(self): | ||
Pierre-Yves David
|
r29682 | return not _forcebundle1(self) | ||
Gregory Szorc
|
r26465 | |||
@util.propertycache | ||||
Gregory Szorc
|
r26464 | def remotebundle2caps(self): | ||
return bundle2.bundle2caps(self.remote) | ||||
Pierre-Yves David
|
r20477 | def gettransaction(self): | ||
Eric Sumner
|
r23436 | # deprecated; talk to trmanager directly | ||
return self.trmanager.transaction() | ||||
Martin von Zweigbergk
|
r33790 | class transactionmanager(util.transactional): | ||
Mads Kiilerich
|
r23543 | """An object to manage the life cycle of a transaction | ||
Eric Sumner
|
r23436 | |||
It creates the transaction on demand and calls the appropriate hooks when | ||||
closing the transaction.""" | ||||
def __init__(self, repo, source, url): | ||||
self.repo = repo | ||||
self.source = source | ||||
self.url = url | ||||
self._tr = None | ||||
def transaction(self): | ||||
"""Return an open transaction object, constructing if necessary""" | ||||
if not self._tr: | ||||
trname = '%s\n%s' % (self.source, util.hidepassword(self.url)) | ||||
self._tr = self.repo.transaction(trname) | ||||
self._tr.hookargs['source'] = self.source | ||||
self._tr.hookargs['url'] = self.url | ||||
Pierre-Yves David
|
r20477 | return self._tr | ||
Eric Sumner
|
r23436 | def close(self): | ||
Pierre-Yves David
|
r20477 | """close transaction if created""" | ||
if self._tr is not None: | ||||
Pierre-Yves David
|
r23222 | self._tr.close() | ||
Pierre-Yves David
|
r20477 | |||
Eric Sumner
|
r23436 | def release(self): | ||
Pierre-Yves David
|
r20477 | """release transaction if created""" | ||
if self._tr is not None: | ||||
self._tr.release() | ||||
Pierre-Yves David
|
r20469 | |||
Gregory Szorc
|
r37775 | def listkeys(remote, namespace): | ||
with remote.commandexecutor() as e: | ||||
return e.callcommand('listkeys', {'namespace': namespace}).result() | ||||
Joerg Sonnenberger
|
r37516 | def _fullpullbundle2(repo, pullop): | ||
# The server may send a partial reply, i.e. when inlining | ||||
# pre-computed bundles. In that case, update the common | ||||
# set based on the results and pull another bundle. | ||||
# | ||||
# There are two indicators that the process is finished: | ||||
# - no changeset has been added, or | ||||
# - all remote heads are known locally. | ||||
# The head check must use the unfiltered view as obsoletion | ||||
# markers can hide heads. | ||||
unfi = repo.unfiltered() | ||||
unficl = unfi.changelog | ||||
def headsofdiff(h1, h2): | ||||
"""Returns heads(h1 % h2)""" | ||||
res = unfi.set('heads(%ln %% %ln)', h1, h2) | ||||
return set(ctx.node() for ctx in res) | ||||
def headsofunion(h1, h2): | ||||
"""Returns heads((h1 + h2) - null)""" | ||||
res = unfi.set('heads((%ln + %ln - null))', h1, h2) | ||||
return set(ctx.node() for ctx in res) | ||||
while True: | ||||
old_heads = unficl.heads() | ||||
clstart = len(unficl) | ||||
_pullbundle2(pullop) | ||||
Martin von Zweigbergk
|
r38871 | if repository.NARROW_REQUIREMENT in repo.requirements: | ||
Joerg Sonnenberger
|
r37516 | # XXX narrow clones filter the heads on the server side during | ||
# XXX getbundle and result in partial replies as well. | ||||
# XXX Disable pull bundles in this case as band aid to avoid | ||||
# XXX extra round trips. | ||||
break | ||||
if clstart == len(unficl): | ||||
break | ||||
if all(unficl.hasnode(n) for n in pullop.rheads): | ||||
break | ||||
new_heads = headsofdiff(unficl.heads(), old_heads) | ||||
pullop.common = headsofunion(new_heads, pullop.common) | ||||
pullop.rheads = set(pullop.rheads) - pullop.common | ||||
Gregory Szorc
|
r26448 | def pull(repo, remote, heads=None, force=False, bookmarks=(), opargs=None, | ||
Gregory Szorc
|
r40367 | streamclonerequested=None, includepats=None, excludepats=None, | ||
depth=None): | ||||
Gregory Szorc
|
r26440 | """Fetch repository data from a remote. | ||
This is the main function used to retrieve data from a remote repository. | ||||
``repo`` is the local repository to clone into. | ||||
``remote`` is a peer instance. | ||||
``heads`` is an iterable of revisions we want to pull. ``None`` (the | ||||
default) means to pull everything from the remote. | ||||
``bookmarks`` is an iterable of bookmarks requesting to be pulled. By | ||||
default, all remote bookmarks are pulled. | ||||
``opargs`` are additional keyword arguments to pass to ``pulloperation`` | ||||
initialization. | ||||
Gregory Szorc
|
r26448 | ``streamclonerequested`` is a boolean indicating whether a "streaming | ||
clone" is requested. A "streaming clone" is essentially a raw file copy | ||||
of revlogs from the server. This only works when the local repository is | ||||
empty. The default value of ``None`` means to respect the server | ||||
configuration for preferring stream clones. | ||||
Gregory Szorc
|
r39589 | ``includepats`` and ``excludepats`` define explicit file patterns to | ||
include and exclude in storage, respectively. If not defined, narrow | ||||
patterns from the repo instance are used, if available. | ||||
Gregory Szorc
|
r40367 | ``depth`` is an integer indicating the DAG depth of history we're | ||
interested in. If defined, for each revision specified in ``heads``, we | ||||
will fetch up to this many of its ancestors and data associated with them. | ||||
Gregory Szorc
|
r26440 | |||
Returns the ``pulloperation`` created for this pull. | ||||
""" | ||||
Pierre-Yves David
|
r25445 | if opargs is None: | ||
opargs = {} | ||||
Gregory Szorc
|
r39589 | |||
# We allow the narrow patterns to be passed in explicitly to provide more | ||||
# flexibility for API consumers. | ||||
if includepats or excludepats: | ||||
includepats = includepats or set() | ||||
excludepats = excludepats or set() | ||||
else: | ||||
includepats, excludepats = repo.narrowpats | ||||
narrowspec.validatepatterns(includepats) | ||||
narrowspec.validatepatterns(excludepats) | ||||
Pierre-Yves David
|
r25445 | pullop = pulloperation(repo, remote, heads, force, bookmarks=bookmarks, | ||
Pulkit Goyal
|
r35356 | streamclonerequested=streamclonerequested, | ||
Gregory Szorc
|
r39589 | includepats=includepats, excludepats=excludepats, | ||
Gregory Szorc
|
r40367 | depth=depth, | ||
Pulkit Goyal
|
r35356 | **pycompat.strkwargs(opargs)) | ||
Gregory Szorc
|
r33668 | |||
peerlocal = pullop.remote.local() | ||||
if peerlocal: | ||||
missing = set(peerlocal.requirements) - pullop.repo.supported | ||||
Pierre-Yves David
|
r20469 | if missing: | ||
msg = _("required features are not" | ||||
" supported in the destination:" | ||||
" %s") % (', '.join(sorted(missing))) | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg) | ||
Pierre-Yves David
|
r20469 | |||
Martin von Zweigbergk
|
r35596 | pullop.trmanager = transactionmanager(repo, 'pull', remote.url()) | ||
with repo.wlock(), repo.lock(), pullop.trmanager: | ||||
Gregory Szorc
|
r39665 | # Use the modern wire protocol, if available. | ||
Gregory Szorc
|
r39666 | if remote.capable('command-changesetdata'): | ||
Gregory Szorc
|
r39665 | exchangev2.pull(pullop) | ||
else: | ||||
# This should ideally be in _pullbundle2(). However, it needs to run | ||||
# before discovery to avoid extra work. | ||||
_maybeapplyclonebundle(pullop) | ||||
streamclone.maybeperformlegacystreamclone(pullop) | ||||
_pulldiscovery(pullop) | ||||
if pullop.canusebundle2: | ||||
_fullpullbundle2(repo, pullop) | ||||
_pullchangeset(pullop) | ||||
_pullphase(pullop) | ||||
_pullbookmarks(pullop) | ||||
_pullobsolete(pullop) | ||||
Pierre-Yves David
|
r20469 | |||
Pulkit Goyal
|
r35236 | # storing remotenames | ||
if repo.ui.configbool('experimental', 'remotenames'): | ||||
Pulkit Goyal
|
r35348 | logexchange.pullremotenames(repo, remote) | ||
Pulkit Goyal
|
r35236 | |||
Pierre-Yves David
|
r22693 | return pullop | ||
Pierre-Yves David
|
r20476 | |||
Pierre-Yves David
|
r22936 | # list of steps to perform discovery before pull | ||
pulldiscoveryorder = [] | ||||
# Mapping between step name and function | ||||
# | ||||
# This exists to help extensions wrap steps if necessary | ||||
pulldiscoverymapping = {} | ||||
def pulldiscovery(stepname): | ||||
"""decorator for function performing discovery before pull | ||||
The function is added to the step -> function mapping and appended to the | ||||
list of steps. Beware that decorated function will be added in order (this | ||||
may matter). | ||||
You can only use this decorator for a new step, if you want to wrap a step | ||||
from an extension, change the pulldiscovery dictionary directly.""" | ||||
def dec(func): | ||||
assert stepname not in pulldiscoverymapping | ||||
pulldiscoverymapping[stepname] = func | ||||
pulldiscoveryorder.append(stepname) | ||||
return func | ||||
return dec | ||||
Pierre-Yves David
|
r20900 | def _pulldiscovery(pullop): | ||
Pierre-Yves David
|
r22936 | """Run all discovery steps""" | ||
for stepname in pulldiscoveryorder: | ||||
step = pulldiscoverymapping[stepname] | ||||
step(pullop) | ||||
Pierre-Yves David
|
r25369 | @pulldiscovery('b1:bookmarks') | ||
def _pullbookmarkbundle1(pullop): | ||||
"""fetch bookmark data in bundle1 case | ||||
If not using bundle2, we have to fetch bookmarks before changeset | ||||
discovery to reduce the chance and impact of race conditions.""" | ||||
Pierre-Yves David
|
r25443 | if pullop.remotebookmarks is not None: | ||
return | ||||
Gregory Szorc
|
r26465 | if pullop.canusebundle2 and 'listkeys' in pullop.remotebundle2caps: | ||
Pierre-Yves David
|
r25479 | # all known bundle2 servers now support listkeys, but lets be nice with | ||
# new implementation. | ||||
return | ||||
Gregory Szorc
|
r37775 | books = listkeys(pullop.remote, 'bookmarks') | ||
Boris Feld
|
r35030 | pullop.remotebookmarks = bookmod.unhexlifybookmarks(books) | ||
Pierre-Yves David
|
r25369 | |||
Pierre-Yves David
|
r22936 | @pulldiscovery('changegroup') | ||
def _pulldiscoverychangegroup(pullop): | ||||
Pierre-Yves David
|
r20900 | """discovery phase for the pull | ||
Current handle changeset discovery only, will change handle all discovery | ||||
at some point.""" | ||||
Pierre-Yves David
|
r23848 | tmp = discovery.findcommonincoming(pullop.repo, | ||
Pierre-Yves David
|
r20900 | pullop.remote, | ||
heads=pullop.heads, | ||||
force=pullop.force) | ||||
Pierre-Yves David
|
r23848 | common, fetch, rheads = tmp | ||
nm = pullop.repo.unfiltered().changelog.nodemap | ||||
if fetch and rheads: | ||||
Boris Feld
|
r34318 | # If a remote heads is filtered locally, put in back in common. | ||
Pierre-Yves David
|
r23848 | # | ||
# This is a hackish solution to catch most of "common but locally | ||||
# hidden situation". We do not performs discovery on unfiltered | ||||
# repository because it end up doing a pathological amount of round | ||||
# trip for w huge amount of changeset we do not care about. | ||||
# | ||||
# If a set of such "common but filtered" changeset exist on the server | ||||
# but are not including a remote heads, we'll not be able to detect it, | ||||
scommon = set(common) | ||||
for n in rheads: | ||||
Pierre-Yves David
|
r23975 | if n in nm: | ||
if n not in scommon: | ||||
common.append(n) | ||||
Boris Feld
|
r34318 | if set(rheads).issubset(set(common)): | ||
Pierre-Yves David
|
r23848 | fetch = [] | ||
pullop.common = common | ||||
pullop.fetch = fetch | ||||
pullop.rheads = rheads | ||||
Pierre-Yves David
|
r20900 | |||
Pierre-Yves David
|
r20955 | def _pullbundle2(pullop): | ||
"""pull data using bundle2 | ||||
For now, the only supported data are changegroup.""" | ||||
Gregory Szorc
|
r35801 | kwargs = {'bundlecaps': caps20to10(pullop.repo, role='client')} | ||
Gregory Szorc
|
r26471 | |||
Boris Feld
|
r35779 | # make ui easier to access | ||
ui = pullop.repo.ui | ||||
Siddharth Agarwal
|
r32257 | # At the moment we don't do stream clones over bundle2. If that is | ||
# implemented then here's where the check for that will go. | ||||
Boris Feld
|
r35781 | streaming = streamclone.canperformstreamclone(pullop, bundle2=True)[0] | ||
Gregory Szorc
|
r26471 | |||
Boris Feld
|
r35779 | # declare pull perimeters | ||
kwargs['common'] = pullop.common | ||||
kwargs['heads'] = pullop.heads or pullop.rheads | ||||
Pulkit Goyal
|
r40527 | # check server supports narrow and then adding includepats and excludepats | ||
servernarrow = pullop.remote.capable(wireprototypes.NARROWCAP) | ||||
if servernarrow and pullop.includepats: | ||||
kwargs['includepats'] = pullop.includepats | ||||
if servernarrow and pullop.excludepats: | ||||
kwargs['excludepats'] = pullop.excludepats | ||||
Boris Feld
|
r35781 | if streaming: | ||
kwargs['cg'] = False | ||||
kwargs['stream'] = True | ||||
pullop.stepsdone.add('changegroup') | ||||
Boris Feld
|
r35783 | pullop.stepsdone.add('phases') | ||
Boris Feld
|
r35781 | |||
else: | ||||
Boris Feld
|
r35780 | # pulling changegroup | ||
pullop.stepsdone.add('changegroup') | ||||
Durham Goode
|
r21259 | |||
Boris Feld
|
r35780 | kwargs['cg'] = pullop.fetch | ||
Boris Feld
|
r34323 | |||
Boris Feld
|
r35783 | legacyphase = 'phases' in ui.configlist('devel', 'legacy.exchange') | ||
hasbinaryphase = 'heads' in pullop.remotebundle2caps.get('phases', ()) | ||||
if (not legacyphase and hasbinaryphase): | ||||
kwargs['phases'] = True | ||||
pullop.stepsdone.add('phases') | ||||
Boris Feld
|
r34323 | |||
Boris Feld
|
r35783 | if 'listkeys' in pullop.remotebundle2caps: | ||
if 'phases' not in pullop.stepsdone: | ||||
kwargs['listkeys'] = ['phases'] | ||||
Boris Feld
|
r35779 | |||
Boris Feld
|
r35269 | bookmarksrequested = False | ||
legacybookmark = 'bookmarks' in ui.configlist('devel', 'legacy.exchange') | ||||
hasbinarybook = 'bookmarks' in pullop.remotebundle2caps | ||||
if pullop.remotebookmarks is not None: | ||||
pullop.stepsdone.add('request-bookmarks') | ||||
if ('request-bookmarks' not in pullop.stepsdone | ||||
and pullop.remotebookmarks is None | ||||
and not legacybookmark and hasbinarybook): | ||||
kwargs['bookmarks'] = True | ||||
bookmarksrequested = True | ||||
Gregory Szorc
|
r26464 | if 'listkeys' in pullop.remotebundle2caps: | ||
Boris Feld
|
r35269 | if 'request-bookmarks' not in pullop.stepsdone: | ||
Pierre-Yves David
|
r25444 | # make sure to always includes bookmark data when migrating | ||
# `hg incoming --bundle` to using this function. | ||||
Boris Feld
|
r35269 | pullop.stepsdone.add('request-bookmarks') | ||
Boris Feld
|
r34323 | kwargs.setdefault('listkeys', []).append('bookmarks') | ||
Gregory Szorc
|
r26690 | |||
# If this is a full pull / clone and the server supports the clone bundles | ||||
# feature, tell the server whether we attempted a clone bundle. The | ||||
# presence of this flag indicates the client supports clone bundles. This | ||||
# will enable the server to treat clients that support clone bundles | ||||
# differently from those that don't. | ||||
if (pullop.remote.capable('clonebundles') | ||||
and pullop.heads is None and list(pullop.common) == [nullid]): | ||||
kwargs['cbattempted'] = pullop.clonebundleattempted | ||||
Gregory Szorc
|
r26471 | if streaming: | ||
pullop.repo.ui.status(_('streaming all changes\n')) | ||||
elif not pullop.fetch: | ||||
Pierre-Yves David
|
r21258 | pullop.repo.ui.status(_("no changes found\n")) | ||
pullop.cgresult = 0 | ||||
Pierre-Yves David
|
r20955 | else: | ||
if pullop.heads is None and list(pullop.common) == [nullid]: | ||||
pullop.repo.ui.status(_("requesting all changes\n")) | ||||
Durham Goode
|
r22953 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): | ||
Gregory Szorc
|
r26464 | remoteversions = bundle2.obsmarkersversion(pullop.remotebundle2caps) | ||
Pierre-Yves David
|
r22354 | if obsolete.commonversion(remoteversions) is not None: | ||
kwargs['obsmarkers'] = True | ||||
Pierre-Yves David
|
r22937 | pullop.stepsdone.add('obsmarkers') | ||
Pierre-Yves David
|
r21159 | _pullbundle2extraprepare(pullop, kwargs) | ||
Gregory Szorc
|
r37666 | |||
with pullop.remote.commandexecutor() as e: | ||||
args = dict(kwargs) | ||||
args['source'] = 'pull' | ||||
bundle = e.callcommand('getbundle', args).result() | ||||
try: | ||||
op = bundle2.bundleoperation(pullop.repo, pullop.gettransaction, | ||||
source='pull') | ||||
op.modes['bookmarks'] = 'records' | ||||
bundle2.processbundle(pullop.repo, bundle, op=op) | ||||
except bundle2.AbortFromPart as exc: | ||||
pullop.repo.ui.status(_('remote: abort: %s\n') % exc) | ||||
raise error.Abort(_('pull failed on remote'), hint=exc.hint) | ||||
except error.BundleValueError as exc: | ||||
raise error.Abort(_('missing support for %s') % exc) | ||||
Durham Goode
|
r21259 | |||
if pullop.fetch: | ||||
Martin von Zweigbergk
|
r33037 | pullop.cgresult = bundle2.combinechangegroupresults(op) | ||
Pierre-Yves David
|
r20955 | |||
Pierre-Yves David
|
r21658 | # processing phases change | ||
for namespace, value in op.records['listkeys']: | ||||
if namespace == 'phases': | ||||
_pullapplyphases(pullop, value) | ||||
Pierre-Yves David
|
r22656 | # processing bookmark update | ||
Boris Feld
|
r35269 | if bookmarksrequested: | ||
books = {} | ||||
for record in op.records['bookmarks']: | ||||
books[record['bookmark']] = record["node"] | ||||
pullop.remotebookmarks = books | ||||
else: | ||||
for namespace, value in op.records['listkeys']: | ||||
if namespace == 'bookmarks': | ||||
pullop.remotebookmarks = bookmod.unhexlifybookmarks(value) | ||||
Pierre-Yves David
|
r25444 | |||
# bookmark data were either already there or pulled in the bundle | ||||
if pullop.remotebookmarks is not None: | ||||
_pullbookmarks(pullop) | ||||
Pierre-Yves David
|
r22656 | |||
Pierre-Yves David
|
r21159 | def _pullbundle2extraprepare(pullop, kwargs): | ||
"""hook function so that extensions can extend the getbundle call""" | ||||
Pierre-Yves David
|
r20489 | def _pullchangeset(pullop): | ||
"""pull changeset from unbundle into the local repo""" | ||||
# We delay the open of the transaction as late as possible so we | ||||
# don't open transaction for nothing or you break future useful | ||||
# rollback call | ||||
Pierre-Yves David
|
r22937 | if 'changegroup' in pullop.stepsdone: | ||
Pierre-Yves David
|
r22653 | return | ||
Pierre-Yves David
|
r22937 | pullop.stepsdone.add('changegroup') | ||
Pierre-Yves David
|
r20899 | if not pullop.fetch: | ||
Mike Edgar
|
r23217 | pullop.repo.ui.status(_("no changes found\n")) | ||
pullop.cgresult = 0 | ||||
return | ||||
Martin von Zweigbergk
|
r32930 | tr = pullop.gettransaction() | ||
Pierre-Yves David
|
r20489 | if pullop.heads is None and list(pullop.common) == [nullid]: | ||
pullop.repo.ui.status(_("requesting all changes\n")) | ||||
elif pullop.heads is None and pullop.remote.capable('changegroupsubset'): | ||||
# issue1320, avoid a race if remote changed after discovery | ||||
pullop.heads = pullop.rheads | ||||
if pullop.remote.capable('getbundle'): | ||||
# TODO: get bundlecaps from remote | ||||
cg = pullop.remote.getbundle('pull', common=pullop.common, | ||||
heads=pullop.heads or pullop.rheads) | ||||
elif pullop.heads is None: | ||||
Gregory Szorc
|
r37653 | with pullop.remote.commandexecutor() as e: | ||
cg = e.callcommand('changegroup', { | ||||
'nodes': pullop.fetch, | ||||
'source': 'pull', | ||||
}).result() | ||||
Pierre-Yves David
|
r20489 | elif not pullop.remote.capable('changegroupsubset'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("partial pull cannot be done because " | ||
Pierre-Yves David
|
r21554 | "other repository doesn't support " | ||
"changegroupsubset.")) | ||||
Pierre-Yves David
|
r20489 | else: | ||
Gregory Szorc
|
r37653 | with pullop.remote.commandexecutor() as e: | ||
cg = e.callcommand('changegroupsubset', { | ||||
'bases': pullop.fetch, | ||||
'heads': pullop.heads, | ||||
'source': 'pull', | ||||
}).result() | ||||
Martin von Zweigbergk
|
r33043 | bundleop = bundle2.applybundle(pullop.repo, cg, tr, 'pull', | ||
pullop.remote.url()) | ||||
Martin von Zweigbergk
|
r33040 | pullop.cgresult = bundle2.combinechangegroupresults(bundleop) | ||
Pierre-Yves David
|
r20489 | |||
Pierre-Yves David
|
r20486 | def _pullphase(pullop): | ||
# Get remote phases data from remote | ||||
Pierre-Yves David
|
r22937 | if 'phases' in pullop.stepsdone: | ||
Pierre-Yves David
|
r22653 | return | ||
Gregory Szorc
|
r37775 | remotephases = listkeys(pullop.remote, 'phases') | ||
Pierre-Yves David
|
r21654 | _pullapplyphases(pullop, remotephases) | ||
def _pullapplyphases(pullop, remotephases): | ||||
"""apply phase movement from observed remote state""" | ||||
Pierre-Yves David
|
r22937 | if 'phases' in pullop.stepsdone: | ||
return | ||||
pullop.stepsdone.add('phases') | ||||
Pierre-Yves David
|
r20486 | publishing = bool(remotephases.get('publishing', False)) | ||
if remotephases and not publishing: | ||||
Mads Kiilerich
|
r30332 | # remote is new and non-publishing | ||
Pierre-Yves David
|
r20486 | pheads, _dr = phases.analyzeremotephases(pullop.repo, | ||
pullop.pulledsubset, | ||||
remotephases) | ||||
Pierre-Yves David
|
r22068 | dheads = pullop.pulledsubset | ||
Pierre-Yves David
|
r20486 | else: | ||
# Remote is old or publishing all common changesets | ||||
# should be seen as public | ||||
Pierre-Yves David
|
r22068 | pheads = pullop.pulledsubset | ||
dheads = [] | ||||
unfi = pullop.repo.unfiltered() | ||||
phase = unfi._phasecache.phase | ||||
rev = unfi.changelog.nodemap.get | ||||
public = phases.public | ||||
draft = phases.draft | ||||
# exclude changesets already public locally and update the others | ||||
pheads = [pn for pn in pheads if phase(unfi, rev(pn)) > public] | ||||
if pheads: | ||||
Pierre-Yves David
|
r22069 | tr = pullop.gettransaction() | ||
phases.advanceboundary(pullop.repo, tr, public, pheads) | ||||
Pierre-Yves David
|
r22068 | |||
# exclude changesets already draft locally and update the others | ||||
dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft] | ||||
if dheads: | ||||
Pierre-Yves David
|
r22069 | tr = pullop.gettransaction() | ||
phases.advanceboundary(pullop.repo, tr, draft, dheads) | ||||
Pierre-Yves David
|
r20486 | |||
Pierre-Yves David
|
r22654 | def _pullbookmarks(pullop): | ||
"""process the remote bookmark information to update the local one""" | ||||
Pierre-Yves David
|
r22937 | if 'bookmarks' in pullop.stepsdone: | ||
Pierre-Yves David
|
r22654 | return | ||
Pierre-Yves David
|
r22937 | pullop.stepsdone.add('bookmarks') | ||
Pierre-Yves David
|
r22654 | repo = pullop.repo | ||
remotebookmarks = pullop.remotebookmarks | ||||
bookmod.updatefromremote(repo.ui, repo, remotebookmarks, | ||||
Pierre-Yves David
|
r22658 | pullop.remote.url(), | ||
Pierre-Yves David
|
r22666 | pullop.gettransaction, | ||
Pierre-Yves David
|
r22658 | explicit=pullop.explicitbookmarks) | ||
Pierre-Yves David
|
r22654 | |||
Pierre-Yves David
|
r20478 | def _pullobsolete(pullop): | ||
Pierre-Yves David
|
r20476 | """utility function to pull obsolete markers from a remote | ||
The `gettransaction` is function that return the pull transaction, creating | ||||
one if necessary. We return the transaction to inform the calling code that | ||||
a new transaction have been created (when applicable). | ||||
Exists mostly to allow overriding for experimentation purpose""" | ||||
Pierre-Yves David
|
r22937 | if 'obsmarkers' in pullop.stepsdone: | ||
Pierre-Yves David
|
r22653 | return | ||
Pierre-Yves David
|
r22937 | pullop.stepsdone.add('obsmarkers') | ||
Pierre-Yves David
|
r20476 | tr = None | ||
Durham Goode
|
r22953 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): | ||
Pierre-Yves David
|
r20478 | pullop.repo.ui.debug('fetching remote obsolete markers\n') | ||
Gregory Szorc
|
r37775 | remoteobs = listkeys(pullop.remote, 'obsolete') | ||
Pierre-Yves David
|
r20476 | if 'dump0' in remoteobs: | ||
Pierre-Yves David
|
r20478 | tr = pullop.gettransaction() | ||
Matt Mackall
|
r27558 | markers = [] | ||
Pierre-Yves David
|
r20476 | for key in sorted(remoteobs, reverse=True): | ||
if key.startswith('dump'): | ||||
Yuya Nishihara
|
r32200 | data = util.b85decode(remoteobs[key]) | ||
Matt Mackall
|
r27558 | version, newmarks = obsolete._readmarkers(data) | ||
markers += newmarks | ||||
if markers: | ||||
pullop.repo.obsstore.add(tr, markers) | ||||
Pierre-Yves David
|
r20478 | pullop.repo.invalidatevolatilesets() | ||
Pierre-Yves David
|
r20476 | return tr | ||
Gregory Szorc
|
r38826 | def applynarrowacl(repo, kwargs): | ||
"""Apply narrow fetch access control. | ||||
This massages the named arguments for getbundle wire protocol commands | ||||
so requested data is filtered through access control rules. | ||||
""" | ||||
ui = repo.ui | ||||
# TODO this assumes existence of HTTP and is a layering violation. | ||||
username = ui.shortuser(ui.environ.get('REMOTE_USER') or ui.username()) | ||||
user_includes = ui.configlist( | ||||
_NARROWACL_SECTION, username + '.includes', | ||||
ui.configlist(_NARROWACL_SECTION, 'default.includes')) | ||||
user_excludes = ui.configlist( | ||||
_NARROWACL_SECTION, username + '.excludes', | ||||
ui.configlist(_NARROWACL_SECTION, 'default.excludes')) | ||||
if not user_includes: | ||||
raise error.Abort(_("{} configuration for user {} is empty") | ||||
.format(_NARROWACL_SECTION, username)) | ||||
user_includes = [ | ||||
'path:.' if p == '*' else 'path:' + p for p in user_includes] | ||||
user_excludes = [ | ||||
'path:.' if p == '*' else 'path:' + p for p in user_excludes] | ||||
req_includes = set(kwargs.get(r'includepats', [])) | ||||
req_excludes = set(kwargs.get(r'excludepats', [])) | ||||
req_includes, req_excludes, invalid_includes = narrowspec.restrictpatterns( | ||||
req_includes, req_excludes, user_includes, user_excludes) | ||||
if invalid_includes: | ||||
raise error.Abort( | ||||
_("The following includes are not accessible for {}: {}") | ||||
.format(username, invalid_includes)) | ||||
new_args = {} | ||||
new_args.update(kwargs) | ||||
Gregory Szorc
|
r38843 | new_args[r'narrow'] = True | ||
Pulkit Goyal
|
r40373 | new_args[r'narrow_acl'] = True | ||
Gregory Szorc
|
r38843 | new_args[r'includepats'] = req_includes | ||
Gregory Szorc
|
r38826 | if req_excludes: | ||
Gregory Szorc
|
r38843 | new_args[r'excludepats'] = req_excludes | ||
Gregory Szorc
|
r38826 | return new_args | ||
Gregory Szorc
|
r38827 | def _computeellipsis(repo, common, heads, known, match, depth=None): | ||
"""Compute the shape of a narrowed DAG. | ||||
Args: | ||||
repo: The repository we're transferring. | ||||
common: The roots of the DAG range we're transferring. | ||||
May be just [nullid], which means all ancestors of heads. | ||||
heads: The heads of the DAG range we're transferring. | ||||
match: The narrowmatcher that allows us to identify relevant changes. | ||||
depth: If not None, only consider nodes to be full nodes if they are at | ||||
most depth changesets away from one of heads. | ||||
Returns: | ||||
A tuple of (visitnodes, relevant_nodes, ellipsisroots) where: | ||||
visitnodes: The list of nodes (either full or ellipsis) which | ||||
need to be sent to the client. | ||||
relevant_nodes: The set of changelog nodes which change a file inside | ||||
the narrowspec. The client needs these as non-ellipsis nodes. | ||||
ellipsisroots: A dict of {rev: parents} that is used in | ||||
narrowchangegroup to produce ellipsis nodes with the | ||||
correct parents. | ||||
""" | ||||
cl = repo.changelog | ||||
mfl = repo.manifestlog | ||||
Gregory Szorc
|
r39194 | clrev = cl.rev | ||
commonrevs = {clrev(n) for n in common} | {nullrev} | ||||
headsrevs = {clrev(n) for n in heads} | ||||
Gregory Szorc
|
r38827 | if depth: | ||
revdepth = {h: 0 for h in headsrevs} | ||||
ellipsisheads = collections.defaultdict(set) | ||||
ellipsisroots = collections.defaultdict(set) | ||||
def addroot(head, curchange): | ||||
"""Add a root to an ellipsis head, splitting heads with 3 roots.""" | ||||
ellipsisroots[head].add(curchange) | ||||
# Recursively split ellipsis heads with 3 roots by finding the | ||||
# roots' youngest common descendant which is an elided merge commit. | ||||
# That descendant takes 2 of the 3 roots as its own, and becomes a | ||||
# root of the head. | ||||
while len(ellipsisroots[head]) > 2: | ||||
child, roots = splithead(head) | ||||
splitroots(head, child, roots) | ||||
head = child # Recurse in case we just added a 3rd root | ||||
def splitroots(head, child, roots): | ||||
ellipsisroots[head].difference_update(roots) | ||||
ellipsisroots[head].add(child) | ||||
ellipsisroots[child].update(roots) | ||||
ellipsisroots[child].discard(child) | ||||
def splithead(head): | ||||
r1, r2, r3 = sorted(ellipsisroots[head]) | ||||
for nr1, nr2 in ((r2, r3), (r1, r3), (r1, r2)): | ||||
mid = repo.revs('sort(merge() & %d::%d & %d::%d, -rev)', | ||||
nr1, head, nr2, head) | ||||
for j in mid: | ||||
if j == nr2: | ||||
return nr2, (nr1, nr2) | ||||
if j not in ellipsisroots or len(ellipsisroots[j]) < 2: | ||||
return j, (nr1, nr2) | ||||
raise error.Abort(_('Failed to split up ellipsis node! head: %d, ' | ||||
'roots: %d %d %d') % (head, r1, r2, r3)) | ||||
missing = list(cl.findmissingrevs(common=commonrevs, heads=headsrevs)) | ||||
visit = reversed(missing) | ||||
relevant_nodes = set() | ||||
visitnodes = [cl.node(m) for m in missing] | ||||
required = set(headsrevs) | known | ||||
for rev in visit: | ||||
clrev = cl.changelogrevision(rev) | ||||
Gregory Szorc
|
r39194 | ps = [prev for prev in cl.parentrevs(rev) if prev != nullrev] | ||
Gregory Szorc
|
r38827 | if depth is not None: | ||
curdepth = revdepth[rev] | ||||
for p in ps: | ||||
revdepth[p] = min(curdepth + 1, revdepth.get(p, depth + 1)) | ||||
needed = False | ||||
shallow_enough = depth is None or revdepth[rev] <= depth | ||||
if shallow_enough: | ||||
curmf = mfl[clrev.manifest].read() | ||||
if ps: | ||||
# We choose to not trust the changed files list in | ||||
# changesets because it's not always correct. TODO: could | ||||
# we trust it for the non-merge case? | ||||
p1mf = mfl[cl.changelogrevision(ps[0]).manifest].read() | ||||
needed = bool(curmf.diff(p1mf, match)) | ||||
if not needed and len(ps) > 1: | ||||
# For merge changes, the list of changed files is not | ||||
# helpful, since we need to emit the merge if a file | ||||
# in the narrow spec has changed on either side of the | ||||
# merge. As a result, we do a manifest diff to check. | ||||
p2mf = mfl[cl.changelogrevision(ps[1]).manifest].read() | ||||
needed = bool(curmf.diff(p2mf, match)) | ||||
else: | ||||
# For a root node, we need to include the node if any | ||||
# files in the node match the narrowspec. | ||||
needed = any(curmf.walk(match)) | ||||
if needed: | ||||
for head in ellipsisheads[rev]: | ||||
addroot(head, rev) | ||||
for p in ps: | ||||
required.add(p) | ||||
relevant_nodes.add(cl.node(rev)) | ||||
else: | ||||
if not ps: | ||||
ps = [nullrev] | ||||
if rev in required: | ||||
for head in ellipsisheads[rev]: | ||||
addroot(head, rev) | ||||
for p in ps: | ||||
ellipsisheads[p].add(rev) | ||||
else: | ||||
for p in ps: | ||||
ellipsisheads[p] |= ellipsisheads[rev] | ||||
# add common changesets as roots of their reachable ellipsis heads | ||||
for c in commonrevs: | ||||
for head in ellipsisheads[c]: | ||||
addroot(head, c) | ||||
return visitnodes, relevant_nodes, ellipsisroots | ||||
Gregory Szorc
|
r35801 | def caps20to10(repo, role): | ||
Pierre-Yves David
|
r21645 | """return a set with appropriate options to use bundle20 during getbundle""" | ||
Martin von Zweigbergk
|
r32291 | caps = {'HG20'} | ||
Gregory Szorc
|
r35801 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo, role=role)) | ||
timeless
|
r28883 | caps.add('bundle2=' + urlreq.quote(capsblob)) | ||
Pierre-Yves David
|
r21645 | return caps | ||
Mike Hommey
|
r22542 | # List of names of steps to perform for a bundle2 for getbundle, order matters. | ||
getbundle2partsorder = [] | ||||
# Mapping between step name and function | ||||
# | ||||
# This exists to help extensions wrap steps if necessary | ||||
getbundle2partsmapping = {} | ||||
Pierre-Yves David
|
r24732 | def getbundle2partsgenerator(stepname, idx=None): | ||
Mike Hommey
|
r22542 | """decorator for function generating bundle2 part for getbundle | ||
The function is added to the step -> function mapping and appended to the | ||||
list of steps. Beware that decorated functions will be added in order | ||||
(this may matter). | ||||
You can only use this decorator for new steps, if you want to wrap a step | ||||
from an extension, attack the getbundle2partsmapping dictionary directly.""" | ||||
def dec(func): | ||||
assert stepname not in getbundle2partsmapping | ||||
getbundle2partsmapping[stepname] = func | ||||
Pierre-Yves David
|
r24732 | if idx is None: | ||
getbundle2partsorder.append(stepname) | ||||
else: | ||||
getbundle2partsorder.insert(idx, stepname) | ||||
Mike Hommey
|
r22542 | return func | ||
return dec | ||||
Gregory Szorc
|
r27244 | def bundle2requested(bundlecaps): | ||
if bundlecaps is not None: | ||||
return any(cap.startswith('HG2') for cap in bundlecaps) | ||||
return False | ||||
Gregory Szorc
|
r30187 | def getbundlechunks(repo, source, heads=None, common=None, bundlecaps=None, | ||
**kwargs): | ||||
"""Return chunks constituting a bundle's raw data. | ||||
Pierre-Yves David
|
r20954 | |||
Pierre-Yves David
|
r24686 | Could be a bundle HG10 or a bundle HG20 depending on bundlecaps | ||
Gregory Szorc
|
r30187 | passed. | ||
Pierre-Yves David
|
r20954 | |||
Gregory Szorc
|
r35803 | Returns a 2-tuple of a dict with metadata about the generated bundle | ||
and an iterator over raw chunks (of varying sizes). | ||||
Pierre-Yves David
|
r20954 | """ | ||
Pulkit Goyal
|
r33016 | kwargs = pycompat.byteskwargs(kwargs) | ||
Gregory Szorc
|
r35803 | info = {} | ||
Gregory Szorc
|
r27244 | usebundle2 = bundle2requested(bundlecaps) | ||
Mike Hommey
|
r22542 | # bundle10 case | ||
Pierre-Yves David
|
r24649 | if not usebundle2: | ||
Mike Hommey
|
r22542 | if bundlecaps and not kwargs.get('cg', True): | ||
raise ValueError(_('request for bundle10 must include changegroup')) | ||||
Pierre-Yves David
|
r21656 | if kwargs: | ||
raise ValueError(_('unsupported getbundle arguments: %s') | ||||
% ', '.join(sorted(kwargs.keys()))) | ||||
Pierre-Yves David
|
r29808 | outgoing = _computeoutgoing(repo, heads, common) | ||
Gregory Szorc
|
r35803 | info['bundleversion'] = 1 | ||
return info, changegroup.makestream(repo, outgoing, '01', source, | ||||
bundlecaps=bundlecaps) | ||||
Mike Hommey
|
r22542 | |||
# bundle20 case | ||||
Gregory Szorc
|
r35803 | info['bundleversion'] = 2 | ||
Pierre-Yves David
|
r21143 | b2caps = {} | ||
for bcaps in bundlecaps: | ||||
if bcaps.startswith('bundle2='): | ||||
timeless
|
r28883 | blob = urlreq.unquote(bcaps[len('bundle2='):]) | ||
Pierre-Yves David
|
r21143 | b2caps.update(bundle2.decodecaps(blob)) | ||
bundler = bundle2.bundle20(repo.ui, b2caps) | ||||
Mike Hommey
|
r22542 | |||
Mike Edgar
|
r23218 | kwargs['heads'] = heads | ||
kwargs['common'] = common | ||||
Mike Hommey
|
r22542 | for name in getbundle2partsorder: | ||
func = getbundle2partsmapping[name] | ||||
Mike Hommey
|
r22543 | func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps, | ||
Pulkit Goyal
|
r33017 | **pycompat.strkwargs(kwargs)) | ||
Mike Hommey
|
r22542 | |||
Gregory Szorc
|
r35805 | info['prefercompressed'] = bundler.prefercompressed | ||
Gregory Szorc
|
r35803 | return info, bundler.getchunks() | ||
Mike Hommey
|
r22542 | |||
Gregory Szorc
|
r35806 | @getbundle2partsgenerator('stream2') | ||
Boris Feld
|
r37184 | def _getbundlestream2(bundler, repo, *args, **kwargs): | ||
return bundle2.addpartbundlestream2(bundler, repo, **kwargs) | ||||
Boris Feld
|
r35777 | |||
Mike Hommey
|
r22542 | @getbundle2partsgenerator('changegroup') | ||
Mike Hommey
|
r22543 | def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None, | ||
b2caps=None, heads=None, common=None, **kwargs): | ||||
Mike Hommey
|
r22542 | """add a changegroup part to the requested bundle""" | ||
Gregory Szorc
|
r38828 | if not kwargs.get(r'cg', True): | ||
return | ||||
version = '01' | ||||
cgversions = b2caps.get('changegroup') | ||||
if cgversions: # 3.1 and 3.2 ship with an empty value | ||||
cgversions = [v for v in cgversions | ||||
if v in changegroup.supportedoutgoingversions(repo)] | ||||
if not cgversions: | ||||
raise ValueError(_('no common changegroup version')) | ||||
version = max(cgversions) | ||||
Mike Hommey
|
r22542 | |||
Gregory Szorc
|
r38828 | outgoing = _computeoutgoing(repo, heads, common) | ||
if not outgoing.missing: | ||||
return | ||||
Gregory Szorc
|
r38844 | if kwargs.get(r'narrow', False): | ||
include = sorted(filter(bool, kwargs.get(r'includepats', []))) | ||||
exclude = sorted(filter(bool, kwargs.get(r'excludepats', []))) | ||||
Martin von Zweigbergk
|
r40380 | matcher = narrowspec.match(repo.root, include=include, exclude=exclude) | ||
Gregory Szorc
|
r38844 | else: | ||
Martin von Zweigbergk
|
r40380 | matcher = None | ||
Gregory Szorc
|
r38844 | |||
Gregory Szorc
|
r38828 | cgstream = changegroup.makestream(repo, outgoing, version, source, | ||
Martin von Zweigbergk
|
r40380 | bundlecaps=bundlecaps, matcher=matcher) | ||
Gregory Szorc
|
r38828 | |||
part = bundler.newpart('changegroup', data=cgstream) | ||||
if cgversions: | ||||
part.addparam('version', version) | ||||
part.addparam('nbchanges', '%d' % len(outgoing.missing), | ||||
mandatory=False) | ||||
if 'treemanifest' in repo.requirements: | ||||
part.addparam('treemanifest', '1') | ||||
Mike Hommey
|
r22542 | |||
Pulkit Goyal
|
r40388 | if (kwargs.get(r'narrow', False) and kwargs.get(r'narrow_acl', False) | ||
Pulkit Goyal
|
r40373 | and (include or exclude)): | ||
Gregory Szorc
|
r38844 | narrowspecpart = bundler.newpart('narrow:spec') | ||
if include: | ||||
narrowspecpart.addparam( | ||||
'include', '\n'.join(include), mandatory=True) | ||||
if exclude: | ||||
narrowspecpart.addparam( | ||||
'exclude', '\n'.join(exclude), mandatory=True) | ||||
Boris Feld
|
r35268 | @getbundle2partsgenerator('bookmarks') | ||
def _getbundlebookmarkpart(bundler, repo, source, bundlecaps=None, | ||||
b2caps=None, **kwargs): | ||||
"""add a bookmark part to the requested bundle""" | ||||
Pulkit Goyal
|
r35356 | if not kwargs.get(r'bookmarks', False): | ||
Boris Feld
|
r35268 | return | ||
if 'bookmarks' not in b2caps: | ||||
raise ValueError(_('no common bookmarks exchange method')) | ||||
books = bookmod.listbinbookmarks(repo) | ||||
data = bookmod.binaryencode(books) | ||||
if data: | ||||
bundler.newpart('bookmarks', data=data) | ||||
Mike Hommey
|
r22542 | @getbundle2partsgenerator('listkeys') | ||
Mike Hommey
|
r22543 | def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None, | ||
b2caps=None, **kwargs): | ||||
Mike Hommey
|
r22542 | """add parts containing listkeys namespaces to the requested bundle""" | ||
Pulkit Goyal
|
r35356 | listkeys = kwargs.get(r'listkeys', ()) | ||
Pierre-Yves David
|
r21657 | for namespace in listkeys: | ||
Pierre-Yves David
|
r24686 | part = bundler.newpart('listkeys') | ||
Pierre-Yves David
|
r21657 | part.addparam('namespace', namespace) | ||
keys = repo.listkeys(namespace).items() | ||||
part.data = pushkey.encodekeys(keys) | ||||
Pierre-Yves David
|
r20967 | |||
Mike Hommey
|
r22542 | @getbundle2partsgenerator('obsmarkers') | ||
Mike Hommey
|
r22543 | def _getbundleobsmarkerpart(bundler, repo, source, bundlecaps=None, | ||
b2caps=None, heads=None, **kwargs): | ||||
Mike Hommey
|
r22541 | """add an obsolescence markers part to the requested bundle""" | ||
Pulkit Goyal
|
r35356 | if kwargs.get(r'obsmarkers', False): | ||
Pierre-Yves David
|
r22353 | if heads is None: | ||
heads = repo.heads() | ||||
subset = [c.node() for c in repo.set('::%ln', heads)] | ||||
markers = repo.obsstore.relevantmarkers(subset) | ||||
Pierre-Yves David
|
r25118 | markers = sorted(markers) | ||
r32515 | bundle2.buildobsmarkerspart(bundler, markers) | |||
Pierre-Yves David
|
r22353 | |||
Boris Feld
|
r34323 | @getbundle2partsgenerator('phases') | ||
def _getbundlephasespart(bundler, repo, source, bundlecaps=None, | ||||
b2caps=None, heads=None, **kwargs): | ||||
"""add phase heads part to the requested bundle""" | ||||
Pulkit Goyal
|
r35356 | if kwargs.get(r'phases', False): | ||
Boris Feld
|
r34323 | if not 'heads' in b2caps.get('phases'): | ||
raise ValueError(_('no common phases exchange method')) | ||||
if heads is None: | ||||
heads = repo.heads() | ||||
headsbyphase = collections.defaultdict(set) | ||||
if repo.publishing(): | ||||
headsbyphase[phases.public] = heads | ||||
else: | ||||
# find the appropriate heads to move | ||||
phase = repo._phasecache.phase | ||||
node = repo.changelog.node | ||||
rev = repo.changelog.rev | ||||
for h in heads: | ||||
headsbyphase[phase(repo, rev(h))].add(h) | ||||
seenphases = list(headsbyphase.keys()) | ||||
# We do not handle anything but public and draft phase for now) | ||||
if seenphases: | ||||
assert max(seenphases) <= phases.draft | ||||
# if client is pulling non-public changesets, we need to find | ||||
# intermediate public heads. | ||||
draftheads = headsbyphase.get(phases.draft, set()) | ||||
if draftheads: | ||||
publicheads = headsbyphase.get(phases.public, set()) | ||||
revset = 'heads(only(%ln, %ln) and public())' | ||||
extraheads = repo.revs(revset, draftheads, publicheads) | ||||
for r in extraheads: | ||||
headsbyphase[phases.public].add(node(r)) | ||||
# transform data in a format used by the encoding function | ||||
phasemapping = [] | ||||
for phase in phases.allphases: | ||||
phasemapping.append(sorted(headsbyphase[phase])) | ||||
# generate the actual part | ||||
phasedata = phases.binaryencode(phasemapping) | ||||
bundler.newpart('phase-heads', data=phasedata) | ||||
Gregory Szorc
|
r25402 | @getbundle2partsgenerator('hgtagsfnodes') | ||
def _getbundletagsfnodes(bundler, repo, source, bundlecaps=None, | ||||
b2caps=None, heads=None, common=None, | ||||
**kwargs): | ||||
"""Transfer the .hgtags filenodes mapping. | ||||
Only values for heads in this bundle will be transferred. | ||||
The part data consists of pairs of 20 byte changeset node and .hgtags | ||||
filenodes raw values. | ||||
""" | ||||
# Don't send unless: | ||||
# - changeset are being exchanged, | ||||
# - the client supports it. | ||||
Pulkit Goyal
|
r35356 | if not (kwargs.get(r'cg', True) and 'hgtagsfnodes' in b2caps): | ||
Gregory Szorc
|
r25402 | return | ||
Pierre-Yves David
|
r29808 | outgoing = _computeoutgoing(repo, heads, common) | ||
r32217 | bundle2.addparttagsfnodescache(repo, bundler, outgoing) | |||
Gregory Szorc
|
r25402 | |||
Boris Feld
|
r36984 | @getbundle2partsgenerator('cache:rev-branch-cache') | ||
def _getbundlerevbranchcache(bundler, repo, source, bundlecaps=None, | ||||
b2caps=None, heads=None, common=None, | ||||
**kwargs): | ||||
"""Transfer the rev-branch-cache mapping | ||||
The payload is a series of data related to each branch | ||||
1) branch name length | ||||
2) number of open heads | ||||
3) number of closed heads | ||||
4) open heads nodes | ||||
5) closed heads nodes | ||||
""" | ||||
# Don't send unless: | ||||
# - changeset are being exchanged, | ||||
# - the client supports it. | ||||
Gregory Szorc
|
r38825 | # - narrow bundle isn't in play (not currently compatible). | ||
if (not kwargs.get(r'cg', True) | ||||
or 'rev-branch-cache' not in b2caps | ||||
or kwargs.get(r'narrow', False) | ||||
or repo.ui.has_section(_NARROWACL_SECTION)): | ||||
Boris Feld
|
r36984 | return | ||
Gregory Szorc
|
r38825 | |||
Boris Feld
|
r36984 | outgoing = _computeoutgoing(repo, heads, common) | ||
bundle2.addpartrevbranchcache(repo, bundler, outgoing) | ||||
Pierre-Yves David
|
r20967 | def check_heads(repo, their_heads, context): | ||
"""check if the heads of a repo have been modified | ||||
Used by peer for unbundling. | ||||
""" | ||||
heads = repo.heads() | ||||
Augie Fackler
|
r29341 | heads_hash = hashlib.sha1(''.join(sorted(heads))).digest() | ||
Pierre-Yves David
|
r20967 | if not (their_heads == ['force'] or their_heads == heads or | ||
their_heads == ['hashed', heads_hash]): | ||||
# someone else committed/pushed/unbundled while we | ||||
# were transferring data | ||||
Pierre-Yves David
|
r21184 | raise error.PushRaced('repository changed while %s - ' | ||
'please try again' % context) | ||||
Pierre-Yves David
|
r20968 | |||
def unbundle(repo, cg, heads, source, url): | ||||
"""Apply a bundle to a repo. | ||||
this function makes sure the repo is locked during the application and have | ||||
Mads Kiilerich
|
r21024 | mechanism to check that no push race occurred between the creation of the | ||
Pierre-Yves David
|
r20968 | bundle and its application. | ||
If the push was raced as PushRaced exception is raised.""" | ||||
r = 0 | ||||
Pierre-Yves David
|
r21061 | # need a transaction when processing a bundle2 stream | ||
Durham Goode
|
r26566 | # [wlock, lock, tr] - needs to be an array so nested functions can modify it | ||
lockandtr = [None, None, None] | ||||
Pierre-Yves David
|
r24847 | recordout = None | ||
Pierre-Yves David
|
r24878 | # quick fix for output mismatch with bundle2 in 3.4 | ||
Jun Wu
|
r33499 | captureoutput = repo.ui.configbool('experimental', 'bundle2-output-capture') | ||
Pierre-Yves David
|
r25423 | if url.startswith('remote:http:') or url.startswith('remote:https:'): | ||
Pierre-Yves David
|
r24878 | captureoutput = True | ||
Pierre-Yves David
|
r20968 | try: | ||
Pierre-Yves David
|
r30868 | # note: outside bundle1, 'heads' is expected to be empty and this | ||
# 'check_heads' call wil be a no-op | ||||
Pierre-Yves David
|
r20968 | check_heads(repo, heads, 'uploading changes') | ||
# push can proceed | ||||
Martin von Zweigbergk
|
r32891 | if not isinstance(cg, bundle2.unbundle20): | ||
Pierre-Yves David
|
r30870 | # legacy case: bundle1 (changegroup 01) | ||
Martin von Zweigbergk
|
r32927 | txnname = "\n".join([source, util.hidepassword(url)]) | ||
Martin von Zweigbergk
|
r32930 | with repo.lock(), repo.transaction(txnname) as tr: | ||
Martin von Zweigbergk
|
r33043 | op = bundle2.applybundle(repo, cg, tr, source, url) | ||
Martin von Zweigbergk
|
r33040 | r = bundle2.combinechangegroupresults(op) | ||
Pierre-Yves David
|
r30870 | else: | ||
Pierre-Yves David
|
r24795 | r = None | ||
Pierre-Yves David
|
r21187 | try: | ||
Durham Goode
|
r26566 | def gettransaction(): | ||
if not lockandtr[2]: | ||||
lockandtr[0] = repo.wlock() | ||||
lockandtr[1] = repo.lock() | ||||
lockandtr[2] = repo.transaction(source) | ||||
lockandtr[2].hookargs['source'] = source | ||||
lockandtr[2].hookargs['url'] = url | ||||
lockandtr[2].hookargs['bundle2'] = '1' | ||||
return lockandtr[2] | ||||
# Do greedy locking by default until we're satisfied with lazy | ||||
# locking. | ||||
if not repo.ui.configbool('experimental', 'bundle2lazylocking'): | ||||
gettransaction() | ||||
op = bundle2.bundleoperation(repo, gettransaction, | ||||
Pulkit Goyal
|
r37254 | captureoutput=captureoutput, | ||
source='push') | ||||
Pierre-Yves David
|
r24851 | try: | ||
Martin von Zweigbergk
|
r25896 | op = bundle2.processbundle(repo, cg, op=op) | ||
Pierre-Yves David
|
r24851 | finally: | ||
r = op.reply | ||||
Pierre-Yves David
|
r24878 | if captureoutput and r is not None: | ||
Pierre-Yves David
|
r24851 | repo.ui.pushbuffer(error=True, subproc=True) | ||
def recordout(output): | ||||
r.newpart('output', data=output, mandatory=False) | ||||
Durham Goode
|
r26566 | if lockandtr[2] is not None: | ||
lockandtr[2].close() | ||||
Gregory Szorc
|
r25660 | except BaseException as exc: | ||
Pierre-Yves David
|
r21187 | exc.duringunbundle2 = True | ||
Pierre-Yves David
|
r24878 | if captureoutput and r is not None: | ||
Pierre-Yves David
|
r24847 | parts = exc._bundle2salvagedoutput = r.salvageoutput() | ||
def recordout(output): | ||||
part = bundle2.bundlepart('output', data=output, | ||||
mandatory=False) | ||||
parts.append(part) | ||||
Pierre-Yves David
|
r21187 | raise | ||
Pierre-Yves David
|
r20968 | finally: | ||
Durham Goode
|
r26566 | lockmod.release(lockandtr[2], lockandtr[1], lockandtr[0]) | ||
Pierre-Yves David
|
r24847 | if recordout is not None: | ||
recordout(repo.ui.popbuffer()) | ||||
Pierre-Yves David
|
r20968 | return r | ||
Gregory Szorc
|
r26623 | |||
def _maybeapplyclonebundle(pullop): | ||||
"""Apply a clone bundle from a remote, if possible.""" | ||||
repo = pullop.repo | ||||
remote = pullop.remote | ||||
Jun Wu
|
r33499 | if not repo.ui.configbool('ui', 'clonebundles'): | ||
Gregory Szorc
|
r26623 | return | ||
Gregory Szorc
|
r26855 | # Only run if local repo is empty. | ||
if len(repo): | ||||
return | ||||
Gregory Szorc
|
r26623 | if pullop.heads: | ||
return | ||||
if not remote.capable('clonebundles'): | ||||
return | ||||
Gregory Szorc
|
r37667 | with remote.commandexecutor() as e: | ||
res = e.callcommand('clonebundles', {}).result() | ||||
Gregory Szorc
|
r26689 | |||
# If we call the wire protocol command, that's good enough to record the | ||||
# attempt. | ||||
pullop.clonebundleattempted = True | ||||
Gregory Szorc
|
r26647 | entries = parseclonebundlesmanifest(repo, res) | ||
Gregory Szorc
|
r26623 | if not entries: | ||
repo.ui.note(_('no clone bundles available on remote; ' | ||||
'falling back to regular clone\n')) | ||||
return | ||||
Gregory Szorc
|
r34360 | entries = filterclonebundleentries( | ||
repo, entries, streamclonerequested=pullop.streamclonerequested) | ||||
Gregory Szorc
|
r26644 | if not entries: | ||
# There is a thundering herd concern here. However, if a server | ||||
# operator doesn't advertise bundles appropriate for its clients, | ||||
# they deserve what's coming. Furthermore, from a client's | ||||
# perspective, no automatic fallback would mean not being able to | ||||
# clone! | ||||
repo.ui.warn(_('no compatible clone bundles available on server; ' | ||||
'falling back to regular clone\n')) | ||||
repo.ui.warn(_('(you may want to report this to the server ' | ||||
'operator)\n')) | ||||
return | ||||
Gregory Szorc
|
r26648 | entries = sortclonebundleentries(repo.ui, entries) | ||
Gregory Szorc
|
r26644 | |||
Gregory Szorc
|
r26623 | url = entries[0]['URL'] | ||
repo.ui.status(_('applying clone bundle from %s\n') % url) | ||||
if trypullbundlefromurl(repo.ui, repo, url): | ||||
repo.ui.status(_('finished applying clone bundle\n')) | ||||
# Bundle failed. | ||||
# | ||||
# We abort by default to avoid the thundering herd of | ||||
# clients flooding a server that was expecting expensive | ||||
# clone load to be offloaded. | ||||
Jun Wu
|
r33499 | elif repo.ui.configbool('ui', 'clonebundlefallback'): | ||
Gregory Szorc
|
r26623 | repo.ui.warn(_('falling back to normal clone\n')) | ||
else: | ||||
raise error.Abort(_('error applying bundle'), | ||||
Gregory Szorc
|
r26688 | hint=_('if this error persists, consider contacting ' | ||
'the server operator or disable clone ' | ||||
'bundles via ' | ||||
Gregory Szorc
|
r27738 | '"--config ui.clonebundles=false"')) | ||
Gregory Szorc
|
r26623 | |||
Gregory Szorc
|
r26647 | def parseclonebundlesmanifest(repo, s): | ||
Gregory Szorc
|
r26623 | """Parses the raw text of a clone bundles manifest. | ||
Returns a list of dicts. The dicts have a ``URL`` key corresponding | ||||
to the URL and other keys are the attributes for the entry. | ||||
""" | ||||
m = [] | ||||
for line in s.splitlines(): | ||||
fields = line.split() | ||||
if not fields: | ||||
continue | ||||
attrs = {'URL': fields[0]} | ||||
for rawattr in fields[1:]: | ||||
key, value = rawattr.split('=', 1) | ||||
timeless
|
r28883 | key = urlreq.unquote(key) | ||
value = urlreq.unquote(value) | ||||
Gregory Szorc
|
r26647 | attrs[key] = value | ||
# Parse BUNDLESPEC into components. This makes client-side | ||||
# preferences easier to specify since you can prefer a single | ||||
# component of the BUNDLESPEC. | ||||
if key == 'BUNDLESPEC': | ||||
try: | ||||
Joerg Sonnenberger
|
r37786 | bundlespec = parsebundlespec(repo, value) | ||
Boris Feld
|
r37181 | attrs['COMPRESSION'] = bundlespec.compression | ||
attrs['VERSION'] = bundlespec.version | ||||
Gregory Szorc
|
r26647 | except error.InvalidBundleSpecification: | ||
pass | ||||
except error.UnsupportedBundleSpecification: | ||||
pass | ||||
Gregory Szorc
|
r26623 | |||
m.append(attrs) | ||||
return m | ||||
Boris Feld
|
r37187 | def isstreamclonespec(bundlespec): | ||
# Stream clone v1 | ||||
Joerg Sonnenberger
|
r37786 | if (bundlespec.wirecompression == 'UN' and bundlespec.wireversion == 's1'): | ||
Boris Feld
|
r37187 | return True | ||
# Stream clone v2 | ||||
Joerg Sonnenberger
|
r37786 | if (bundlespec.wirecompression == 'UN' and \ | ||
bundlespec.wireversion == '02' and \ | ||||
Boris Feld
|
r37187 | bundlespec.contentopts.get('streamv2')): | ||
return True | ||||
return False | ||||
Gregory Szorc
|
r34360 | def filterclonebundleentries(repo, entries, streamclonerequested=False): | ||
Gregory Szorc
|
r26687 | """Remove incompatible clone bundle manifest entries. | ||
Accepts a list of entries parsed with ``parseclonebundlesmanifest`` | ||||
and returns a new list consisting of only the entries that this client | ||||
should be able to apply. | ||||
There is no guarantee we'll be able to apply all returned entries because | ||||
the metadata we use to filter on may be missing or wrong. | ||||
""" | ||||
Gregory Szorc
|
r26644 | newentries = [] | ||
for entry in entries: | ||||
spec = entry.get('BUNDLESPEC') | ||||
if spec: | ||||
try: | ||||
Boris Feld
|
r37181 | bundlespec = parsebundlespec(repo, spec, strict=True) | ||
Gregory Szorc
|
r34360 | |||
# If a stream clone was requested, filter out non-streamclone | ||||
# entries. | ||||
Boris Feld
|
r37187 | if streamclonerequested and not isstreamclonespec(bundlespec): | ||
Gregory Szorc
|
r34360 | repo.ui.debug('filtering %s because not a stream clone\n' % | ||
entry['URL']) | ||||
continue | ||||
Gregory Szorc
|
r26644 | except error.InvalidBundleSpecification as e: | ||
Pulkit Goyal
|
r37681 | repo.ui.debug(stringutil.forcebytestr(e) + '\n') | ||
Gregory Szorc
|
r26644 | continue | ||
except error.UnsupportedBundleSpecification as e: | ||||
repo.ui.debug('filtering %s because unsupported bundle ' | ||||
Augie Fackler
|
r36440 | 'spec: %s\n' % ( | ||
Yuya Nishihara
|
r37102 | entry['URL'], stringutil.forcebytestr(e))) | ||
Gregory Szorc
|
r26644 | continue | ||
Gregory Szorc
|
r34360 | # If we don't have a spec and requested a stream clone, we don't know | ||
# what the entry is so don't attempt to apply it. | ||||
elif streamclonerequested: | ||||
repo.ui.debug('filtering %s because cannot determine if a stream ' | ||||
'clone bundle\n' % entry['URL']) | ||||
continue | ||||
Gregory Szorc
|
r26644 | |||
Gregory Szorc
|
r26645 | if 'REQUIRESNI' in entry and not sslutil.hassni: | ||
repo.ui.debug('filtering %s because SNI not supported\n' % | ||||
entry['URL']) | ||||
continue | ||||
Gregory Szorc
|
r26644 | newentries.append(entry) | ||
return newentries | ||||
Gregory Szorc
|
r30685 | class clonebundleentry(object): | ||
"""Represents an item in a clone bundles manifest. | ||||
This rich class is needed to support sorting since sorted() in Python 3 | ||||
doesn't support ``cmp`` and our comparison is complex enough that ``key=`` | ||||
won't work. | ||||
""" | ||||
Gregory Szorc
|
r26648 | |||
Gregory Szorc
|
r30685 | def __init__(self, value, prefers): | ||
self.value = value | ||||
self.prefers = prefers | ||||
Gregory Szorc
|
r26648 | |||
Gregory Szorc
|
r30685 | def _cmp(self, other): | ||
for prefkey, prefvalue in self.prefers: | ||||
avalue = self.value.get(prefkey) | ||||
bvalue = other.value.get(prefkey) | ||||
Gregory Szorc
|
r26648 | |||
# Special case for b missing attribute and a matches exactly. | ||||
if avalue is not None and bvalue is None and avalue == prefvalue: | ||||
return -1 | ||||
# Special case for a missing attribute and b matches exactly. | ||||
if bvalue is not None and avalue is None and bvalue == prefvalue: | ||||
return 1 | ||||
# We can't compare unless attribute present on both. | ||||
if avalue is None or bvalue is None: | ||||
continue | ||||
# Same values should fall back to next attribute. | ||||
if avalue == bvalue: | ||||
continue | ||||
# Exact matches come first. | ||||
if avalue == prefvalue: | ||||
return -1 | ||||
if bvalue == prefvalue: | ||||
return 1 | ||||
# Fall back to next attribute. | ||||
continue | ||||
# If we got here we couldn't sort by attributes and prefers. Fall | ||||
# back to index order. | ||||
return 0 | ||||
Gregory Szorc
|
r30685 | def __lt__(self, other): | ||
return self._cmp(other) < 0 | ||||
def __gt__(self, other): | ||||
return self._cmp(other) > 0 | ||||
def __eq__(self, other): | ||||
return self._cmp(other) == 0 | ||||
def __le__(self, other): | ||||
return self._cmp(other) <= 0 | ||||
def __ge__(self, other): | ||||
return self._cmp(other) >= 0 | ||||
def __ne__(self, other): | ||||
return self._cmp(other) != 0 | ||||
def sortclonebundleentries(ui, entries): | ||||
r32989 | prefers = ui.configlist('ui', 'clonebundleprefers') | |||
Gregory Szorc
|
r30685 | if not prefers: | ||
return list(entries) | ||||
prefers = [p.split('=', 1) for p in prefers] | ||||
items = sorted(clonebundleentry(v, prefers) for v in entries) | ||||
return [i.value for i in items] | ||||
Gregory Szorc
|
r26648 | |||
Gregory Szorc
|
r26623 | def trypullbundlefromurl(ui, repo, url): | ||
"""Attempt to apply a bundle from a URL.""" | ||||
Martin von Zweigbergk
|
r32843 | with repo.lock(), repo.transaction('bundleurl') as tr: | ||
Gregory Szorc
|
r26623 | try: | ||
Martin von Zweigbergk
|
r32843 | fh = urlmod.open(ui, url) | ||
cg = readbundle(ui, fh, 'stream') | ||||
Gregory Szorc
|
r26643 | |||
Martin von Zweigbergk
|
r33043 | if isinstance(cg, streamclone.streamcloneapplier): | ||
Martin von Zweigbergk
|
r32843 | cg.apply(repo) | ||
else: | ||||
Martin von Zweigbergk
|
r33043 | bundle2.applybundle(repo, cg, tr, 'clonebundles', url) | ||
Martin von Zweigbergk
|
r32843 | return True | ||
except urlerr.httperror as e: | ||||
Augie Fackler
|
r36440 | ui.warn(_('HTTP error fetching bundle: %s\n') % | ||
Yuya Nishihara
|
r37102 | stringutil.forcebytestr(e)) | ||
Martin von Zweigbergk
|
r32843 | except urlerr.urlerror as e: | ||
Pulkit Goyal
|
r36506 | ui.warn(_('error fetching bundle: %s\n') % | ||
Yuya Nishihara
|
r37102 | stringutil.forcebytestr(e.reason)) | ||
Gregory Szorc
|
r26623 | |||
Martin von Zweigbergk
|
r32843 | return False | ||