Commit Graph

141 Commits

Author SHA1 Message Date
Pierre-Yves David
f96ca2174a unbundle20: allow generic dispatch between unbundlers
We now take full advantage of the 'getunbundler' function by using a
'{version -> unbundler-class}' mapping. This map currently contains a single
entry but will make it easy to support more versions from an extension/the
future.

At some point, this map will probably contain bundler-class information too,
in the same fashion the packer map does. However, this is not critically required
right now so it will happen by itself when needed.

The main target is to allow HG2Y support in an extension to ease transition of
companies using the experimental protocol in production (yeah...) But I've no
doubt this will be useful when playing with a future HG21.
2015-04-06 17:23:11 -07:00
Pierre-Yves David
e57a876dd7 unbundle20: move header parsing into the 'getunbundler' function
The dispatching will be based on the header content, so we need to move this
logic into the factory function.
2015-04-06 16:07:18 -07:00
Pierre-Yves David
9dd801717e unbundle20: retrieve unbundler instances through a factory function
To support multiple bundle2 formats, we will need a function returning
the proper unbundler according to the header. We introduce such aa
function and change the usage in the code base. The function will get
smarter in later changesets.

This is somewhat similar to the dispatching we do for 'HG10' and 'HG11'.

The main target is to allow HG2Y support in an extension to ease transition of
companies using the experimental protocol in production (yeah...) But I've no
doubt this will be useful when playing with a future HG21.
2015-04-06 16:04:33 -07:00
Pierre-Yves David
f5b136bf48 bundle20: move magic string into the class
This makes it easy to create a new bundler class that inherits from
the core one. This matches the way 'changegroup' packers work.

The main target is to allow HG2Y support in an extension to ease transition of
companies using the experimental protocol in production (yeah...) But I've no
doubt this will be useful when playing with a future HG21.
2015-04-06 15:40:12 -07:00
Eric Sumner
7be7f03ddd bundle2.unbundle20: add compressed() method
Bundlerepo uses the compressed() method to determine whether it should write
an uncompressed temporary file.  Since we don't support compressed bundle2 files
at the moment, make this method return true.
2015-02-05 15:56:50 -08:00
Eric Sumner
a5c538fc74 bundle2.unpackermixin: default value for seek() whence parameter
The contract for seek() includes seeking to an offset from the beginning of the
file when whence is omitted; put this implementation in compliance.
2015-02-05 15:52:57 -08:00
Eric Sumner
226e333215 bundle2: seek in part iterator
When iterating over bundle2 parts, add a seek to the iterator so that
processing will continue normally even if the entire part isn't
consumed.
2015-02-05 10:57:45 -08:00
Eric Sumner
bf8078ff25 bundle2: now that we have a seek implementation, use it
Replace bare part.read() calls with part.seek(0, 2) since the return value is
being ignored.  As this doesn't necessarily require building a string that
contains the rest of the part, the potential exists to reduce the memory
footprint of these operations.
2015-02-05 10:56:05 -08:00
Eric Sumner
db734be63f bundle2.unbundlepart: implement seek()
This implements a seek() method for unbundlepart.  This allows on-disk bundle2
parts to behave enough like files for bundlerepo to handle them.  A future
patch will add support for bundlerepo to read the bundle2 files that are
written when the experimental.strip-bundle2-version config option is used.
2015-01-14 16:14:19 -08:00
Eric Sumner
e37a75b13f bundle2.unbundlepart: tell() implementation
Keep track of how many bytes we've returned from read(); fairly straightforward.
2015-01-14 15:57:57 -08:00
Eric Sumner
de1e74f974 bundle2.unbundlepart: keep an index of chunks and their locations
In order to make unbundlepart seekable, we need to keep a record of where the
chunks are so that we can go back to the correct point.
2015-01-14 14:46:23 -08:00
Eric Sumner
37c72c9030 bundle2.unbundlepart: raise payloadchunks from a closure to a method
In a future patch, seek() will need to make a new chunk iterator for
the stream; this places it somewhere it can be called multiple times.
2015-01-14 14:32:22 -08:00
Eric Sumner
26d6ca5b17 bundle2.unpackermixin: control for underlying file descriptor
This patch adds seek(), tell(), and close() implementations for unpackermixin
which forward to the file descriptor's implementation if possible.  A future
patch will use this to make bundle2.unbundlepart seekable, which will in turn
make it usable as a file descriptor for bundlerepo.
2015-01-14 14:24:16 -08:00
Matt Mackall
50094eea66 bundle2: fix parttype enforcement
As spotted by Malte Helmert.
2015-01-17 18:08:47 -08:00
Pierre-Yves David
3256dbc9b3 bundle2: enforce parttype as alphanumerical
The binary format description has always stated that the parttype should be simple,
but it was never really enforced. Recent discussions have convinced me we want to
keep the part type simple and easy to debug. There is enough extensibility in
the rest of the format.
2014-12-18 19:14:01 -08:00
Eric Sumner
688d023c87 bundle2.bundlepart: make mandatory part flag explicit in API
This makes all bundle2 parts mandatory unless they are expressly made advisory
via the keyword parameter or the bundlepart.mandatory property.
2014-12-17 21:14:19 -08:00
Eric Sumner
165755115f bundle2._processpart: forcing lower-case compare is no longer necessary
Encoding whether or not a part is mandatory in the capitalization of the
parttype is unintuitive and error-prone.  This sequence of patches separates
these concerns in the API to reduce programmer error and pave the way for
a potential change in how this information is transmitted over the wire.

