2014-04-13 21:01:00 +04:00
|
|
|
# exchange.py - utility to exchange data between repos.
|
2014-01-31 03:34:01 +04:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2015-12-23 23:32:08 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2017-09-24 22:27:18 +03:00
|
|
|
import collections
|
2015-12-23 23:32:08 +03:00
|
|
|
import errno
|
2016-06-10 07:12:33 +03:00
|
|
|
import hashlib
|
2015-12-23 23:32:08 +03:00
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from .node import (
|
2017-11-13 06:22:45 +03:00
|
|
|
bin,
|
2015-12-23 23:32:08 +03:00
|
|
|
hex,
|
|
|
|
nullid,
|
|
|
|
)
|
|
|
|
from . import (
|
|
|
|
bookmarks as bookmod,
|
|
|
|
bundle2,
|
|
|
|
changegroup,
|
|
|
|
discovery,
|
|
|
|
error,
|
|
|
|
lock as lockmod,
|
2017-12-06 21:56:45 +03:00
|
|
|
logexchange,
|
2015-12-23 23:32:08 +03:00
|
|
|
obsolete,
|
|
|
|
phases,
|
|
|
|
pushkey,
|
2017-06-17 12:35:11 +03:00
|
|
|
pycompat,
|
2015-12-23 23:32:08 +03:00
|
|
|
scmutil,
|
|
|
|
sslutil,
|
|
|
|
streamclone,
|
|
|
|
url as urlmod,
|
|
|
|
util,
|
|
|
|
)
|
2014-01-31 03:34:01 +04:00
|
|
|
|
2016-04-07 02:22:12 +03:00
|
|
|
urlerr = util.urlerr
|
|
|
|
urlreq = util.urlreq
|
|
|
|
|
2015-10-13 20:57:54 +03:00
|
|
|
# Maps bundle version human names to changegroup versions.
|
|
|
|
_bundlespeccgversions = {'v1': '01',
|
|
|
|
'v2': '02',
|
2015-10-15 23:00:45 +03:00
|
|
|
'packed1': 's1',
|
2015-10-13 20:57:54 +03:00
|
|
|
'bundle2': '02', #legacy
|
|
|
|
}
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2017-03-16 22:23:56 +03:00
|
|
|
# Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE.
|
2017-02-11 03:56:29 +03:00
|
|
|
_bundlespecv1compengines = {'gzip', 'bzip2', 'none'}
|
2017-03-16 22:23:56 +03:00
|
|
|
|
2015-10-13 22:29:50 +03:00
|
|
|
def parsebundlespec(repo, spec, strict=True, externalnames=False):
|
2015-10-13 20:57:54 +03:00
|
|
|
"""Parse a bundle string specification into parts.
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2015-10-13 20:57:54 +03:00
|
|
|
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.
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2015-10-13 20:57:54 +03:00
|
|
|
The string currently has the form:
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2015-10-15 03:00:34 +03:00
|
|
|
<compression>-<type>[;<parameter0>[;<parameter1>]]
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2015-10-13 20:57:54 +03:00
|
|
|
Where <compression> is one of the supported compression formats
|
2015-10-15 03:00:34 +03:00
|
|
|
and <type> is (currently) a version string. A ";" can follow the type and
|
2016-10-18 00:16:55 +03:00
|
|
|
all text afterwards is interpreted as URI encoded, ";" delimited key=value
|
2015-10-15 03:00:34 +03:00
|
|
|
pairs.
|
2015-10-13 20:57:54 +03:00
|
|
|
|
|
|
|
If ``strict`` is True (the default) <compression> is required. Otherwise,
|
|
|
|
it is optional.
|
|
|
|
|
2015-10-13 22:29:50 +03:00
|
|
|
If ``externalnames`` is False (the default), the human-centric names will
|
|
|
|
be converted to their internal representation.
|
|
|
|
|
2015-10-15 03:00:34 +03:00
|
|
|
Returns a 3-tuple of (compression, version, parameters). Compression will
|
|
|
|
be ``None`` if not in strict mode and a compression isn't defined.
|
2015-10-13 20:57:54 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Note: this function will likely eventually return a more complex data
|
|
|
|
structure, including bundle2 part information.
|
2015-10-13 21:43:21 +03:00
|
|
|
"""
|
2015-10-15 03:00:34 +03:00
|
|
|
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)
|
2016-04-07 02:22:12 +03:00
|
|
|
key = urlreq.unquote(key)
|
|
|
|
value = urlreq.unquote(value)
|
2015-10-15 03:00:34 +03:00
|
|
|
params[key] = value
|
|
|
|
|
|
|
|
return version, params
|
|
|
|
|
2015-10-13 20:57:54 +03:00
|
|
|
if strict and '-' not in spec:
|
|
|
|
raise error.InvalidBundleSpecification(
|
|
|
|
_('invalid bundle specification; '
|
|
|
|
'must be prefixed with compression: %s') % spec)
|
2015-10-13 21:43:21 +03:00
|
|
|
|
|
|
|
if '-' in spec:
|
2015-10-13 20:57:54 +03:00
|
|
|
compression, version = spec.split('-', 1)
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2016-11-11 10:34:15 +03:00
|
|
|
if compression not in util.compengines.supportedbundlenames:
|
2015-10-13 20:57:54 +03:00
|
|
|
raise error.UnsupportedBundleSpecification(
|
|
|
|
_('%s compression is not supported') % compression)
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2015-10-15 03:00:34 +03:00
|
|
|
version, params = parseparams(version)
|
|
|
|
|
2015-10-13 20:57:54 +03:00
|
|
|
if version not in _bundlespeccgversions:
|
|
|
|
raise error.UnsupportedBundleSpecification(
|
|
|
|
_('%s is not a recognized bundle version') % version)
|
|
|
|
else:
|
|
|
|
# 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
|
|
|
|
|
2015-10-15 03:00:34 +03:00
|
|
|
spec, params = parseparams(spec)
|
|
|
|
|
2016-11-11 10:34:15 +03:00
|
|
|
if spec in util.compengines.supportedbundlenames:
|
2015-10-13 20:57:54 +03:00
|
|
|
compression = spec
|
|
|
|
version = 'v1'
|
2017-03-16 22:33:15 +03:00
|
|
|
# Generaldelta repos require v2.
|
2015-10-13 20:57:54 +03:00
|
|
|
if 'generaldelta' in repo.requirements:
|
|
|
|
version = 'v2'
|
2017-03-16 22:33:15 +03:00
|
|
|
# Modern compression engines require v2.
|
|
|
|
if compression not in _bundlespecv1compengines:
|
|
|
|
version = 'v2'
|
2015-10-13 20:57:54 +03:00
|
|
|
elif spec in _bundlespeccgversions:
|
2015-10-15 23:00:45 +03:00
|
|
|
if spec == 'packed1':
|
|
|
|
compression = 'none'
|
|
|
|
else:
|
|
|
|
compression = 'bzip2'
|
2015-10-13 20:57:54 +03:00
|
|
|
version = spec
|
|
|
|
else:
|
|
|
|
raise error.UnsupportedBundleSpecification(
|
|
|
|
_('%s is not a recognized bundle specification') % spec)
|
|
|
|
|
2017-03-16 22:23:56 +03:00
|
|
|
# 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)
|
|
|
|
|
2015-10-17 20:26:34 +03:00
|
|
|
# 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)))
|
|
|
|
|
2015-10-13 22:29:50 +03:00
|
|
|
if not externalnames:
|
2016-11-11 10:34:15 +03:00
|
|
|
engine = util.compengines.forbundlename(compression)
|
|
|
|
compression = engine.bundletype()[1]
|
2015-10-13 22:29:50 +03:00
|
|
|
version = _bundlespeccgversions[version]
|
2015-10-15 03:00:34 +03:00
|
|
|
return compression, version, params
|
2015-10-13 21:43:21 +03:00
|
|
|
|
2014-04-14 23:45:30 +04:00
|
|
|
def readbundle(ui, fh, fname, vfs=None):
|
2014-04-15 21:42:45 +04:00
|
|
|
header = changegroup.readexactly(fh, 4)
|
2014-04-14 23:33:50 +04:00
|
|
|
|
2014-04-15 21:42:45 +04:00
|
|
|
alg = None
|
2014-04-14 23:33:50 +04:00
|
|
|
if not fname:
|
|
|
|
fname = "stream"
|
|
|
|
if not header.startswith('HG') and header.startswith('\0'):
|
|
|
|
fh = changegroup.headerlessfixup(fh, header)
|
2014-04-15 21:42:45 +04:00
|
|
|
header = "HG10"
|
|
|
|
alg = 'UN'
|
2014-04-14 23:33:50 +04:00
|
|
|
elif vfs:
|
|
|
|
fname = vfs.join(fname)
|
|
|
|
|
2014-04-15 21:42:45 +04:00
|
|
|
magic, version = header[0:2], header[2:4]
|
2014-04-14 23:33:50 +04:00
|
|
|
|
|
|
|
if magic != 'HG':
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('%s: not a Mercurial bundle') % fname)
|
2014-04-15 21:42:45 +04:00
|
|
|
if version == '10':
|
|
|
|
if alg is None:
|
|
|
|
alg = changegroup.readexactly(fh, 2)
|
2014-09-02 14:11:36 +04:00
|
|
|
return changegroup.cg1unpacker(fh, alg)
|
2015-04-08 02:01:32 +03:00
|
|
|
elif version.startswith('2'):
|
2015-04-08 00:14:27 +03:00
|
|
|
return bundle2.getunbundler(ui, fh, magicstring=magic + version)
|
2015-10-15 23:00:45 +03:00
|
|
|
elif version == 'S1':
|
|
|
|
return streamclone.streamcloneapplier(fh)
|
2014-04-15 21:42:45 +04:00
|
|
|
else:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('%s: unknown bundle version %s') % (fname, version))
|
2014-04-14 23:33:50 +04:00
|
|
|
|
2016-01-15 09:49:03 +03:00
|
|
|
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):
|
2016-11-11 10:34:15 +03:00
|
|
|
try:
|
|
|
|
return util.compengines.forbundletype(alg).bundletype()[0]
|
|
|
|
except KeyError:
|
|
|
|
return None
|
2016-01-15 09:49:03 +03:00
|
|
|
|
|
|
|
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'))
|
|
|
|
|
|
|
|
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]
|
|
|
|
params = 'requirements=%s' % ','.join(sorted(requirements))
|
2016-04-07 02:22:12 +03:00
|
|
|
return 'none-packed1;%s' % urlreq.quote(params)
|
2016-01-15 09:49:03 +03:00
|
|
|
else:
|
|
|
|
raise error.Abort(_('unknown bundle type: %s') % b)
|
|
|
|
|
2016-08-09 18:06:35 +03:00
|
|
|
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)
|
|
|
|
|
2016-08-03 16:01:23 +03:00
|
|
|
def _forcebundle1(op):
|
|
|
|
"""return true if a pull/push must use bundle1
|
2015-04-07 04:31:59 +03:00
|
|
|
|
2016-08-02 15:48:21 +03:00
|
|
|
This function is used to allow testing of the older bundle version"""
|
|
|
|
ui = op.repo.ui
|
|
|
|
forcebundle1 = False
|
2016-10-18 00:16:55 +03:00
|
|
|
# The goal is this config is to allow developer to choose the bundle
|
2016-08-02 15:48:21 +03:00
|
|
|
# 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')
|
2016-08-03 17:23:26 +03:00
|
|
|
forcebundle1 = 'bundle2' not in exchange and 'bundle1' in exchange
|
2016-08-02 15:48:21 +03:00
|
|
|
return forcebundle1 or not op.remote.capable('bundle2')
|
2015-04-07 04:31:59 +03:00
|
|
|
|
2014-01-31 04:43:11 +04:00
|
|
|
class pushoperation(object):
|
|
|
|
"""A object that represent a single push operation
|
|
|
|
|
2016-03-11 02:31:38 +03:00
|
|
|
Its purpose is to carry push related state and very common operations.
|
2014-01-31 04:43:11 +04:00
|
|
|
|
2016-03-11 02:31:38 +03:00
|
|
|
A new pushoperation should be created at the beginning of each push and
|
|
|
|
discarded afterward.
|
2014-01-31 04:43:11 +04:00
|
|
|
"""
|
|
|
|
|
2014-09-25 12:49:20 +04:00
|
|
|
def __init__(self, repo, remote, force=False, revs=None, newbranch=False,
|
2017-08-17 01:48:48 +03:00
|
|
|
bookmarks=(), pushvars=None):
|
2014-01-31 04:43:11 +04:00
|
|
|
# repo we push from
|
|
|
|
self.repo = repo
|
2014-01-31 04:46:30 +04:00
|
|
|
self.ui = repo.ui
|
2014-01-31 04:57:01 +04:00
|
|
|
# repo we push to
|
|
|
|
self.remote = remote
|
2014-01-31 04:59:25 +04:00
|
|
|
# force option provided
|
|
|
|
self.force = force
|
2014-01-31 05:04:23 +04:00
|
|
|
# revs to be pushed (None is "all")
|
|
|
|
self.revs = revs
|
2014-09-25 12:49:20 +04:00
|
|
|
# bookmark explicitly pushed
|
|
|
|
self.bookmarks = bookmarks
|
2014-01-31 05:08:29 +04:00
|
|
|
# allow push of new branch
|
|
|
|
self.newbranch = newbranch
|
2014-07-02 14:48:54 +04:00
|
|
|
# step already performed
|
|
|
|
# (used to check what steps have been already performed through bundle2)
|
|
|
|
self.stepsdone = set()
|
2014-09-25 11:55:39 +04:00
|
|
|
# Integer version of the changegroup push result
|
2014-01-31 07:43:28 +04:00
|
|
|
# - 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()
|
2014-09-25 11:55:39 +04:00
|
|
|
self.cgresult = None
|
2014-09-25 11:57:36 +04:00
|
|
|
# Boolean value for the bookmark push
|
|
|
|
self.bkresult = None
|
2014-04-13 21:01:00 +04:00
|
|
|
# discover.outgoing object (contains common and outgoing data)
|
2014-01-31 08:18:26 +04:00
|
|
|
self.outgoing = None
|
2017-05-29 06:53:58 +03:00
|
|
|
# all remote topological heads before the push
|
2014-01-31 08:34:35 +04:00
|
|
|
self.remoteheads = None
|
2017-05-29 06:53:58 +03:00
|
|
|
# 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
|
2014-01-31 09:01:13 +04:00
|
|
|
# testable as a boolean indicating if any nodes are missing locally.
|
|
|
|
self.incoming = None
|
2017-10-11 19:39:04 +03:00
|
|
|
# summary of the remote phase situation
|
|
|
|
self.remotephases = None
|
2014-07-31 06:26:47 +04:00
|
|
|
# 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
|
2014-07-05 21:17:09 +04:00
|
|
|
# outgoing obsmarkers
|
2014-07-05 21:32:20 +04:00
|
|
|
self.outobsmarkers = set()
|
2014-08-16 05:39:39 +04:00
|
|
|
# outgoing bookmarks
|
|
|
|
self.outbookmarks = []
|
2014-11-22 02:06:38 +03:00
|
|
|
# transaction manager
|
|
|
|
self.trmanager = None
|
2015-06-06 02:30:11 +03:00
|
|
|
# map { pushkey partid -> callback handling failure}
|
|
|
|
# used to handle exception from mandatory pushkey part failure
|
|
|
|
self.pkfailcb = {}
|
2017-08-17 01:48:48 +03:00
|
|
|
# an iterable of pushvars or None
|
|
|
|
self.pushvars = pushvars
|
2014-01-31 04:43:11 +04:00
|
|
|
|
2014-07-01 19:20:31 +04:00
|
|
|
@util.propertycache
|
|
|
|
def futureheads(self):
|
|
|
|
"""future remote heads if the changeset push succeeds"""
|
|
|
|
return self.outgoing.missingheads
|
|
|
|
|
2014-07-01 19:20:47 +04:00
|
|
|
@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)
|
2015-09-08 03:08:35 +03:00
|
|
|
common = self.outgoing.common
|
2014-07-01 19:20:47 +04:00
|
|
|
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
|
|
|
|
|
2014-07-01 19:27:22 +04:00
|
|
|
@property
|
|
|
|
def commonheads(self):
|
|
|
|
"""set of all common heads after changeset bundle push"""
|
2014-09-25 11:55:39 +04:00
|
|
|
if self.cgresult:
|
2014-07-01 19:27:22 +04:00
|
|
|
return self.futureheads
|
|
|
|
else:
|
|
|
|
return self.fallbackheads
|
2014-07-01 19:20:47 +04:00
|
|
|
|
2014-09-27 05:33:11 +04:00
|
|
|
# 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')),
|
|
|
|
}
|
|
|
|
|
2015-10-14 09:04:53 +03:00
|
|
|
def push(repo, remote, force=False, revs=None, newbranch=False, bookmarks=(),
|
|
|
|
opargs=None):
|
2014-01-31 03:34:01 +04:00
|
|
|
'''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()
|
|
|
|
'''
|
2015-10-14 09:04:53 +03:00
|
|
|
if opargs is None:
|
|
|
|
opargs = {}
|
|
|
|
pushop = pushoperation(repo, remote, force, revs, newbranch, bookmarks,
|
2017-09-16 18:09:08 +03:00
|
|
|
**pycompat.strkwargs(opargs))
|
2014-01-31 04:57:01 +04:00
|
|
|
if pushop.remote.local():
|
|
|
|
missing = (set(pushop.repo.requirements)
|
|
|
|
- pushop.remote.local().supported)
|
2014-01-31 03:34:01 +04:00
|
|
|
if missing:
|
|
|
|
msg = _("required features are not"
|
|
|
|
" supported in the destination:"
|
|
|
|
" %s") % (', '.join(sorted(missing)))
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
2014-01-31 03:34:01 +04:00
|
|
|
|
2014-01-31 04:57:01 +04:00
|
|
|
if not pushop.remote.canpush():
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("destination does not support push"))
|
2017-08-07 03:44:56 +03:00
|
|
|
|
|
|
|
if not pushop.remote.capable('unbundle'):
|
|
|
|
raise error.Abort(_('cannot push: destination does not support the '
|
|
|
|
'unbundle wire protocol command'))
|
|
|
|
|
2017-08-15 02:14:14 +03:00
|
|
|
# get lock as we might write phase data
|
|
|
|
wlock = lock = None
|
2014-01-31 03:34:01 +04:00
|
|
|
try:
|
2015-04-15 17:36:21 +03:00
|
|
|
# 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')
|
2016-08-03 16:01:23 +03:00
|
|
|
if (not _forcebundle1(pushop)) and maypushback:
|
2017-08-15 02:14:14 +03:00
|
|
|
wlock = pushop.repo.wlock()
|
|
|
|
lock = pushop.repo.lock()
|
2017-08-15 02:26:36 +03:00
|
|
|
pushop.trmanager = transactionmanager(pushop.repo,
|
|
|
|
'push-response',
|
|
|
|
pushop.remote.url())
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as err:
|
2014-01-31 03:34:01 +04:00
|
|
|
if err.errno != errno.EACCES:
|
|
|
|
raise
|
|
|
|
# source repo cannot be locked.
|
|
|
|
# We do not abort the push, but just disable the local phase
|
|
|
|
# synchronisation.
|
|
|
|
msg = 'cannot lock source repository: %s\n' % err
|
2014-01-31 04:46:30 +04:00
|
|
|
pushop.ui.debug(msg)
|
2017-08-15 02:26:36 +03:00
|
|
|
|
2017-07-29 08:04:27 +03:00
|
|
|
with wlock or util.nullcontextmanager(), \
|
|
|
|
lock or util.nullcontextmanager(), \
|
|
|
|
pushop.trmanager or util.nullcontextmanager():
|
2014-04-02 00:45:48 +04:00
|
|
|
pushop.repo.checkpush(pushop)
|
2017-08-07 03:44:56 +03:00
|
|
|
_pushdiscovery(pushop)
|
|
|
|
if not _forcebundle1(pushop):
|
|
|
|
_pushbundle2(pushop)
|
|
|
|
_pushchangeset(pushop)
|
|
|
|
_pushsyncphase(pushop)
|
|
|
|
_pushobsolete(pushop)
|
|
|
|
_pushbookmark(pushop)
|
|
|
|
|
2014-09-25 13:21:59 +04:00
|
|
|
return pushop
|
2014-01-31 05:46:51 +04:00
|
|
|
|
2014-07-01 19:06:02 +04:00
|
|
|
# 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
|
|
|
|
|
2014-01-31 09:05:29 +04:00
|
|
|
def _pushdiscovery(pushop):
|
2014-07-01 19:06:02 +04:00
|
|
|
"""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"""
|
2014-01-31 09:05:29 +04:00
|
|
|
fci = discovery.findcommonincoming
|
2017-12-07 01:33:01 +03:00
|
|
|
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)
|
2014-01-31 09:05:29 +04:00
|
|
|
common, inc, remoteheads = commoninc
|
|
|
|
fco = discovery.findcommonoutgoing
|
2015-01-07 11:07:29 +03:00
|
|
|
outgoing = fco(pushop.repo, pushop.remote, onlyheads=pushop.revs,
|
2014-01-31 09:05:29 +04:00
|
|
|
commoninc=commoninc, force=pushop.force)
|
|
|
|
pushop.outgoing = outgoing
|
|
|
|
pushop.remoteheads = remoteheads
|
|
|
|
pushop.incoming = inc
|
|
|
|
|
2014-07-31 06:26:47 +04:00
|
|
|
@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()
|
|
|
|
remotephases = pushop.remote.listkeys('phases')
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
if (pushop.ui.configbool('ui', '_usedassubrepo')
|
2015-05-27 16:08:14 +03:00
|
|
|
and remotephases # server supports phases
|
|
|
|
and not pushop.outgoing.missing # no changesets to be pushed
|
2017-10-11 19:39:34 +03:00
|
|
|
and remotephases.get('publishing', False)):
|
2015-05-27 16:08:14 +03:00
|
|
|
# When:
|
|
|
|
# - this is a subrepo push
|
|
|
|
# - and remote support phase
|
|
|
|
# - and no changeset are to be pushed
|
|
|
|
# - and remote is publishing
|
2017-10-16 13:36:42 +03:00
|
|
|
# We may be in issue 3781 case!
|
2015-05-27 16:08:14 +03:00
|
|
|
# We drop the possible phase synchronisation done by
|
|
|
|
# courtesy to publish changesets possibly locally draft
|
|
|
|
# on the remote.
|
2017-10-11 19:39:34 +03:00
|
|
|
pushop.outdatedphases = []
|
|
|
|
pushop.fallbackoutdatedphases = []
|
|
|
|
return
|
2017-10-11 19:39:04 +03:00
|
|
|
|
|
|
|
pushop.remotephases = phases.remotephasessummary(pushop.repo,
|
|
|
|
pushop.fallbackheads,
|
|
|
|
remotephases)
|
|
|
|
droots = pushop.remotephases.draftroots
|
|
|
|
|
2014-07-31 06:26:47 +04:00
|
|
|
extracond = ''
|
2017-10-11 19:39:04 +03:00
|
|
|
if not pushop.remotephases.publishing:
|
2014-07-31 06:26:47 +04:00
|
|
|
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))
|
|
|
|
if not outgoing.missing:
|
|
|
|
future = fallback
|
|
|
|
else:
|
|
|
|
# adds changeset we are going to push as draft
|
|
|
|
#
|
2014-04-18 00:47:38 +04:00
|
|
|
# should not be necessary for publishing server, but because of an
|
2014-07-31 06:26:47 +04:00
|
|
|
# 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
|
|
|
|
|
2014-07-05 21:32:20 +04:00
|
|
|
@pushdiscovery('obsmarker')
|
|
|
|
def _pushdiscoveryobsmarkers(pushop):
|
2014-10-15 00:26:01 +04:00
|
|
|
if (obsolete.isenabled(pushop.repo, obsolete.exchangeopt)
|
2014-08-21 04:36:54 +04:00
|
|
|
and pushop.repo.obsstore
|
|
|
|
and 'obsolete' in pushop.remote.listkeys('namespaces')):
|
2014-08-20 12:15:09 +04:00
|
|
|
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)
|
2014-07-05 21:32:20 +04:00
|
|
|
|
2014-08-16 05:39:39 +04:00
|
|
|
@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:
|
|
|
|
revnums = map(repo.changelog.rev, pushop.revs)
|
|
|
|
ancestors = repo.changelog.ancestors(revnums, inclusive=True)
|
|
|
|
remotebookmark = remote.listkeys('bookmarks')
|
|
|
|
|
2016-02-20 00:28:09 +03:00
|
|
|
explicit = set([repo._bookmarks.expandname(bookmark)
|
|
|
|
for bookmark in pushop.bookmarks])
|
2014-09-28 07:51:53 +04:00
|
|
|
|
2016-12-09 14:22:26 +03:00
|
|
|
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):
|
|
|
|
for b, scid, dcid in bookmarks:
|
|
|
|
yield b, safehex(scid), safehex(dcid)
|
|
|
|
|
|
|
|
comp = [hexifycompbookmarks(marks) for marks in comp]
|
2014-10-24 21:40:37 +04:00
|
|
|
addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp
|
2016-12-09 14:22:26 +03:00
|
|
|
|
2014-08-16 05:39:39 +04:00
|
|
|
for b, scid, dcid in advsrc:
|
2014-09-28 07:51:53 +04:00
|
|
|
if b in explicit:
|
|
|
|
explicit.remove(b)
|
2014-08-16 05:39:39 +04:00
|
|
|
if not ancestors or repo[scid].rev() in ancestors:
|
|
|
|
pushop.outbookmarks.append((b, dcid, scid))
|
2014-09-28 07:51:53 +04:00
|
|
|
# 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
|
2016-12-09 14:22:26 +03:00
|
|
|
for b, scid, dcid in list(advdst) + list(diverge) + list(differ):
|
2014-09-28 07:51:53 +04:00
|
|
|
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, ''))
|
2014-10-25 02:24:46 +04:00
|
|
|
# identical bookmarks shouldn't get reported
|
|
|
|
for b, scid, dcid in same:
|
|
|
|
if b in explicit:
|
|
|
|
explicit.remove(b)
|
2014-09-28 07:51:53 +04:00
|
|
|
|
|
|
|
if explicit:
|
|
|
|
explicit = sorted(explicit)
|
|
|
|
# we should probably list all of them
|
|
|
|
ui.warn(_('bookmark %s does not exist on the local '
|
|
|
|
'or remote repository!\n') % explicit[0])
|
|
|
|
pushop.bkresult = 2
|
|
|
|
|
|
|
|
pushop.outbookmarks.sort()
|
2014-08-16 05:39:39 +04:00
|
|
|
|
2014-01-31 09:01:21 +04:00
|
|
|
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!")
|
2017-08-01 19:07:34 +03:00
|
|
|
mspd = _("push includes phase-divergent changeset: %s!")
|
2017-08-01 18:58:20 +03:00
|
|
|
mscd = _("push includes content-divergent changeset: %s!")
|
2017-08-01 18:53:48 +03:00
|
|
|
mst = {"orphan": _("push includes orphan changeset: %s!"),
|
2017-08-01 19:07:34 +03:00
|
|
|
"phase-divergent": mspd,
|
2017-08-01 18:58:20 +03:00
|
|
|
"content-divergent": mscd}
|
2014-01-31 09:01:21 +04:00
|
|
|
# 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():
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(mso % ctx)
|
2017-08-02 20:13:56 +03:00
|
|
|
elif ctx.isunstable():
|
2017-08-02 19:34:39 +03:00
|
|
|
# TODO print more than one instability in the abort
|
|
|
|
# message
|
|
|
|
raise error.Abort(mst[ctx.instabilities()[0]] % ctx)
|
2015-06-26 01:47:32 +03:00
|
|
|
|
2015-11-10 22:13:21 +03:00
|
|
|
discovery.checkheads(pushop)
|
2014-01-31 09:01:21 +04:00
|
|
|
return True
|
|
|
|
|
2014-07-31 06:04:50 +04:00
|
|
|
# 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 = {}
|
|
|
|
|
2015-04-14 21:07:35 +03:00
|
|
|
def b2partsgenerator(stepname, idx=None):
|
2014-07-31 06:04:50 +04:00
|
|
|
"""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
|
2015-04-14 21:07:35 +03:00
|
|
|
if idx is None:
|
|
|
|
b2partsgenorder.append(stepname)
|
|
|
|
else:
|
|
|
|
b2partsgenorder.insert(idx, stepname)
|
2014-07-31 06:04:50 +04:00
|
|
|
return func
|
|
|
|
return dec
|
|
|
|
|
2015-10-01 20:48:14 +03:00
|
|
|
def _pushb2ctxcheckheads(pushop, bundler):
|
|
|
|
"""Generate race condition checking parts
|
|
|
|
|
2015-10-17 01:58:46 +03:00
|
|
|
Exists as an independent function to aid extensions
|
2015-10-01 20:48:14 +03:00
|
|
|
"""
|
2017-05-29 06:53:58 +03:00
|
|
|
# * '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', ())
|
2017-06-28 18:41:25 +03:00
|
|
|
emptyremote = pushop.pushbranchmap is None
|
|
|
|
if not allowunrelated or emptyremote:
|
2017-05-29 06:53:58 +03:00
|
|
|
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)
|
2015-10-01 20:48:14 +03:00
|
|
|
|
2017-10-11 08:40:00 +03:00
|
|
|
def _pushing(pushop):
|
|
|
|
"""return True if we are pushing anything"""
|
|
|
|
return bool(pushop.outgoing.missing
|
|
|
|
or pushop.outdatedphases
|
|
|
|
or pushop.outobsmarkers
|
|
|
|
or pushop.outbookmarks)
|
|
|
|
|
2017-11-13 06:22:45 +03:00
|
|
|
@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)
|
|
|
|
|
2014-07-31 06:04:50 +04:00
|
|
|
@b2partsgenerator('changeset')
|
2014-07-02 13:42:35 +04:00
|
|
|
def _pushb2ctx(pushop, bundler):
|
|
|
|
"""handle changegroup push through bundle2
|
|
|
|
|
2014-09-25 11:55:39 +04:00
|
|
|
addchangegroup result is stored in the ``pushop.cgresult`` attribute.
|
2014-07-02 13:42:35 +04:00
|
|
|
"""
|
2014-07-07 14:30:31 +04:00
|
|
|
if 'changesets' in pushop.stepsdone:
|
|
|
|
return
|
|
|
|
pushop.stepsdone.add('changesets')
|
2014-07-02 13:42:35 +04:00
|
|
|
# Send known heads to the server for race detection.
|
2014-07-02 14:55:09 +04:00
|
|
|
if not _pushcheckoutgoing(pushop):
|
|
|
|
return
|
2016-04-13 02:09:11 +03:00
|
|
|
pushop.repo.prepushoutgoinghooks(pushop)
|
2015-10-01 20:48:14 +03:00
|
|
|
|
|
|
|
_pushb2ctxcheckheads(pushop, bundler)
|
|
|
|
|
2014-10-17 23:19:24 +04:00
|
|
|
b2caps = bundle2.bundle2caps(pushop.remote)
|
2016-03-26 02:13:28 +03:00
|
|
|
version = '01'
|
2015-04-09 23:25:48 +03:00
|
|
|
cgversions = b2caps.get('changegroup')
|
2016-03-26 02:13:28 +03:00
|
|
|
if cgversions: # 3.1 and 3.2 ship with an empty value
|
2016-01-13 08:01:06 +03:00
|
|
|
cgversions = [v for v in cgversions
|
2016-01-27 20:07:28 +03:00
|
|
|
if v in changegroup.supportedoutgoingversions(
|
|
|
|
pushop.repo)]
|
2014-10-17 23:19:24 +04:00
|
|
|
if not cgversions:
|
|
|
|
raise ValueError(_('no common changegroup version'))
|
|
|
|
version = max(cgversions)
|
2017-09-11 05:01:56 +03:00
|
|
|
cgstream = changegroup.makestream(pushop.repo, pushop.outgoing, version,
|
|
|
|
'push')
|
|
|
|
cgpart = bundler.newpart('changegroup', data=cgstream)
|
2016-03-26 02:13:28 +03:00
|
|
|
if cgversions:
|
2014-10-17 23:19:24 +04:00
|
|
|
cgpart.addparam('version', version)
|
2016-01-23 03:31:50 +03:00
|
|
|
if 'treemanifest' in pushop.repo.requirements:
|
|
|
|
cgpart.addparam('treemanifest', '1')
|
2014-07-02 13:42:35 +04:00
|
|
|
def handlereply(op):
|
2014-04-18 00:47:38 +04:00
|
|
|
"""extract addchangegroup returns from server reply"""
|
2014-07-02 13:42:35 +04:00
|
|
|
cgreplies = op.records.getreplies(cgpart.id)
|
|
|
|
assert len(cgreplies['changegroup']) == 1
|
2014-09-25 11:55:39 +04:00
|
|
|
pushop.cgresult = cgreplies['changegroup'][0]['return']
|
2014-07-02 13:42:35 +04:00
|
|
|
return handlereply
|
|
|
|
|
2014-07-02 01:08:17 +04:00
|
|
|
@b2partsgenerator('phase')
|
|
|
|
def _pushb2phases(pushop, bundler):
|
|
|
|
"""handle phase push through bundle2"""
|
|
|
|
if 'phases' in pushop.stepsdone:
|
|
|
|
return
|
|
|
|
b2caps = bundle2.bundle2caps(pushop.remote)
|
2017-09-20 20:38:06 +03:00
|
|
|
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:
|
2017-10-19 22:50:14 +03:00
|
|
|
return _pushb2phaseheads(pushop, bundler)
|
2017-09-20 20:38:06 +03:00
|
|
|
elif haspushkey:
|
2017-10-19 22:50:14 +03:00
|
|
|
return _pushb2phasespushkey(pushop, bundler)
|
2017-09-20 20:17:37 +03:00
|
|
|
|
2017-09-20 20:38:06 +03:00
|
|
|
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)
|
|
|
|
|
2017-09-20 20:17:37 +03:00
|
|
|
def _pushb2phasespushkey(pushop, bundler):
|
|
|
|
"""push phase information through a bundle2 - pushkey part"""
|
2014-07-02 01:08:17 +04:00
|
|
|
pushop.stepsdone.add('phases')
|
|
|
|
part2node = []
|
2015-05-28 08:25:51 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2014-07-02 01:08:17 +04:00
|
|
|
enc = pushkey.encode
|
|
|
|
for newremotehead in pushop.outdatedphases:
|
2015-05-28 08:25:51 +03:00
|
|
|
part = bundler.newpart('pushkey')
|
2014-07-02 01:08:17 +04:00
|
|
|
part.addparam('namespace', enc('phases'))
|
|
|
|
part.addparam('key', enc(newremotehead.hex()))
|
2017-08-23 04:21:13 +03:00
|
|
|
part.addparam('old', enc('%d' % phases.draft))
|
|
|
|
part.addparam('new', enc('%d' % phases.public))
|
2014-07-02 01:08:17 +04:00
|
|
|
part2node.append((part.id, newremotehead))
|
2015-05-28 08:25:51 +03:00
|
|
|
pushop.pkfailcb[part.id] = handlefailure
|
|
|
|
|
2014-07-02 01:08:17 +04:00
|
|
|
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
|
2014-07-02 17:26:04 +04:00
|
|
|
|
2014-08-25 21:44:27 +04:00
|
|
|
@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:
|
2015-05-10 16:48:08 +03:00
|
|
|
markers = sorted(pushop.outobsmarkers)
|
2017-05-28 21:48:18 +03:00
|
|
|
bundle2.buildobsmarkerspart(bundler, markers)
|
2014-08-25 21:44:27 +04:00
|
|
|
|
2014-08-16 06:03:42 +04:00
|
|
|
@b2partsgenerator('bookmarks')
|
|
|
|
def _pushb2bookmarks(pushop, bundler):
|
2015-07-20 23:35:19 +03:00
|
|
|
"""handle bookmark push through bundle2"""
|
2014-08-16 06:03:42 +04:00
|
|
|
if 'bookmarks' in pushop.stepsdone:
|
|
|
|
return
|
|
|
|
b2caps = bundle2.bundle2caps(pushop.remote)
|
2017-10-17 13:38:13 +03:00
|
|
|
|
|
|
|
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:
|
2017-10-15 20:22:56 +03:00
|
|
|
return _pushb2bookmarkspushkey(pushop, bundler)
|
|
|
|
|
2017-10-17 13:38:13 +03:00
|
|
|
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
|
|
|
|
|
2017-10-15 20:22:56 +03:00
|
|
|
def _pushb2bookmarkspushkey(pushop, bundler):
|
2014-08-16 06:03:42 +04:00
|
|
|
pushop.stepsdone.add('bookmarks')
|
|
|
|
part2book = []
|
|
|
|
enc = pushkey.encode
|
2015-05-28 08:25:33 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-08-16 06:03:42 +04:00
|
|
|
for book, old, new in pushop.outbookmarks:
|
2015-05-28 08:25:33 +03:00
|
|
|
part = bundler.newpart('pushkey')
|
2014-08-16 06:03:42 +04:00
|
|
|
part.addparam('namespace', enc('bookmarks'))
|
|
|
|
part.addparam('key', enc(book))
|
|
|
|
part.addparam('old', enc(old))
|
|
|
|
part.addparam('new', enc(new))
|
2014-09-27 05:33:11 +04:00
|
|
|
action = 'update'
|
|
|
|
if not old:
|
|
|
|
action = 'export'
|
|
|
|
elif not new:
|
|
|
|
action = 'delete'
|
|
|
|
part2book.append((part.id, book, action))
|
2015-05-28 08:25:33 +03:00
|
|
|
pushop.pkfailcb[part.id] = handlefailure
|
2014-09-27 05:33:11 +04:00
|
|
|
|
2014-08-16 06:03:42 +04:00
|
|
|
def handlereply(op):
|
2014-09-27 05:33:11 +04:00
|
|
|
ui = pushop.ui
|
|
|
|
for partid, book, action in part2book:
|
2014-08-16 06:03:42 +04:00
|
|
|
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:
|
2014-09-27 05:33:11 +04:00
|
|
|
ui.status(bookmsgmap[action][0] % book)
|
2014-08-16 06:03:42 +04:00
|
|
|
else:
|
2014-09-27 05:33:11 +04:00
|
|
|
ui.warn(bookmsgmap[action][1] % book)
|
2014-10-02 22:19:49 +04:00
|
|
|
if pushop.bkresult is not None:
|
|
|
|
pushop.bkresult = 1
|
2014-08-16 06:03:42 +04:00
|
|
|
return handlereply
|
|
|
|
|
2017-07-31 07:29:42 +03:00
|
|
|
@b2partsgenerator('pushvars', idx=0)
|
|
|
|
def _getbundlesendvars(pushop, bundler):
|
|
|
|
'''send shellvars via bundle2'''
|
2017-08-17 01:48:48 +03:00
|
|
|
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
|
|
|
|
|
2017-07-31 07:29:42 +03:00
|
|
|
part = bundler.newpart('pushvars')
|
|
|
|
|
2017-08-17 01:48:48 +03:00
|
|
|
for key, value in shellvars.iteritems():
|
2017-07-31 07:29:42 +03:00
|
|
|
part.addparam(key, value, mandatory=False)
|
2014-08-16 06:03:42 +04:00
|
|
|
|
2014-04-10 21:53:43 +04:00
|
|
|
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."""
|
2014-05-25 03:20:09 +04:00
|
|
|
bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
|
2014-11-22 02:50:38 +03:00
|
|
|
pushback = (pushop.trmanager
|
|
|
|
and pushop.ui.configbool('experimental', 'bundle2.pushback'))
|
|
|
|
|
2014-04-17 22:37:24 +04:00
|
|
|
# create reply capability
|
2014-11-22 02:50:38 +03:00
|
|
|
capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo,
|
|
|
|
allowpushback=pushback))
|
2015-04-09 23:25:48 +03:00
|
|
|
bundler.newpart('replycaps', data=capsblob)
|
2014-07-02 17:26:04 +04:00
|
|
|
replyhandlers = []
|
2014-07-31 06:04:50 +04:00
|
|
|
for partgenname in b2partsgenorder:
|
|
|
|
partgen = b2partsgenmapping[partgenname]
|
2014-07-02 17:26:04 +04:00
|
|
|
ret = partgen(pushop, bundler)
|
2014-07-02 18:13:48 +04:00
|
|
|
if callable(ret):
|
|
|
|
replyhandlers.append(ret)
|
2014-07-02 17:26:04 +04:00
|
|
|
# do not push if nothing to push
|
2014-07-02 14:55:09 +04:00
|
|
|
if bundler.nbparts <= 1:
|
|
|
|
return
|
2014-04-10 21:53:43 +04:00
|
|
|
stream = util.chunkbuffer(bundler.getchunks())
|
2014-04-22 22:41:34 +04:00
|
|
|
try:
|
2015-06-06 02:30:11 +03:00
|
|
|
try:
|
2016-08-05 23:25:15 +03:00
|
|
|
reply = pushop.remote.unbundle(
|
|
|
|
stream, ['force'], pushop.remote.url())
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.BundleValueError as exc:
|
2016-06-14 12:53:55 +03:00
|
|
|
raise error.Abort(_('missing support for %s') % exc)
|
2015-06-06 02:30:11 +03:00
|
|
|
try:
|
|
|
|
trgetter = None
|
|
|
|
if pushback:
|
|
|
|
trgetter = pushop.trmanager.transaction
|
|
|
|
op = bundle2.processbundle(pushop.repo, reply, trgetter)
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.BundleValueError as exc:
|
2016-06-14 12:53:55 +03:00
|
|
|
raise error.Abort(_('missing support for %s') % exc)
|
2015-10-24 02:39:22 +03:00
|
|
|
except bundle2.AbortFromPart as exc:
|
|
|
|
pushop.ui.status(_('remote: %s\n') % exc)
|
2017-02-10 19:56:47 +03:00
|
|
|
if exc.hint is not None:
|
|
|
|
pushop.ui.status(_('remote: %s\n') % ('(%s)' % exc.hint))
|
|
|
|
raise error.Abort(_('push failed on remote'))
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.PushkeyFailed as exc:
|
2015-06-06 02:30:11 +03:00
|
|
|
partid = int(exc.partid)
|
|
|
|
if partid not in pushop.pkfailcb:
|
|
|
|
raise
|
|
|
|
pushop.pkfailcb[partid](pushop, exc)
|
2014-07-02 17:26:04 +04:00
|
|
|
for rephand in replyhandlers:
|
|
|
|
rephand(op)
|
2014-04-10 21:53:43 +04:00
|
|
|
|
2014-01-31 08:44:55 +04:00
|
|
|
def _pushchangeset(pushop):
|
|
|
|
"""Make the actual push of changeset bundle to remote repo"""
|
2014-07-07 14:30:31 +04:00
|
|
|
if 'changesets' in pushop.stepsdone:
|
|
|
|
return
|
|
|
|
pushop.stepsdone.add('changesets')
|
2014-07-02 14:55:09 +04:00
|
|
|
if not _pushcheckoutgoing(pushop):
|
|
|
|
return
|
2017-08-07 03:44:56 +03:00
|
|
|
|
|
|
|
# Should have verified this in push().
|
|
|
|
assert pushop.remote.capable('unbundle')
|
|
|
|
|
2016-04-13 02:09:11 +03:00
|
|
|
pushop.repo.prepushoutgoinghooks(pushop)
|
2014-01-31 08:44:55 +04:00
|
|
|
outgoing = pushop.outgoing
|
2017-05-15 19:35:27 +03:00
|
|
|
# TODO: get bundlecaps from remote
|
|
|
|
bundlecaps = None
|
2014-01-31 08:44:55 +04:00
|
|
|
# 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
|
2017-09-11 04:39:02 +03:00
|
|
|
cg = changegroup.makechangegroup(pushop.repo, outgoing, '01', 'push',
|
|
|
|
fastpath=True, bundlecaps=bundlecaps)
|
2014-01-31 08:44:55 +04:00
|
|
|
else:
|
2017-09-11 04:50:12 +03:00
|
|
|
cg = changegroup.makechangegroup(pushop.repo, outgoing, '01',
|
|
|
|
'push', bundlecaps=bundlecaps)
|
2014-01-31 08:44:55 +04:00
|
|
|
|
|
|
|
# apply changegroup to remote
|
2017-08-07 03:44:56 +03:00
|
|
|
# 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']
|
2014-01-31 08:44:55 +04:00
|
|
|
else:
|
2017-08-07 03:44:56 +03:00
|
|
|
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())
|
2014-01-31 08:44:55 +04:00
|
|
|
|
2014-01-31 08:22:43 +04:00
|
|
|
def _pushsyncphase(pushop):
|
2014-04-13 21:01:00 +04:00
|
|
|
"""synchronise phase information locally and remotely"""
|
2014-01-31 11:12:03 +04:00
|
|
|
cheads = pushop.commonheads
|
2014-01-31 08:22:43 +04:00
|
|
|
# even when we don't push, exchanging phase data is useful
|
|
|
|
remotephases = pushop.remote.listkeys('phases')
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
if (pushop.ui.configbool('ui', '_usedassubrepo')
|
2014-01-31 08:22:43 +04:00
|
|
|
and remotephases # server supports phases
|
2014-09-25 11:55:39 +04:00
|
|
|
and pushop.cgresult is None # nothing was pushed
|
2014-01-31 08:22:43 +04:00
|
|
|
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'}
|
2014-04-13 20:21:09 +04:00
|
|
|
if not remotephases: # old server or public only reply from non-publishing
|
2014-01-31 08:22:43 +04:00
|
|
|
_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
|
|
|
|
|
2014-09-25 11:55:39 +04:00
|
|
|
if pushop.cgresult:
|
2014-07-02 01:08:17 +04:00
|
|
|
if 'phases' in pushop.stepsdone:
|
|
|
|
# phases already pushed though bundle2
|
|
|
|
return
|
2014-07-31 06:26:47 +04:00
|
|
|
outdated = pushop.outdatedphases
|
|
|
|
else:
|
|
|
|
outdated = pushop.fallbackoutdatedphases
|
|
|
|
|
2014-07-02 01:08:17 +04:00
|
|
|
pushop.stepsdone.add('phases')
|
|
|
|
|
2014-07-31 06:26:47 +04:00
|
|
|
# filter heads already turned public by the push
|
|
|
|
outdated = [c for c in outdated if c.node() not in pheads]
|
2014-11-19 04:36:17 +03:00
|
|
|
# fallback to independent pushkey command
|
|
|
|
for newremotehead in outdated:
|
|
|
|
r = pushop.remote.pushkey('phases',
|
|
|
|
newremotehead.hex(),
|
|
|
|
str(phases.draft),
|
|
|
|
str(phases.public))
|
|
|
|
if not r:
|
|
|
|
pushop.ui.warn(_('updating %s to public failed!\n')
|
|
|
|
% newremotehead)
|
2014-01-31 08:22:43 +04:00
|
|
|
|
2014-01-31 08:10:59 +04:00
|
|
|
def _localphasemove(pushop, nodes, phase=phases.public):
|
|
|
|
"""move <nodes> to <phase> in the local source repo"""
|
2014-11-22 02:06:38 +03:00
|
|
|
if pushop.trmanager:
|
|
|
|
phases.advanceboundary(pushop.repo,
|
|
|
|
pushop.trmanager.transaction(),
|
|
|
|
phase,
|
|
|
|
nodes)
|
2014-01-31 08:10:59 +04:00
|
|
|
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)
|
|
|
|
|
2014-01-31 05:56:09 +04:00
|
|
|
def _pushobsolete(pushop):
|
2014-01-31 07:51:21 +04:00
|
|
|
"""utility function to push obsolete markers to a remote"""
|
2014-08-01 00:51:17 +04:00
|
|
|
if 'obsmarkers' in pushop.stepsdone:
|
|
|
|
return
|
2014-01-31 05:56:09 +04:00
|
|
|
repo = pushop.repo
|
|
|
|
remote = pushop.remote
|
2014-08-01 00:51:17 +04:00
|
|
|
pushop.stepsdone.add('obsmarkers')
|
2014-08-20 12:15:09 +04:00
|
|
|
if pushop.outobsmarkers:
|
2015-06-11 23:02:21 +03:00
|
|
|
pushop.ui.debug('try to push obsolete markers to remote\n')
|
2014-01-31 05:54:47 +04:00
|
|
|
rslts = []
|
2015-05-10 16:48:08 +03:00
|
|
|
remotedata = obsolete._pushkeyescape(sorted(pushop.outobsmarkers))
|
2014-01-31 05:54:47 +04:00
|
|
|
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)
|
|
|
|
|
2014-01-31 05:51:41 +04:00
|
|
|
def _pushbookmark(pushop):
|
2014-01-31 05:46:51 +04:00
|
|
|
"""Update bookmark position on remote"""
|
2014-09-25 11:55:39 +04:00
|
|
|
if pushop.cgresult == 0 or 'bookmarks' in pushop.stepsdone:
|
2014-08-16 05:26:21 +04:00
|
|
|
return
|
2014-08-16 05:40:57 +04:00
|
|
|
pushop.stepsdone.add('bookmarks')
|
2014-01-31 05:51:41 +04:00
|
|
|
ui = pushop.ui
|
|
|
|
remote = pushop.remote
|
2014-09-27 05:33:11 +04:00
|
|
|
|
2014-08-16 05:39:39 +04:00
|
|
|
for b, old, new in pushop.outbookmarks:
|
2014-09-27 05:33:11 +04:00
|
|
|
action = 'update'
|
|
|
|
if not old:
|
|
|
|
action = 'export'
|
|
|
|
elif not new:
|
|
|
|
action = 'delete'
|
2014-08-16 05:39:39 +04:00
|
|
|
if remote.pushkey('bookmarks', b, old, new):
|
2014-09-27 05:33:11 +04:00
|
|
|
ui.status(bookmsgmap[action][0] % b)
|
2014-01-31 05:46:51 +04:00
|
|
|
else:
|
2014-09-27 05:33:11 +04:00
|
|
|
ui.warn(bookmsgmap[action][1] % b)
|
|
|
|
# discovery can have set the value form invalid entry
|
|
|
|
if pushop.bkresult is not None:
|
|
|
|
pushop.bkresult = 1
|
2014-01-31 04:12:49 +04:00
|
|
|
|
2014-01-31 05:24:49 +04:00
|
|
|
class pulloperation(object):
|
|
|
|
"""A object that represent a single pull operation
|
|
|
|
|
2014-10-24 23:58:46 +04:00
|
|
|
It purpose is to carry pull related state and very common operation.
|
2014-01-31 05:24:49 +04:00
|
|
|
|
2014-04-13 21:01:00 +04:00
|
|
|
A new should be created at the beginning of each pull and discarded
|
2014-01-31 05:24:49 +04:00
|
|
|
afterward.
|
|
|
|
"""
|
|
|
|
|
2015-06-02 08:34:01 +03:00
|
|
|
def __init__(self, repo, remote, heads=None, force=False, bookmarks=(),
|
2015-10-03 08:16:34 +03:00
|
|
|
remotebookmarks=None, streamclonerequested=None):
|
2014-02-28 07:56:36 +04:00
|
|
|
# repo we pull into
|
2014-01-31 05:24:49 +04:00
|
|
|
self.repo = repo
|
2014-02-28 07:56:36 +04:00
|
|
|
# repo we pull from
|
2014-01-31 05:32:04 +04:00
|
|
|
self.remote = remote
|
2014-01-31 05:35:55 +04:00
|
|
|
# revision we try to pull (None is "all")
|
|
|
|
self.heads = heads
|
2014-09-27 12:31:15 +04:00
|
|
|
# bookmark pulled explicitly
|
2016-06-01 23:58:57 +03:00
|
|
|
self.explicitbookmarks = [repo._bookmarks.expandname(bookmark)
|
|
|
|
for bookmark in bookmarks]
|
2014-02-01 15:49:29 +04:00
|
|
|
# do we force pull?
|
|
|
|
self.force = force
|
2015-10-03 08:16:34 +03:00
|
|
|
# whether a streaming clone was requested
|
|
|
|
self.streamclonerequested = streamclonerequested
|
2014-11-22 01:32:57 +03:00
|
|
|
# transaction manager
|
|
|
|
self.trmanager = None
|
2014-01-31 13:34:00 +04:00
|
|
|
# set of common changeset between local and remote before pull
|
|
|
|
self.common = None
|
|
|
|
# set of pulled head
|
|
|
|
self.rheads = None
|
2014-04-13 21:01:00 +04:00
|
|
|
# list of missing changeset to fetch remotely
|
2014-02-12 02:51:38 +04:00
|
|
|
self.fetch = None
|
2014-09-27 12:31:15 +04:00
|
|
|
# remote bookmarks data
|
2015-06-02 08:34:01 +03:00
|
|
|
self.remotebookmarks = remotebookmarks
|
2014-04-13 21:01:00 +04:00
|
|
|
# result of changegroup pulling (used as return code by pull)
|
2014-04-02 04:21:52 +04:00
|
|
|
self.cgresult = None
|
2014-10-12 17:40:36 +04:00
|
|
|
# list of step already done
|
|
|
|
self.stepsdone = set()
|
2015-10-14 00:55:02 +03:00
|
|
|
# Whether we attempted a clone from pre-generated bundles.
|
|
|
|
self.clonebundleattempted = False
|
2014-01-31 13:34:00 +04:00
|
|
|
|
|
|
|
@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
|
2014-03-27 02:55:32 +04:00
|
|
|
c = set(self.common)
|
|
|
|
ret = list(self.common)
|
|
|
|
for n in self.rheads:
|
|
|
|
if n not in c:
|
|
|
|
ret.append(n)
|
|
|
|
return ret
|
2014-01-31 13:34:00 +04:00
|
|
|
else:
|
|
|
|
# We pulled a specific subset
|
|
|
|
# sync on this subset
|
|
|
|
return self.heads
|
2014-01-31 13:04:05 +04:00
|
|
|
|
2015-10-04 22:03:30 +03:00
|
|
|
@util.propertycache
|
|
|
|
def canusebundle2(self):
|
2016-08-03 16:01:23 +03:00
|
|
|
return not _forcebundle1(self)
|
2015-10-04 22:03:30 +03:00
|
|
|
|
2015-10-05 04:31:53 +03:00
|
|
|
@util.propertycache
|
|
|
|
def remotebundle2caps(self):
|
|
|
|
return bundle2.bundle2caps(self.remote)
|
|
|
|
|
2014-01-31 13:04:05 +04:00
|
|
|
def gettransaction(self):
|
2014-11-22 01:32:57 +03:00
|
|
|
# deprecated; talk to trmanager directly
|
|
|
|
return self.trmanager.transaction()
|
|
|
|
|
2017-07-29 08:42:10 +03:00
|
|
|
class transactionmanager(util.transactional):
|
2014-04-18 00:47:38 +04:00
|
|
|
"""An object to manage the life cycle of a transaction
|
2014-11-22 01:32:57 +03:00
|
|
|
|
|
|
|
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
|
2014-01-31 13:04:05 +04:00
|
|
|
return self._tr
|
|
|
|
|
2014-11-22 01:32:57 +03:00
|
|
|
def close(self):
|
2014-01-31 13:04:05 +04:00
|
|
|
"""close transaction if created"""
|
|
|
|
if self._tr is not None:
|
2014-10-28 16:58:36 +03:00
|
|
|
self._tr.close()
|
2014-01-31 13:04:05 +04:00
|
|
|
|
2014-11-22 01:32:57 +03:00
|
|
|
def release(self):
|
2014-01-31 13:04:05 +04:00
|
|
|
"""release transaction if created"""
|
|
|
|
if self._tr is not None:
|
|
|
|
self._tr.release()
|
2014-01-31 04:12:49 +04:00
|
|
|
|
2015-10-03 08:16:34 +03:00
|
|
|
def pull(repo, remote, heads=None, force=False, bookmarks=(), opargs=None,
|
|
|
|
streamclonerequested=None):
|
2015-10-03 01:36:00 +03:00
|
|
|
"""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.
|
2015-10-03 08:16:34 +03:00
|
|
|
``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.
|
2015-10-03 01:36:00 +03:00
|
|
|
|
|
|
|
Returns the ``pulloperation`` created for this pull.
|
|
|
|
"""
|
2015-06-02 10:43:11 +03:00
|
|
|
if opargs is None:
|
|
|
|
opargs = {}
|
|
|
|
pullop = pulloperation(repo, remote, heads, force, bookmarks=bookmarks,
|
2017-12-10 02:16:25 +03:00
|
|
|
streamclonerequested=streamclonerequested,
|
|
|
|
**pycompat.strkwargs(opargs))
|
2017-08-06 01:15:20 +03:00
|
|
|
|
|
|
|
peerlocal = pullop.remote.local()
|
|
|
|
if peerlocal:
|
|
|
|
missing = set(peerlocal.requirements) - pullop.repo.supported
|
2014-01-31 04:12:49 +04:00
|
|
|
if missing:
|
|
|
|
msg = _("required features are not"
|
|
|
|
" supported in the destination:"
|
|
|
|
" %s") % (', '.join(sorted(missing)))
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
2014-01-31 04:12:49 +04:00
|
|
|
|
2016-08-24 00:47:59 +03:00
|
|
|
wlock = lock = None
|
2014-01-31 04:12:49 +04:00
|
|
|
try:
|
2016-08-24 00:47:59 +03:00
|
|
|
wlock = pullop.repo.wlock()
|
|
|
|
lock = pullop.repo.lock()
|
2014-11-22 01:32:57 +03:00
|
|
|
pullop.trmanager = transactionmanager(repo, 'pull', remote.url())
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
# This should ideally be in _pullbundle2(). However, it needs to run
|
|
|
|
# before discovery to avoid extra work.
|
|
|
|
_maybeapplyclonebundle(pullop)
|
2017-09-28 17:24:54 +03:00
|
|
|
streamclone.maybeperformlegacystreamclone(pullop)
|
2014-04-02 04:35:25 +04:00
|
|
|
_pulldiscovery(pullop)
|
2015-10-04 22:03:30 +03:00
|
|
|
if pullop.canusebundle2:
|
2014-04-02 10:41:32 +04:00
|
|
|
_pullbundle2(pullop)
|
2014-09-27 12:34:02 +04:00
|
|
|
_pullchangeset(pullop)
|
|
|
|
_pullphase(pullop)
|
2014-09-27 12:31:15 +04:00
|
|
|
_pullbookmarks(pullop)
|
2014-09-27 12:37:56 +04:00
|
|
|
_pullobsolete(pullop)
|
2014-11-22 01:32:57 +03:00
|
|
|
pullop.trmanager.close()
|
2014-01-31 04:12:49 +04:00
|
|
|
finally:
|
2016-08-24 00:47:59 +03:00
|
|
|
lockmod.release(pullop.trmanager, lock, wlock)
|
2014-01-31 04:12:49 +04:00
|
|
|
|
2017-10-04 21:32:02 +03:00
|
|
|
# storing remotenames
|
|
|
|
if repo.ui.configbool('experimental', 'remotenames'):
|
2017-12-06 21:56:45 +03:00
|
|
|
logexchange.pullremotenames(repo, remote)
|
2017-10-04 21:32:02 +03:00
|
|
|
|
2014-10-03 20:07:47 +04:00
|
|
|
return pullop
|
2014-01-31 05:38:41 +04:00
|
|
|
|
2014-09-27 11:29:06 +04:00
|
|
|
# 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
|
|
|
|
|
2014-04-02 04:35:25 +04:00
|
|
|
def _pulldiscovery(pullop):
|
2014-09-27 11:29:06 +04:00
|
|
|
"""Run all discovery steps"""
|
|
|
|
for stepname in pulldiscoveryorder:
|
|
|
|
step = pulldiscoverymapping[stepname]
|
|
|
|
step(pullop)
|
|
|
|
|
2015-05-27 14:57:03 +03:00
|
|
|
@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."""
|
2015-06-02 08:28:03 +03:00
|
|
|
if pullop.remotebookmarks is not None:
|
|
|
|
return
|
2015-10-04 22:03:30 +03:00
|
|
|
if pullop.canusebundle2 and 'listkeys' in pullop.remotebundle2caps:
|
2015-06-08 23:32:38 +03:00
|
|
|
# all known bundle2 servers now support listkeys, but lets be nice with
|
|
|
|
# new implementation.
|
|
|
|
return
|
2017-10-17 12:01:45 +03:00
|
|
|
books = pullop.remote.listkeys('bookmarks')
|
|
|
|
pullop.remotebookmarks = bookmod.unhexlifybookmarks(books)
|
2015-05-27 14:57:03 +03:00
|
|
|
|
2014-09-27 11:29:06 +04:00
|
|
|
@pulldiscovery('changegroup')
|
|
|
|
def _pulldiscoverychangegroup(pullop):
|
2014-04-02 04:35:25 +04:00
|
|
|
"""discovery phase for the pull
|
|
|
|
|
|
|
|
Current handle changeset discovery only, will change handle all discovery
|
|
|
|
at some point."""
|
2015-01-07 11:07:29 +03:00
|
|
|
tmp = discovery.findcommonincoming(pullop.repo,
|
2014-04-02 04:35:25 +04:00
|
|
|
pullop.remote,
|
|
|
|
heads=pullop.heads,
|
|
|
|
force=pullop.force)
|
2015-01-07 11:07:29 +03:00
|
|
|
common, fetch, rheads = tmp
|
|
|
|
nm = pullop.repo.unfiltered().changelog.nodemap
|
|
|
|
if fetch and rheads:
|
2017-09-20 06:47:33 +03:00
|
|
|
# If a remote heads is filtered locally, put in back in common.
|
2015-01-07 11:07:29 +03:00
|
|
|
#
|
|
|
|
# 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:
|
2015-01-31 00:11:02 +03:00
|
|
|
if n in nm:
|
|
|
|
if n not in scommon:
|
|
|
|
common.append(n)
|
2017-09-20 06:47:33 +03:00
|
|
|
if set(rheads).issubset(set(common)):
|
2015-01-07 11:07:29 +03:00
|
|
|
fetch = []
|
|
|
|
pullop.common = common
|
|
|
|
pullop.fetch = fetch
|
|
|
|
pullop.rheads = rheads
|
2014-04-02 04:35:25 +04:00
|
|
|
|
2014-04-02 10:41:32 +04:00
|
|
|
def _pullbundle2(pullop):
|
|
|
|
"""pull data using bundle2
|
|
|
|
|
|
|
|
For now, the only supported data are changegroup."""
|
2014-05-23 00:31:33 +04:00
|
|
|
kwargs = {'bundlecaps': caps20to10(pullop.repo)}
|
2015-10-04 22:11:44 +03:00
|
|
|
|
2017-05-09 03:30:51 +03:00
|
|
|
# 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.
|
|
|
|
streaming = False
|
2015-10-04 22:11:44 +03:00
|
|
|
|
2014-04-02 10:41:32 +04:00
|
|
|
# pulling changegroup
|
2014-10-12 17:40:36 +04:00
|
|
|
pullop.stepsdone.add('changegroup')
|
2014-05-08 04:24:19 +04:00
|
|
|
|
|
|
|
kwargs['common'] = pullop.common
|
|
|
|
kwargs['heads'] = pullop.heads or pullop.rheads
|
2014-08-29 14:28:58 +04:00
|
|
|
kwargs['cg'] = pullop.fetch
|
2017-09-24 22:27:18 +03:00
|
|
|
|
|
|
|
ui = pullop.repo.ui
|
|
|
|
legacyphase = 'phases' in ui.configlist('devel', 'legacy.exchange')
|
2017-09-30 12:09:29 +03:00
|
|
|
hasbinaryphase = 'heads' in pullop.remotebundle2caps.get('phases', ())
|
|
|
|
if (not legacyphase and hasbinaryphase):
|
2017-09-24 22:27:18 +03:00
|
|
|
kwargs['phases'] = True
|
|
|
|
pullop.stepsdone.add('phases')
|
|
|
|
|
2017-10-17 16:27:22 +03:00
|
|
|
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
|
|
|
|
|
2015-10-05 04:31:53 +03:00
|
|
|
if 'listkeys' in pullop.remotebundle2caps:
|
2017-09-24 22:27:18 +03:00
|
|
|
if 'phases' not in pullop.stepsdone:
|
|
|
|
kwargs['listkeys'] = ['phases']
|
2017-10-17 16:27:22 +03:00
|
|
|
if 'request-bookmarks' not in pullop.stepsdone:
|
2015-06-02 08:29:49 +03:00
|
|
|
# make sure to always includes bookmark data when migrating
|
|
|
|
# `hg incoming --bundle` to using this function.
|
2017-10-17 16:27:22 +03:00
|
|
|
pullop.stepsdone.add('request-bookmarks')
|
2017-09-24 22:27:18 +03:00
|
|
|
kwargs.setdefault('listkeys', []).append('bookmarks')
|
2015-10-14 20:36:20 +03:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2015-10-04 22:11:44 +03:00
|
|
|
if streaming:
|
|
|
|
pullop.repo.ui.status(_('streaming all changes\n'))
|
|
|
|
elif not pullop.fetch:
|
2014-05-08 06:26:15 +04:00
|
|
|
pullop.repo.ui.status(_("no changes found\n"))
|
|
|
|
pullop.cgresult = 0
|
2014-04-02 10:41:32 +04:00
|
|
|
else:
|
|
|
|
if pullop.heads is None and list(pullop.common) == [nullid]:
|
|
|
|
pullop.repo.ui.status(_("requesting all changes\n"))
|
2014-10-15 00:26:01 +04:00
|
|
|
if obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
|
2015-10-05 04:31:53 +03:00
|
|
|
remoteversions = bundle2.obsmarkersversion(pullop.remotebundle2caps)
|
2014-08-26 14:47:41 +04:00
|
|
|
if obsolete.commonversion(remoteversions) is not None:
|
|
|
|
kwargs['obsmarkers'] = True
|
2014-10-12 17:40:36 +04:00
|
|
|
pullop.stepsdone.add('obsmarkers')
|
2014-04-18 00:56:15 +04:00
|
|
|
_pullbundle2extraprepare(pullop, kwargs)
|
2017-06-17 12:35:11 +03:00
|
|
|
bundle = pullop.remote.getbundle('pull', **pycompat.strkwargs(kwargs))
|
2014-04-02 10:41:32 +04:00
|
|
|
try:
|
2017-10-17 16:27:22 +03:00
|
|
|
op = bundle2.bundleoperation(pullop.repo, pullop.gettransaction)
|
|
|
|
op.modes['bookmarks'] = 'records'
|
|
|
|
bundle2.processbundle(pullop.repo, bundle, op=op)
|
2017-02-10 20:17:20 +03:00
|
|
|
except bundle2.AbortFromPart as exc:
|
|
|
|
pullop.repo.ui.status(_('remote: abort: %s\n') % exc)
|
|
|
|
raise error.Abort(_('pull failed on remote'), hint=exc.hint)
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.BundleValueError as exc:
|
2016-06-14 12:53:55 +03:00
|
|
|
raise error.Abort(_('missing support for %s') % exc)
|
2014-05-08 04:24:19 +04:00
|
|
|
|
|
|
|
if pullop.fetch:
|
2017-06-23 00:04:13 +03:00
|
|
|
pullop.cgresult = bundle2.combinechangegroupresults(op)
|
2014-04-02 10:41:32 +04:00
|
|
|
|
2014-05-28 02:44:46 +04:00
|
|
|
# processing phases change
|
|
|
|
for namespace, value in op.records['listkeys']:
|
|
|
|
if namespace == 'phases':
|
|
|
|
_pullapplyphases(pullop, value)
|
|
|
|
|
2014-09-27 12:59:56 +04:00
|
|
|
# processing bookmark update
|
2017-10-17 16:27:22 +03:00
|
|
|
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)
|
2015-06-02 08:29:49 +03:00
|
|
|
|
|
|
|
# bookmark data were either already there or pulled in the bundle
|
|
|
|
if pullop.remotebookmarks is not None:
|
|
|
|
_pullbookmarks(pullop)
|
2014-09-27 12:59:56 +04:00
|
|
|
|
2014-04-18 00:56:15 +04:00
|
|
|
def _pullbundle2extraprepare(pullop, kwargs):
|
|
|
|
"""hook function so that extensions can extend the getbundle call"""
|
|
|
|
|
2014-01-31 13:39:59 +04:00
|
|
|
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
|
2014-10-12 17:40:36 +04:00
|
|
|
if 'changegroup' in pullop.stepsdone:
|
2014-09-27 12:34:02 +04:00
|
|
|
return
|
2014-10-12 17:40:36 +04:00
|
|
|
pullop.stepsdone.add('changegroup')
|
2014-04-02 04:28:21 +04:00
|
|
|
if not pullop.fetch:
|
2014-10-25 08:40:51 +04:00
|
|
|
pullop.repo.ui.status(_("no changes found\n"))
|
|
|
|
pullop.cgresult = 0
|
|
|
|
return
|
2017-06-16 08:46:38 +03:00
|
|
|
tr = pullop.gettransaction()
|
2014-01-31 13:39:59 +04:00
|
|
|
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:
|
|
|
|
cg = pullop.remote.changegroup(pullop.fetch, 'pull')
|
|
|
|
elif not pullop.remote.capable('changegroupsubset'):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("partial pull cannot be done because "
|
2014-05-23 00:39:55 +04:00
|
|
|
"other repository doesn't support "
|
|
|
|
"changegroupsubset."))
|
2014-01-31 13:39:59 +04:00
|
|
|
else:
|
|
|
|
cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
|
2017-06-23 01:00:19 +03:00
|
|
|
bundleop = bundle2.applybundle(pullop.repo, cg, tr, 'pull',
|
|
|
|
pullop.remote.url())
|
2017-06-22 07:08:48 +03:00
|
|
|
pullop.cgresult = bundle2.combinechangegroupresults(bundleop)
|
2014-01-31 13:39:59 +04:00
|
|
|
|
2014-01-31 13:25:56 +04:00
|
|
|
def _pullphase(pullop):
|
|
|
|
# Get remote phases data from remote
|
2014-10-12 17:40:36 +04:00
|
|
|
if 'phases' in pullop.stepsdone:
|
2014-09-27 12:34:02 +04:00
|
|
|
return
|
2014-01-31 13:25:56 +04:00
|
|
|
remotephases = pullop.remote.listkeys('phases')
|
2014-05-28 02:29:08 +04:00
|
|
|
_pullapplyphases(pullop, remotephases)
|
|
|
|
|
|
|
|
def _pullapplyphases(pullop, remotephases):
|
|
|
|
"""apply phase movement from observed remote state"""
|
2014-10-12 17:40:36 +04:00
|
|
|
if 'phases' in pullop.stepsdone:
|
|
|
|
return
|
|
|
|
pullop.stepsdone.add('phases')
|
2014-01-31 13:25:56 +04:00
|
|
|
publishing = bool(remotephases.get('publishing', False))
|
|
|
|
if remotephases and not publishing:
|
2016-10-18 00:16:55 +03:00
|
|
|
# remote is new and non-publishing
|
2014-01-31 13:25:56 +04:00
|
|
|
pheads, _dr = phases.analyzeremotephases(pullop.repo,
|
|
|
|
pullop.pulledsubset,
|
|
|
|
remotephases)
|
2014-08-06 11:54:37 +04:00
|
|
|
dheads = pullop.pulledsubset
|
2014-01-31 13:25:56 +04:00
|
|
|
else:
|
|
|
|
# Remote is old or publishing all common changesets
|
|
|
|
# should be seen as public
|
2014-08-06 11:54:37 +04:00
|
|
|
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:
|
2014-08-06 12:54:19 +04:00
|
|
|
tr = pullop.gettransaction()
|
|
|
|
phases.advanceboundary(pullop.repo, tr, public, pheads)
|
2014-08-06 11:54:37 +04:00
|
|
|
|
|
|
|
# exclude changesets already draft locally and update the others
|
|
|
|
dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft]
|
|
|
|
if dheads:
|
2014-08-06 12:54:19 +04:00
|
|
|
tr = pullop.gettransaction()
|
|
|
|
phases.advanceboundary(pullop.repo, tr, draft, dheads)
|
2014-01-31 13:25:56 +04:00
|
|
|
|
2014-09-27 12:31:15 +04:00
|
|
|
def _pullbookmarks(pullop):
|
|
|
|
"""process the remote bookmark information to update the local one"""
|
2014-10-12 17:40:36 +04:00
|
|
|
if 'bookmarks' in pullop.stepsdone:
|
2014-09-27 12:31:15 +04:00
|
|
|
return
|
2014-10-12 17:40:36 +04:00
|
|
|
pullop.stepsdone.add('bookmarks')
|
2014-09-27 12:31:15 +04:00
|
|
|
repo = pullop.repo
|
|
|
|
remotebookmarks = pullop.remotebookmarks
|
|
|
|
bookmod.updatefromremote(repo.ui, repo, remotebookmarks,
|
2014-09-29 00:43:31 +04:00
|
|
|
pullop.remote.url(),
|
2014-09-29 02:21:38 +04:00
|
|
|
pullop.gettransaction,
|
2014-09-29 00:43:31 +04:00
|
|
|
explicit=pullop.explicitbookmarks)
|
2014-09-27 12:31:15 +04:00
|
|
|
|
2014-01-31 13:12:35 +04:00
|
|
|
def _pullobsolete(pullop):
|
2014-01-31 05:38:41 +04:00
|
|
|
"""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"""
|
2014-10-12 17:40:36 +04:00
|
|
|
if 'obsmarkers' in pullop.stepsdone:
|
2014-09-27 12:34:02 +04:00
|
|
|
return
|
2014-10-12 17:40:36 +04:00
|
|
|
pullop.stepsdone.add('obsmarkers')
|
2014-01-31 05:38:41 +04:00
|
|
|
tr = None
|
2014-10-15 00:26:01 +04:00
|
|
|
if obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
|
2014-01-31 13:12:35 +04:00
|
|
|
pullop.repo.ui.debug('fetching remote obsolete markers\n')
|
|
|
|
remoteobs = pullop.remote.listkeys('obsolete')
|
2014-01-31 05:38:41 +04:00
|
|
|
if 'dump0' in remoteobs:
|
2014-01-31 13:12:35 +04:00
|
|
|
tr = pullop.gettransaction()
|
2015-12-18 22:53:50 +03:00
|
|
|
markers = []
|
2014-01-31 05:38:41 +04:00
|
|
|
for key in sorted(remoteobs, reverse=True):
|
|
|
|
if key.startswith('dump'):
|
2017-04-26 15:56:47 +03:00
|
|
|
data = util.b85decode(remoteobs[key])
|
2015-12-18 22:53:50 +03:00
|
|
|
version, newmarks = obsolete._readmarkers(data)
|
|
|
|
markers += newmarks
|
|
|
|
if markers:
|
|
|
|
pullop.repo.obsstore.add(tr, markers)
|
2014-01-31 13:12:35 +04:00
|
|
|
pullop.repo.invalidatevolatilesets()
|
2014-01-31 05:38:41 +04:00
|
|
|
return tr
|
|
|
|
|
2014-05-23 00:31:33 +04:00
|
|
|
def caps20to10(repo):
|
|
|
|
"""return a set with appropriate options to use bundle20 during getbundle"""
|
2017-02-11 03:56:29 +03:00
|
|
|
caps = {'HG20'}
|
2014-08-25 21:21:47 +04:00
|
|
|
capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo))
|
2016-04-07 02:22:12 +03:00
|
|
|
caps.add('bundle2=' + urlreq.quote(capsblob))
|
2014-05-23 00:31:33 +04:00
|
|
|
return caps
|
|
|
|
|
2014-09-25 06:47:57 +04:00
|
|
|
# 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 = {}
|
|
|
|
|
2015-04-14 21:59:37 +03:00
|
|
|
def getbundle2partsgenerator(stepname, idx=None):
|
2014-09-25 06:47:57 +04:00
|
|
|
"""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
|
2015-04-14 21:59:37 +03:00
|
|
|
if idx is None:
|
|
|
|
getbundle2partsorder.append(stepname)
|
|
|
|
else:
|
|
|
|
getbundle2partsorder.insert(idx, stepname)
|
2014-09-25 06:47:57 +04:00
|
|
|
return func
|
|
|
|
return dec
|
|
|
|
|
2015-12-05 00:31:01 +03:00
|
|
|
def bundle2requested(bundlecaps):
|
|
|
|
if bundlecaps is not None:
|
|
|
|
return any(cap.startswith('HG2') for cap in bundlecaps)
|
|
|
|
return False
|
|
|
|
|
exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.
In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.
util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).
This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.
Callers of exchange.getbundle() have been updated to use the new API.
There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
2016-10-16 20:38:52 +03:00
|
|
|
def getbundlechunks(repo, source, heads=None, common=None, bundlecaps=None,
|
|
|
|
**kwargs):
|
|
|
|
"""Return chunks constituting a bundle's raw data.
|
2014-04-04 12:51:54 +04:00
|
|
|
|
2015-04-09 23:25:48 +03:00
|
|
|
Could be a bundle HG10 or a bundle HG20 depending on bundlecaps
|
exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.
In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.
util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).
This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.
Callers of exchange.getbundle() have been updated to use the new API.
There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
2016-10-16 20:38:52 +03:00
|
|
|
passed.
|
2014-04-04 12:51:54 +04:00
|
|
|
|
exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.
In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.
util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).
This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.
Callers of exchange.getbundle() have been updated to use the new API.
There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
2016-10-16 20:38:52 +03:00
|
|
|
Returns an iterator over raw chunks (of varying sizes).
|
2014-04-04 12:51:54 +04:00
|
|
|
"""
|
2017-06-22 00:40:24 +03:00
|
|
|
kwargs = pycompat.byteskwargs(kwargs)
|
2015-12-05 00:31:01 +03:00
|
|
|
usebundle2 = bundle2requested(bundlecaps)
|
2014-09-25 06:47:57 +04:00
|
|
|
# bundle10 case
|
2015-04-08 02:01:32 +03:00
|
|
|
if not usebundle2:
|
2014-09-25 06:47:57 +04:00
|
|
|
if bundlecaps and not kwargs.get('cg', True):
|
|
|
|
raise ValueError(_('request for bundle10 must include changegroup'))
|
|
|
|
|
2014-05-30 01:59:22 +04:00
|
|
|
if kwargs:
|
|
|
|
raise ValueError(_('unsupported getbundle arguments: %s')
|
|
|
|
% ', '.join(sorted(kwargs.keys())))
|
2016-08-09 18:06:35 +03:00
|
|
|
outgoing = _computeoutgoing(repo, heads, common)
|
2017-09-11 04:51:31 +03:00
|
|
|
return changegroup.makestream(repo, outgoing, '01', source,
|
|
|
|
bundlecaps=bundlecaps)
|
2014-09-25 06:47:57 +04:00
|
|
|
|
|
|
|
# bundle20 case
|
2014-04-17 10:01:38 +04:00
|
|
|
b2caps = {}
|
|
|
|
for bcaps in bundlecaps:
|
|
|
|
if bcaps.startswith('bundle2='):
|
2016-04-07 02:22:12 +03:00
|
|
|
blob = urlreq.unquote(bcaps[len('bundle2='):])
|
2014-04-17 10:01:38 +04:00
|
|
|
b2caps.update(bundle2.decodecaps(blob))
|
|
|
|
bundler = bundle2.bundle20(repo.ui, b2caps)
|
2014-09-25 06:47:57 +04:00
|
|
|
|
2014-10-29 19:46:08 +03:00
|
|
|
kwargs['heads'] = heads
|
|
|
|
kwargs['common'] = common
|
|
|
|
|
2014-09-25 06:47:57 +04:00
|
|
|
for name in getbundle2partsorder:
|
|
|
|
func = getbundle2partsmapping[name]
|
2014-09-25 08:50:03 +04:00
|
|
|
func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps,
|
2017-06-22 00:46:16 +03:00
|
|
|
**pycompat.strkwargs(kwargs))
|
2014-09-25 06:47:57 +04:00
|
|
|
|
exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.
In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.
util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).
This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.
Callers of exchange.getbundle() have been updated to use the new API.
There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
2016-10-16 20:38:52 +03:00
|
|
|
return bundler.getchunks()
|
2014-09-25 06:47:57 +04:00
|
|
|
|
|
|
|
@getbundle2partsgenerator('changegroup')
|
2014-09-25 08:50:03 +04:00
|
|
|
def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
|
|
|
|
b2caps=None, heads=None, common=None, **kwargs):
|
2014-09-25 06:47:57 +04:00
|
|
|
"""add a changegroup part to the requested bundle"""
|
2017-09-11 05:01:56 +03:00
|
|
|
cgstream = None
|
2017-12-10 02:16:25 +03:00
|
|
|
if kwargs.get(r'cg', True):
|
2014-09-25 06:47:57 +04:00
|
|
|
# build changegroup bundle here.
|
2016-03-26 02:01:40 +03:00
|
|
|
version = '01'
|
2015-04-09 23:25:48 +03:00
|
|
|
cgversions = b2caps.get('changegroup')
|
2015-06-08 01:47:07 +03:00
|
|
|
if cgversions: # 3.1 and 3.2 ship with an empty value
|
2016-01-13 08:01:06 +03:00
|
|
|
cgversions = [v for v in cgversions
|
2016-01-27 20:07:28 +03:00
|
|
|
if v in changegroup.supportedoutgoingversions(repo)]
|
2014-10-17 16:59:10 +04:00
|
|
|
if not cgversions:
|
|
|
|
raise ValueError(_('no common changegroup version'))
|
2016-03-26 02:01:40 +03:00
|
|
|
version = max(cgversions)
|
2016-08-09 18:06:35 +03:00
|
|
|
outgoing = _computeoutgoing(repo, heads, common)
|
2017-09-12 19:13:02 +03:00
|
|
|
if outgoing.missing:
|
|
|
|
cgstream = changegroup.makestream(repo, outgoing, version, source,
|
|
|
|
bundlecaps=bundlecaps)
|
2014-09-25 06:47:57 +04:00
|
|
|
|
2017-09-11 05:01:56 +03:00
|
|
|
if cgstream:
|
|
|
|
part = bundler.newpart('changegroup', data=cgstream)
|
2016-03-26 02:01:40 +03:00
|
|
|
if cgversions:
|
2014-10-17 16:59:10 +04:00
|
|
|
part.addparam('version', version)
|
2017-09-16 01:38:36 +03:00
|
|
|
part.addparam('nbchanges', '%d' % len(outgoing.missing),
|
|
|
|
mandatory=False)
|
2016-01-09 08:13:06 +03:00
|
|
|
if 'treemanifest' in repo.requirements:
|
|
|
|
part.addparam('treemanifest', '1')
|
2014-09-25 06:47:57 +04:00
|
|
|
|
2017-10-17 16:27:17 +03:00
|
|
|
@getbundle2partsgenerator('bookmarks')
|
|
|
|
def _getbundlebookmarkpart(bundler, repo, source, bundlecaps=None,
|
|
|
|
b2caps=None, **kwargs):
|
|
|
|
"""add a bookmark part to the requested bundle"""
|
2017-12-10 02:16:25 +03:00
|
|
|
if not kwargs.get(r'bookmarks', False):
|
2017-10-17 16:27:17 +03:00
|
|
|
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)
|
|
|
|
|
2014-09-25 06:47:57 +04:00
|
|
|
@getbundle2partsgenerator('listkeys')
|
2014-09-25 08:50:03 +04:00
|
|
|
def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,
|
|
|
|
b2caps=None, **kwargs):
|
2014-09-25 06:47:57 +04:00
|
|
|
"""add parts containing listkeys namespaces to the requested bundle"""
|
2017-12-10 02:16:25 +03:00
|
|
|
listkeys = kwargs.get(r'listkeys', ())
|
2014-05-28 02:43:09 +04:00
|
|
|
for namespace in listkeys:
|
2015-04-09 23:25:48 +03:00
|
|
|
part = bundler.newpart('listkeys')
|
2014-05-28 02:43:09 +04:00
|
|
|
part.addparam('namespace', namespace)
|
|
|
|
keys = repo.listkeys(namespace).items()
|
|
|
|
part.data = pushkey.encodekeys(keys)
|
2014-04-05 04:15:25 +04:00
|
|
|
|
2014-09-25 06:47:57 +04:00
|
|
|
@getbundle2partsgenerator('obsmarkers')
|
2014-09-25 08:50:03 +04:00
|
|
|
def _getbundleobsmarkerpart(bundler, repo, source, bundlecaps=None,
|
|
|
|
b2caps=None, heads=None, **kwargs):
|
2014-09-25 06:11:37 +04:00
|
|
|
"""add an obsolescence markers part to the requested bundle"""
|
2017-12-10 02:16:25 +03:00
|
|
|
if kwargs.get(r'obsmarkers', False):
|
2014-08-29 14:36:17 +04:00
|
|
|
if heads is None:
|
|
|
|
heads = repo.heads()
|
|
|
|
subset = [c.node() for c in repo.set('::%ln', heads)]
|
|
|
|
markers = repo.obsstore.relevantmarkers(subset)
|
2015-05-10 16:48:08 +03:00
|
|
|
markers = sorted(markers)
|
2017-05-28 21:48:18 +03:00
|
|
|
bundle2.buildobsmarkerspart(bundler, markers)
|
2014-08-29 14:36:17 +04:00
|
|
|
|
2017-09-24 22:27:18 +03:00
|
|
|
@getbundle2partsgenerator('phases')
|
|
|
|
def _getbundlephasespart(bundler, repo, source, bundlecaps=None,
|
|
|
|
b2caps=None, heads=None, **kwargs):
|
|
|
|
"""add phase heads part to the requested bundle"""
|
2017-12-10 02:16:25 +03:00
|
|
|
if kwargs.get(r'phases', False):
|
2017-09-24 22:27:18 +03:00
|
|
|
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)
|
|
|
|
|
exchange: support transferring .hgtags fnodes mapping
On Mozilla's mozilla-beta repository .hgtags fnodes resolution takes
~18s from a clean cache on my machine. This means that the first time
a user runs `hg tags`, `hg log`, or any other command that displays or
accesses tags data, a ~18s pause will occur. There is no output during
this pause. This results in a poor user experience and perception
that Mercurial is slow.
The .hgtags changeset to filenode mapping is deterministic. This
patch takes advantage of that property by implementing support
for transferring .hgtags filenodes mappings in a dedicated bundle2
part. When a client advertising support for the "hgtagsfnodes"
capability requests a bundle, a mapping of changesets to .hgtags
filenodes will be sent to the client.
Only mappings of head changesets included in the bundle will be sent. The
transfer of this mapping effectively eliminates one time tags cache related
pauses after initial clone.
The mappings are sent as binary data. So, 40 bytes per pair of
SHA-1s. On the aforementioned mozilla-beta repository,
659 * 40 = 26,360 raw bytes of mappings are sent over the wire
(in addition to the bundle part headers). Assuming 18s to populate
the cache, we only need to transfer this extra data faster than
1.5 KB/s for overall clone + tags cache population time to be shorter.
Put into perspective, the mozilla-beta repository is ~1 GB in size.
So, this additional data constitutes <0.01% of the cloned data.
The marginal overhead for a multi-second performance win on clones
in my opinion justifies an on-by-default behavior.
2015-05-26 03:14:11 +03:00
|
|
|
@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.
|
2017-12-10 02:16:25 +03:00
|
|
|
if not (kwargs.get(r'cg', True) and 'hgtagsfnodes' in b2caps):
|
exchange: support transferring .hgtags fnodes mapping
On Mozilla's mozilla-beta repository .hgtags fnodes resolution takes
~18s from a clean cache on my machine. This means that the first time
a user runs `hg tags`, `hg log`, or any other command that displays or
accesses tags data, a ~18s pause will occur. There is no output during
this pause. This results in a poor user experience and perception
that Mercurial is slow.
The .hgtags changeset to filenode mapping is deterministic. This
patch takes advantage of that property by implementing support
for transferring .hgtags filenodes mappings in a dedicated bundle2
part. When a client advertising support for the "hgtagsfnodes"
capability requests a bundle, a mapping of changesets to .hgtags
filenodes will be sent to the client.
Only mappings of head changesets included in the bundle will be sent. The
transfer of this mapping effectively eliminates one time tags cache related
pauses after initial clone.
The mappings are sent as binary data. So, 40 bytes per pair of
SHA-1s. On the aforementioned mozilla-beta repository,
659 * 40 = 26,360 raw bytes of mappings are sent over the wire
(in addition to the bundle part headers). Assuming 18s to populate
the cache, we only need to transfer this extra data faster than
1.5 KB/s for overall clone + tags cache population time to be shorter.
Put into perspective, the mozilla-beta repository is ~1 GB in size.
So, this additional data constitutes <0.01% of the cloned data.
The marginal overhead for a multi-second performance win on clones
in my opinion justifies an on-by-default behavior.
2015-05-26 03:14:11 +03:00
|
|
|
return
|
|
|
|
|
2016-08-09 18:06:35 +03:00
|
|
|
outgoing = _computeoutgoing(repo, heads, common)
|
2017-05-05 18:28:52 +03:00
|
|
|
bundle2.addparttagsfnodescache(repo, bundler, outgoing)
|
exchange: support transferring .hgtags fnodes mapping
On Mozilla's mozilla-beta repository .hgtags fnodes resolution takes
~18s from a clean cache on my machine. This means that the first time
a user runs `hg tags`, `hg log`, or any other command that displays or
accesses tags data, a ~18s pause will occur. There is no output during
this pause. This results in a poor user experience and perception
that Mercurial is slow.
The .hgtags changeset to filenode mapping is deterministic. This
patch takes advantage of that property by implementing support
for transferring .hgtags filenodes mappings in a dedicated bundle2
part. When a client advertising support for the "hgtagsfnodes"
capability requests a bundle, a mapping of changesets to .hgtags
filenodes will be sent to the client.
Only mappings of head changesets included in the bundle will be sent. The
transfer of this mapping effectively eliminates one time tags cache related
pauses after initial clone.
The mappings are sent as binary data. So, 40 bytes per pair of
SHA-1s. On the aforementioned mozilla-beta repository,
659 * 40 = 26,360 raw bytes of mappings are sent over the wire
(in addition to the bundle part headers). Assuming 18s to populate
the cache, we only need to transfer this extra data faster than
1.5 KB/s for overall clone + tags cache population time to be shorter.
Put into perspective, the mozilla-beta repository is ~1 GB in size.
So, this additional data constitutes <0.01% of the cloned data.
The marginal overhead for a multi-second performance win on clones
in my opinion justifies an on-by-default behavior.
2015-05-26 03:14:11 +03:00
|
|
|
|
2014-04-05 04:15:25 +04:00
|
|
|
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()
|
2016-06-10 07:12:33 +03:00
|
|
|
heads_hash = hashlib.sha1(''.join(sorted(heads))).digest()
|
2014-04-05 04:15:25 +04:00
|
|
|
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
|
2014-04-22 05:59:09 +04:00
|
|
|
raise error.PushRaced('repository changed while %s - '
|
|
|
|
'please try again' % context)
|
2014-04-05 04:28:59 +04:00
|
|
|
|
|
|
|
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
|
2014-04-13 21:01:00 +04:00
|
|
|
mechanism to check that no push race occurred between the creation of the
|
2014-04-05 04:28:59 +04:00
|
|
|
bundle and its application.
|
|
|
|
|
|
|
|
If the push was raced as PushRaced exception is raised."""
|
|
|
|
r = 0
|
2014-04-10 21:53:43 +04:00
|
|
|
# need a transaction when processing a bundle2 stream
|
2015-10-06 02:19:54 +03:00
|
|
|
# [wlock, lock, tr] - needs to be an array so nested functions can modify it
|
|
|
|
lockandtr = [None, None, None]
|
2015-04-23 16:20:36 +03:00
|
|
|
recordout = None
|
2015-04-29 03:38:02 +03:00
|
|
|
# quick fix for output mismatch with bundle2 in 3.4
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
captureoutput = repo.ui.configbool('experimental', 'bundle2-output-capture')
|
2015-05-20 19:44:06 +03:00
|
|
|
if url.startswith('remote:http:') or url.startswith('remote:https:'):
|
2015-04-29 03:38:02 +03:00
|
|
|
captureoutput = True
|
2014-04-05 04:28:59 +04:00
|
|
|
try:
|
2017-02-02 12:51:04 +03:00
|
|
|
# note: outside bundle1, 'heads' is expected to be empty and this
|
|
|
|
# 'check_heads' call wil be a no-op
|
2014-04-05 04:28:59 +04:00
|
|
|
check_heads(repo, heads, 'uploading changes')
|
|
|
|
# push can proceed
|
2017-06-17 08:57:31 +03:00
|
|
|
if not isinstance(cg, bundle2.unbundle20):
|
2017-02-02 12:53:55 +03:00
|
|
|
# legacy case: bundle1 (changegroup 01)
|
2017-06-16 02:10:53 +03:00
|
|
|
txnname = "\n".join([source, util.hidepassword(url)])
|
2017-06-16 08:46:38 +03:00
|
|
|
with repo.lock(), repo.transaction(txnname) as tr:
|
2017-06-23 01:00:19 +03:00
|
|
|
op = bundle2.applybundle(repo, cg, tr, source, url)
|
2017-06-22 07:08:48 +03:00
|
|
|
r = bundle2.combinechangegroupresults(op)
|
2017-02-02 12:53:55 +03:00
|
|
|
else:
|
2015-04-16 10:17:01 +03:00
|
|
|
r = None
|
2014-04-22 03:13:15 +04:00
|
|
|
try:
|
2015-10-06 02:19:54 +03:00
|
|
|
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,
|
2015-04-29 03:38:02 +03:00
|
|
|
captureoutput=captureoutput)
|
2015-04-23 18:36:18 +03:00
|
|
|
try:
|
2015-07-20 23:39:25 +03:00
|
|
|
op = bundle2.processbundle(repo, cg, op=op)
|
2015-04-23 18:36:18 +03:00
|
|
|
finally:
|
|
|
|
r = op.reply
|
2015-04-29 03:38:02 +03:00
|
|
|
if captureoutput and r is not None:
|
2015-04-23 18:36:18 +03:00
|
|
|
repo.ui.pushbuffer(error=True, subproc=True)
|
|
|
|
def recordout(output):
|
|
|
|
r.newpart('output', data=output, mandatory=False)
|
2015-10-06 02:19:54 +03:00
|
|
|
if lockandtr[2] is not None:
|
|
|
|
lockandtr[2].close()
|
2015-06-24 08:20:08 +03:00
|
|
|
except BaseException as exc:
|
2014-04-22 03:13:15 +04:00
|
|
|
exc.duringunbundle2 = True
|
2015-04-29 03:38:02 +03:00
|
|
|
if captureoutput and r is not None:
|
2015-04-23 16:20:36 +03:00
|
|
|
parts = exc._bundle2salvagedoutput = r.salvageoutput()
|
|
|
|
def recordout(output):
|
|
|
|
part = bundle2.bundlepart('output', data=output,
|
|
|
|
mandatory=False)
|
|
|
|
parts.append(part)
|
2014-04-22 03:13:15 +04:00
|
|
|
raise
|
2014-04-05 04:28:59 +04:00
|
|
|
finally:
|
2015-10-06 02:19:54 +03:00
|
|
|
lockmod.release(lockandtr[2], lockandtr[1], lockandtr[0])
|
2015-04-23 16:20:36 +03:00
|
|
|
if recordout is not None:
|
|
|
|
recordout(repo.ui.popbuffer())
|
2014-04-05 04:28:59 +04:00
|
|
|
return r
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
|
|
|
|
def _maybeapplyclonebundle(pullop):
|
|
|
|
"""Apply a clone bundle from a remote, if possible."""
|
|
|
|
|
|
|
|
repo = pullop.repo
|
|
|
|
remote = pullop.remote
|
|
|
|
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
if not repo.ui.configbool('ui', 'clonebundles'):
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
return
|
|
|
|
|
2015-11-03 23:16:54 +03:00
|
|
|
# Only run if local repo is empty.
|
|
|
|
if len(repo):
|
|
|
|
return
|
|
|
|
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
if pullop.heads:
|
|
|
|
return
|
|
|
|
|
|
|
|
if not remote.capable('clonebundles'):
|
|
|
|
return
|
|
|
|
|
|
|
|
res = remote._call('clonebundles')
|
2015-10-14 00:55:02 +03:00
|
|
|
|
|
|
|
# If we call the wire protocol command, that's good enough to record the
|
|
|
|
# attempt.
|
|
|
|
pullop.clonebundleattempted = True
|
|
|
|
|
2015-10-13 22:31:19 +03:00
|
|
|
entries = parseclonebundlesmanifest(repo, res)
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
if not entries:
|
|
|
|
repo.ui.note(_('no clone bundles available on remote; '
|
|
|
|
'falling back to regular clone\n'))
|
|
|
|
return
|
|
|
|
|
2017-09-28 17:24:54 +03:00
|
|
|
entries = filterclonebundleentries(
|
|
|
|
repo, entries, streamclonerequested=pullop.streamclonerequested)
|
|
|
|
|
2015-10-13 21:45:30 +03:00
|
|
|
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
|
|
|
|
|
2015-10-13 22:30:39 +03:00
|
|
|
entries = sortclonebundleentries(repo.ui, entries)
|
2015-10-13 21:45:30 +03:00
|
|
|
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
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.
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
elif repo.ui.configbool('ui', 'clonebundlefallback'):
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
repo.ui.warn(_('falling back to normal clone\n'))
|
|
|
|
else:
|
|
|
|
raise error.Abort(_('error applying bundle'),
|
2015-10-13 22:41:32 +03:00
|
|
|
hint=_('if this error persists, consider contacting '
|
|
|
|
'the server operator or disable clone '
|
|
|
|
'bundles via '
|
2016-01-08 21:58:04 +03:00
|
|
|
'"--config ui.clonebundles=false"'))
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
|
2015-10-13 22:31:19 +03:00
|
|
|
def parseclonebundlesmanifest(repo, s):
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
"""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)
|
2016-04-07 02:22:12 +03:00
|
|
|
key = urlreq.unquote(key)
|
|
|
|
value = urlreq.unquote(value)
|
2015-10-13 22:31:19 +03:00
|
|
|
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:
|
2015-10-15 03:00:34 +03:00
|
|
|
comp, version, params = parsebundlespec(repo, value,
|
|
|
|
externalnames=True)
|
2015-10-13 22:31:19 +03:00
|
|
|
attrs['COMPRESSION'] = comp
|
|
|
|
attrs['VERSION'] = version
|
|
|
|
except error.InvalidBundleSpecification:
|
|
|
|
pass
|
|
|
|
except error.UnsupportedBundleSpecification:
|
|
|
|
pass
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
|
|
|
|
m.append(attrs)
|
|
|
|
|
|
|
|
return m
|
|
|
|
|
2017-09-28 17:24:54 +03:00
|
|
|
def filterclonebundleentries(repo, entries, streamclonerequested=False):
|
2015-10-14 20:03:26 +03:00
|
|
|
"""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.
|
|
|
|
"""
|
2015-10-13 21:45:30 +03:00
|
|
|
newentries = []
|
|
|
|
for entry in entries:
|
|
|
|
spec = entry.get('BUNDLESPEC')
|
|
|
|
if spec:
|
|
|
|
try:
|
2017-09-28 17:24:54 +03:00
|
|
|
comp, version, params = parsebundlespec(repo, spec, strict=True)
|
|
|
|
|
|
|
|
# If a stream clone was requested, filter out non-streamclone
|
|
|
|
# entries.
|
|
|
|
if streamclonerequested and (comp != 'UN' or version != 's1'):
|
|
|
|
repo.ui.debug('filtering %s because not a stream clone\n' %
|
|
|
|
entry['URL'])
|
|
|
|
continue
|
|
|
|
|
2015-10-13 21:45:30 +03:00
|
|
|
except error.InvalidBundleSpecification as e:
|
|
|
|
repo.ui.debug(str(e) + '\n')
|
|
|
|
continue
|
|
|
|
except error.UnsupportedBundleSpecification as e:
|
|
|
|
repo.ui.debug('filtering %s because unsupported bundle '
|
|
|
|
'spec: %s\n' % (entry['URL'], str(e)))
|
|
|
|
continue
|
2017-09-28 17:24:54 +03:00
|
|
|
# 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
|
2015-10-13 21:45:30 +03:00
|
|
|
|
2015-10-13 20:59:41 +03:00
|
|
|
if 'REQUIRESNI' in entry and not sslutil.hassni:
|
|
|
|
repo.ui.debug('filtering %s because SNI not supported\n' %
|
|
|
|
entry['URL'])
|
|
|
|
continue
|
|
|
|
|
2015-10-13 21:45:30 +03:00
|
|
|
newentries.append(entry)
|
|
|
|
|
|
|
|
return newentries
|
|
|
|
|
2016-12-26 22:11:29 +03:00
|
|
|
class clonebundleentry(object):
|
|
|
|
"""Represents an item in a clone bundles manifest.
|
2015-10-13 22:30:39 +03:00
|
|
|
|
2016-12-26 22:11:29 +03:00
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, value, prefers):
|
|
|
|
self.value = value
|
|
|
|
self.prefers = prefers
|
2015-10-13 22:30:39 +03:00
|
|
|
|
2016-12-26 22:11:29 +03:00
|
|
|
def _cmp(self, other):
|
|
|
|
for prefkey, prefvalue in self.prefers:
|
|
|
|
avalue = self.value.get(prefkey)
|
|
|
|
bvalue = other.value.get(prefkey)
|
2015-10-13 22:30:39 +03:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2016-12-26 22:11:29 +03:00
|
|
|
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):
|
2017-06-17 14:25:42 +03:00
|
|
|
prefers = ui.configlist('ui', 'clonebundleprefers')
|
2016-12-26 22:11:29 +03:00
|
|
|
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]
|
2015-10-13 22:30:39 +03:00
|
|
|
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
def trypullbundlefromurl(ui, repo, url):
|
|
|
|
"""Attempt to apply a bundle from a URL."""
|
2017-06-16 03:00:32 +03:00
|
|
|
with repo.lock(), repo.transaction('bundleurl') as tr:
|
clonebundles: support for seeding clones from pre-generated bundles
Cloning can be an expensive operation for servers because the server
generates a bundle from existing repository data at request time. For
a large repository like mozilla-central, this consumes 4+ minutes
of CPU time on the server. It also results in significant network
utilization. Multiplied by hundreds or even thousands of clients and
the ensuing load can result in difficulties scaling the Mercurial server.
Despite generation of bundles being deterministic until the next
changeset is added, the generation of bundles to service a clone request
is not cached. Each clone thus performs redundant work. This is
wasteful.
This patch introduces the "clonebundles" extension and related
client-side functionality to help alleviate this deficiency. The
client-side feature is behind an experimental flag and is not enabled by
default.
It works as follows:
1) Server operator generates a bundle and makes it available on a
server (likely HTTP).
2) Server operator defines the URL of a bundle file in a
.hg/clonebundles.manifest file.
3) Client `hg clone`ing sees the server is advertising bundle URLs.
4) Client fetches and applies the advertised bundle.
5) Client performs equivalent of `hg pull` to fetch changes made since
the bundle was created.
Essentially, the server performs the expensive work of generating a
bundle once and all subsequent clones fetch a static file from
somewhere. Scaling static file serving is a much more manageable
problem than scaling a Python application like Mercurial. Assuming your
repository grows less than 1% per day, the end result is 99+% of CPU
and network load from clones is eliminated, allowing Mercurial servers
to scale more easily. Serving static files also means data can be
transferred to clients as fast as they can consume it, rather than as
fast as servers can generate it. This makes clones faster.
Mozilla has implemented similar functionality of this patch on
hg.mozilla.org using a custom extension. We are hosting bundle files in
Amazon S3 and CloudFront (a CDN) and have successfully offloaded
>1 TB/day in data transfer from hg.mozilla.org, freeing up significant
bandwidth and CPU resources. The positive impact has been stellar and
I believe it has proved its value to be included in Mercurial core. I
feel it is important for the client-side support to be enabled in core
by default because it means that clients will get faster, more reliable
clones and will enable server operators to reduce load without
requiring any client-side configuration changes (assuming clients are
up to date, of course).
The scope of this feature is narrowly and specifically tailored to
cloning, despite "serve pulls from pre-generated bundles" being a valid
and useful feature. I would eventually like for Mercurial servers to
support transferring *all* repository data via statically hosted files.
You could imagine a server that siphons all pushed data to bundle files
and instructs clients to apply a stream of bundles to reconstruct all
repository data. This feature, while useful and powerful, is
significantly more work to implement because it requires the server
component have awareness of discovery and a mapping of which changesets
are in which files. Full, clone bundles, by contrast, are much simpler.
The wire protocol command is named "clonebundles" instead of something
more generic like "staticbundles" to leave the door open for a new, more
powerful and more generic server-side component with minimal backwards
compatibility implications. The name "bundleclone" is used by Mozilla's
extension and would cause problems since there are subtle differences
in Mozilla's extension.
Mozilla's experience with this idea has taught us that some form of
"content negotiation" is required. Not all clients will support all
bundle formats or even URLs (advanced TLS requirements, etc). To ensure
the highest uptake possible, a server needs to advertise multiple
versions of bundles and clients need to be able to choose the most
appropriate from that list one. The "attributes" in each
server-advertised entry facilitate this filtering and sorting. Their
use will become apparent in subsequent patches.
Initial inspiration and credit for the idea of cloning from static files
belongs to Augie Fackler and his "lookaside clone" extension proof of
concept.
2015-10-09 21:22:01 +03:00
|
|
|
try:
|
2017-06-16 03:00:32 +03:00
|
|
|
fh = urlmod.open(ui, url)
|
|
|
|
cg = readbundle(ui, fh, 'stream')
|
2015-10-13 20:41:54 +03:00
|
|
|
|
2017-06-23 01:00:19 +03:00
|
|
|
if isinstance(cg, streamclone.streamcloneapplier):
|
2017-06-16 03:00:32 +03:00
|
|
|
cg.apply(repo)
|
|
|
|
else:
|
2017-06-23 01:00:19 +03:00
|
|
|
bundle2.applybundle(repo, cg, tr, 'clonebundles', url)
|
2017-06-16 03:00:32 +03:00
|
|
|
return True
|
|
|
|
except urlerr.httperror as e:
|
|
|
|
ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
|
|
|
|
except urlerr.urlerror as e:
|
|
|
|
ui.warn(_('error fetching bundle: %s\n') % e.reason)
|
|
|
|
|
|
|
|
return False
|