Since the parttype and mandatory bit are separated in bundle2.unbundlepart
(see previous patch), there is no longer a need to remove the mandatory bit
before working with the parttype.
2014-12-12 12:31:41 -08:00
Eric Sumner
a5fc298ca7 bundle2.unbundlepart: decouple mandatory from parttype
Encoding whether or not a part is mandatory in the capitalization of the
parttype is unintuitive and error-prone.  This sequence of patches separates
these concerns in the API to reduce programmer error and pave the way for
a potential change in how this information is transmitted over the wire.

This patch separates the two pieces of information when reading the part header
so that it's unnecessary to know how they were combined during transmission.
2014-12-12 11:26:56 -08:00
Eric Sumner
973f0c3522 bundle2-push: provide transaction to reply unbundler
This patch series is intended to allow bundle2 push reply part handlers to
make changes to the local repository; it has been developed in parallel with
an extension that allows the server to rebase incoming changesets while applying
them.

This diff adds an experimental config option "bundle2.pushback" which provides
a transaction to the reply unbundler during a push operation.  This behavior is
opt-in because of potential security issues: the response can contain any part
type that has a handler defined, allowing the server to make arbitrary changes
to the local repository.
2014-11-21 15:50:38 -08:00
Eric Sumner
154e42b303 bundle2.processbundle: let callers request default behavior
This patch series is intended to allow bundle2 push reply part handlers to
make changes to the local repository; it has been developed in parallel with
an extension that allows the server to rebase incoming changesets while applying
them.

The default transaction getter for processbundle is a private function that
raises an exception; this diff lets calling code pass None as the transaction
getter to explicitly request this default behavior.

The next diff will check a config option to determine whether to provide a
transaction to the reply bundle processor.  If one shouldn't be provided, the
code needs a way to specify that the default behavior should be used.
2014-11-24 16:04:44 -08:00
Pierre-Yves David
1da866fd04 bundle2: drop duplicated definition of 'b2x:exchange'
This bundle2 capability is going to be dynamically computed in 'getrepocaps'. We
do not need to include it in the static value.
2014-11-06 10:05:43 +00:00
Pierre-Yves David
80ae5ba5ab bundle2: support a "version" argument in changegroup part
When included, this mandatory parameter (mandatory == cannot be ignored) lets the
part handler select the right cgunpacker class.
2014-09-24 21:33:12 -07:00
Pierre-Yves David
553f12b081 bundle2caps: advertise the available versions for changegroup packer
This will let the bundle2 client and server detect what packer they should be using.

This detection part is not done. I expect it to be done with the addition of the
second packer (with generaldelta support).
2014-09-24 21:28:54 -07:00
Mads Kiilerich
523c87c1fe spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
Pierre-Yves David
ad1ec3399d bundle2: transmit exception during part generation
If an exception is raised during a bundle2 part payload generation it is now
recorded in the bundle. If such exception occurs, we capture it, transmit an
abort exception through the bundle, cleanly close the current part payload and
raise it again. This allow to generate valid bundle even in case of exception so
that the consumer does not wait forever for a dead producer. This also allow to
raise the exception during unbundling at the exact point it happened during
bundling make debugging easier.
2014-10-15 03:52:20 -07:00
Pierre-Yves David
38561c6027 bundle2: add a interrupt mechanism
It is now possible to emit a single part in the middle of a payload production.
This part will be processed with limitation (only access to a `ui` object). The
goal is to let the server raise exception and output while a part is being
processed. The source motivation is to transmit exception that occurs while
generating a part.

This change is was the motivation to bump the bundle2 format from HG2X to HG2Y.
Somehow, the format bump made it into 3.2 without it. So this change go on
stable. It is low risk as bundle2 is still disabled by default.
2014-10-14 10:47:47 -07:00
Mike Hommey
a290d1f800 bundle2: client side support for a part to import external bundles
Bundle2 opens doors to advanced features allowing to reduce load on
mercurial servers, and improve clone experience for users on unstable or
slow networks.

For instance, it could be possible to pre-generate a bundle of a
repository, and give a pointer to it to clients cloning the repository,
followed by another changegroup with the remainder. For significantly
big repositories, this could come as several base bundles with e.g. 10k
changesets, which, combined with checkpoints (not part of this change),
would prevent users with flaky networks from starting over any time
their connection fails.

While the server-side support for those features doesn't exist yet, it
is preferable to have client-side support for this early-on, allowing
experiments on servers only requiring a vanilla client with bundle2
enabled.
2014-10-17 09:57:05 +09:00
Pierre-Yves David
a4c1167319 bundle2: detect and disallow a negative chunk size
We have no usage planned for 2/3 of them and the support for the planned
usecase is not here yet. So we raise a BundleValueError when encountered
2014-10-15 03:27:25 -07:00
Pierre-Yves David
2ecc46cd04 bundle2: add an UnsupportedPartError
We need the BundleValueError for format errors not related to part support. So
we add a specific class for part-support errors.
2014-10-15 03:22:47 -07:00
Pierre-Yves David
15397993b6 bundle2: change header size and make them signed (new format)
We are changing all integers that denote the size of a chunk to read to int32.
There are two main motivations for that.

First, we change everything to the same width (32 bits) to make it possible for
a reasonably agnostic actor to forward a bundle2 without any extra processing.
With this change, this could be achieved by just reading int32s and forwarding
chunks of the size read. A bit a smartness would be logic to detect the end of
stream but nothing too complicated.

Second, we need some capacity to transmit special information during the bundle
processing. For example we would like to be able to raise an exception while a
part is being read if this exception happend while this part was generated.
Having signed integer let us use negative numbers to trigger special events
during the parsing of the bundle.

The format is renamed for B2X to B2Y because this breaks binary
compatibility. The B2X format support is dropped. It was experimental to
allow this kind of things. All elements not directly related to the binary
format remain flagged "b2x" because they are still compatible.
2014-10-01 23:40:23 -05:00
Pierre-Yves David
4a9c5fcd2c bundle2: extract processing of part into its own function
This is code movement only. This will be useful to have it separated for reuse
purposes. We plan to introduce a new feature to the bundle format that allow
inserting a part in the middle of another part payload. This will be useful to
transmit a exception raised during a part generation.
2014-10-14 02:32:26 -07:00
Pierre-Yves David
a56876db03 bundle2: add a comment about addchangegroup source and url 2014-10-14 01:27:25 -07:00
Durham Goode
bbb89aae08 obsolete: add exchange option
This adds an option that enables obsolete marker exchange.
2014-10-14 13:26:01 -07:00
Pierre-Yves David
1bbca4d386 bundle2: remove an explicit packing
The final writing of the empty part was done explicitly. We now using proper
pack call using symbolic constant. This open simple change in the bundle2
format.
2014-10-02 00:15:15 -05:00
Mike Hommey
d553e368f9 bundle2: rename functions that have the same name 2014-09-23 16:22:52 +09:00
Sune Foldager
eb415860f8 changegroup: rename bundle-related functions and classes
Functions like getbundle and classes like unbundle10 really manipulate
changegroups and not bundles. A HG10 bundle is the same as a changegroup
plus a small header, but this is no longer the case for a HG2X bundle,
so it's better to separate the names a bit.
2014-09-02 12:11:36 +02:00
Pierre-Yves David
e2072df9be bundle2: add a obsmarkersversion function to extract supported version
Right next to the function that encodes the supported versions in
capabilities we add a function that decodes the versions out of capabilities.
This is going to be useful to know what formats can be used for exchange.
2014-08-26 11:48:26 +02:00
Pierre-Yves David
661ba0c427 bundle2: advertise the obsmarker part in bundle2 capabilities 2014-08-21 18:18:38 -07:00
Pierre-Yves David
efcf1868b1 bundle2: introduce a getrepocaps to retrieve the bundle2 caps of a repo
This function lets extensions change the bundle2 capabilities of a repository.
2014-08-25 19:21:47 +02:00
Pierre-Yves David
757af06075 obsmarker: move bundle2caps from the localrepo class to the bundle2 module
The localrepo path was quicker, easier, more seductive. We'll soon add a
function in another changeset to alter the capabilities.
2014-08-25 19:17:06 +02:00
Pierre-Yves David
c3dde4235f obsmarker: produce a reply part for markers received through bundle2 2014-08-25 18:35:39 +02:00
Pierre-Yves David
417557b6af obssmarker: add a bundle2 record with the number of markers added 2014-08-25 18:10:08 +02:00
Pierre-Yves David
2a117cfbf2 obsmarker: write a message with the number of markers added through bundle2 2014-08-25 18:09:54 +02:00
Pierre-Yves David
fc505cbe59 bundle2: add an obsmarkers part handler
This part contains a binary stream of obsolescence markers. Received markers are
added to the repository.
2014-08-25 18:08:22 +02:00
Pierre-Yves David
4be695cccc bundle2: add a `bundle20.nbparts` property
This property can be used to know how much parts have been added to the bundle2.
This will be useful to check if any part have been generated for a push.
2014-07-02 16:17:54 +02:00
Pierre-Yves David
f7baff1111 bundle2: add `pushkey` support
After ``listkeys`` we can now include ``pushkey`` request in a bundle2. The part
uses a very simple scheme closest as possible to the current wireproto command
for ``pushkey``. We may eventually decide for a more sophisticated part format
before the protocol becomes final.
2014-05-27 16:32:50 -07:00
Pierre-Yves David
c4d12e35a5 bundle: introduce a listkey handler
This makes it possible to handle listkeys-related data stored in a bundle2.
There are no producers yet.
2014-05-27 15:42:03 -07:00
Pierre-Yves David
c2721b6512 bundle2: introduce a bundle2caps function
The process of decoding remote bundle2caps blob into a dictionary is cumbersome.
We move it into a small helper function. This will clarify code that reads
bundle2 capabilities of peers and helps using it in new places.
2014-05-24 16:20:09 -07:00
Pierre-Yves David
e60d3c1093 bundle2: raise BundleValueError error for stream level unsupported params
This ensures both consistency and smooth propagation over the wire.
2014-05-28 15:37:47 -07:00
Pierre-Yves David
ee9ac67c31 bundle2: support None parttype in BundleValueError
This will be used for errors at the stream level.
2014-05-28 16:46:58 -07:00