Commit Graph

276 Commits

Author SHA1 Message Date
Pierre-Yves David
e567efc154 bundle2: convey PushkeyFailed error over the wire
We add a way to convey the precise exception. This will allow better error
message on the server.
2015-06-10 13:10:53 -04:00
Pierre-Yves David
b5e74719f4 bundle2: also capture reply capability on failure
When unbundling over the wire is aborted, we have a mechanism to convey the
error inside a bundle part. As we add support for more errors, we need to know if
the client will support them. For this purpose, we duck punch the reply
capabilities of the client on the raised extensions.

This is similar to what is done to salvage the server output on error.
2015-06-06 00:50:27 -07:00
Pierre-Yves David
8956fcc604 bundle2: add an 'error' capability
This capability will be extended as new error type is introduced.
2015-06-06 00:32:19 -07:00
Pierre-Yves David
4386f8310a bundle2: introduce a PushkeyFail error to abort unbundle on pushkey error
The pushkey code is generic and the server side has little context on what the
client is trying to achieve. Generating interesting error messages server side
would be challenging. Instead we introduce a dedicated exception that carries more
data. In particular, it carries the id of the part which failed that will allow
clients to display custom error messages depending on the part intent.

The processing and transfer-over-the-wire of this exception is to be implemented
in coming changesets.
2015-05-27 23:48:54 -07:00
Pierre-Yves David
2f30e7a692 bundle2: abort when a mandatory pushkey part fails
So far, result of a pushkey operation had no consequence on the transaction
(beside the change). We makes it respect the 'mandatory' flag of part so that
failed pushkey call abort the whole transaction. This will allow rejecting
changes (primary target: changesets) regarding phases or bookmark criteria in
the future (when we will push such data in a mandatory part).

We currently raise an abort error because all clients support it. We'll
introduce a more precise error in the next changesets.
2015-05-27 05:28:40 -07:00
Gregory Szorc
a7e363e0cf bundle2: part handler for processing .hgtags fnodes mappings
.hgtags fnodes cache entries can be expensive to compute, especially
if there are hundreds of even thousands of them. This patch implements
support for receiving a bundle2 part that contains a mapping of
changeset to .hgtags fnodes.

An upcoming patch will teach the server to send this part, allowing
clients to bypass having to redundantly compute these values.

A number of tests changed due to the client advertising the "hgtagsfnodes"
capability.
2015-06-01 20:23:22 -07:00
Pierre-Yves David
d0e8796a75 bundle2: hide bundle2 stream debug under a config flag
The old output is very verbose and unsuitable for general debug level. It is
however very useful for debugging bundle2 generation or consumption issues. All
this verbose ouput is hidden under a 'devel.bundle2.debug' flag.
2015-05-26 23:06:17 -07:00
Pierre-Yves David
7d33b04271 bundle2: add generic debug output regarding processed interruption
If we are about to hide the detailed debug output, we need some generic debug
message to replace it in a concise way.
2015-05-26 23:47:19 -07:00
Pierre-Yves David
397fb0efd5 bundle2: add generic debug output regarding processed part payload
If we are about to hide the detailed debug output, we need some generic debug
message to replace it in a concise way.
2015-05-26 23:58:38 -07:00
Pierre-Yves David
977711b858 bundle2: add generic debug output regarding processed part
If we are about to hide the detailed debug output, we need some generic debug
message to replace it.
2015-05-26 23:36:31 -07:00
Pierre-Yves David
f4b0d8312f bundle2: add generic debug output at the end of bundle processing
If we are about to hide the detailed debug output, we need some generic debug
message to replace it in a concise way.
2015-05-27 00:02:49 -07:00
Pierre-Yves David
2d056781e3 bundle2: add generic debug output regarding processed bundle
If we are about to hide the detailed debug output, we need some generic debug
message to replace it in a concise way.
2015-05-27 00:00:35 -07:00
Pierre-Yves David
323fbad9e5 bundle2: add generic debug output regarding generated interruption
If we are about to hide the detailed debug output, we need some generic debug
message to replace it in a concise way.
2015-05-27 00:22:29 -07:00
Pierre-Yves David
aca59375f8 bundle2: add generic debug output regarding generated parts
If we are about to hide the detailed debug output, we need some generic debug
message to replace it in a concise way.
2015-05-27 00:19:16 -07:00
Pierre-Yves David
2aa990e3f6 bundle2: add generic debug output regarding generated bundle
If we are about to hide the detailed debug output, we need some generic debug
message to replace it in a more compact way.
2015-05-27 00:10:30 -07:00
Pierre-Yves David
669aff65a4 bundle2: add debug output for part generation
The part generation process was lacking a ui object and could not produce debug
output. It seems valuable to have some debug output on this part too, especially
now that we are planning to be able to hide it in the default --debug output.
2015-05-27 00:52:01 -07:00
Pierre-Yves David
803290608b bundle2: handle new line in 'indebug' function
Now that we have a prefix, it make sense to assume all output will be on a
single line.
2015-05-26 23:01:39 -07:00
Pierre-Yves David
91f110738d bundle2: prefix all unbundling debug message with 'bundle2-input:'
This make the origin of the message more explicit.
2015-05-26 20:40:21 -07:00
Pierre-Yves David
57e3ddc76b bundle2: introduce a specific function for debug messages while unbundling
The bundling process is very verbose, we would like to be able to hide such
output behind a configuration flag and have it more explicitly referencing
bundle2. The first step is to gather all these messages in a dedicated function.
2015-05-26 22:48:52 -07:00
Pierre-Yves David
b6c9526df1 bundle2: add an informative comment to the capability dict
It is fairly easy to get confused by capabilities "missing" from this dict. We
make it clear the dict is not the whole story.
2015-05-28 10:00:22 -07:00
Pierre-Yves David
01590fd818 bundle2: handle new line in 'outdebug' function
Now that we have a prefix, it make sense to assume all output will be on a
single line.
2015-05-26 23:02:19 -07:00
Pierre-Yves David
106d2910c2 bundle2: prefix all bundling debug messages with 'bundle2-ouput:'
This makes the origin of the message more explicit.
2015-05-26 22:57:35 -07:00
Pierre-Yves David
6a3212b3f4 bundle2: introduce a specific function for bundling debug message
The bundling process is very verbose, we would like to be able to hide such
output behind a configuration flag and have it more explicitly referencing
bundle2. The first step is to gather all these messages in a dedicated
function.

The same gathering will be later do for debug message issue by unbundling.
2015-05-26 22:49:03 -07:00
Pierre-Yves David
886a130d51 bundle2: use BaseException in bundle2
We can ensure we fail over properly in more cases.
2015-05-18 13:23:14 -05:00
Pierre-Yves David
e5b26a2e94 bundle2: disable ouput capture unless we use http (issue4613 issue4615)
The current bundle2 processing was capturing all output. This is nice as it
provide better meta data about what output what, but this was changing two
things:

1) adding a prefix "remote: " to "other" output during local push (issue4613)
2) local and ssh push does not provide real time output anymore (issue4615)

As we are unsure about what form should be used in (1) and how to solve (2) we
disable output capture in this two cases. Output capture can be forced using an
experimental option.
2015-04-28 17:38:02 -07:00
Pierre-Yves David
1dc90191f8 bundle2: also save output when error happens during part processing
Until this changeset, we were only able to save output if an error happened
during the 'transaction.close()' phase. If the 'processbundle' call raised an
exception, the 'bundleoperation' object was never returned, so the reply bundle
was never accessible and no output could be salvaged. We introduce a quick (but
not very elegant) fix to gain access to any reply created during the processing.

This conclude this output related series. We should hopefully be able client-side to see the
whole server output, in a proper order.

The code is now complex enough that a refactoring of it would make sense on
default.
2015-04-23 16:36:18 +01:00
Pierre-Yves David
1e8ec29191 bundle2: also capture hook output during processing
External hook used to directly write on stdout and stderr. As a result their
output was not captured by the bundle2 processing. This resulted in confusing
out of order output on the client side. We are now capturing hooks output in
this context.
2015-04-23 17:03:58 +01:00
Pierre-Yves David
dcc9ae4956 bundle2: issue remote output as "status" (issue4612)
Remote output should be silenced by --quiet. The issue was found while running
`test-largefiles-cache.t` so it will get tested once we switch bundle2 by
default.
2015-04-24 00:46:48 +01:00
Pierre-Yves David
2d01ad7c2e bundle2: store the salvaged output on the exception object
The re-handling of output is happening in some 'unbundle' callers. We have to
transmit the output information to this place so we stick it on the exception.

This is the third step in our quest for preserving the server output on error
(issue4594). We want to be able to copy the output part from the aborted reply
into the exception bundle.
2015-04-16 03:17:01 -04:00
Pierre-Yves David
9291c81ebf bundle2: add a 'salvageoutput' method on bundle20
This method returns a copy of all 'output' parts added to the bundler.

This is the second step in our quest for preserving the server output on error
(issue4594). We want to be able to copy the output parts from the aborted reply
into the exception bundle.

The function will be used in a later patch.
2015-04-16 03:16:04 -04:00
Pierre-Yves David
ff72f63d50 bundle2: add a 'copy' method on parts
This is the first step in our quest for preserving the server output on error
(issue4594). We want to be able to copy the output parts from the aborted reply
into the exception bundle.

The function will be used in a later patch.
2015-04-16 03:15:28 -04:00
Pierre-Yves David
3c016842a8 bundle2: flush output in a part in all cases
We want to preserve output even when the unbundling fails (eg: hook output). So
we must make sure that everything we have is flushed into the reply bundle.

(This is related to issue4594)
2015-04-11 17:30:45 -04:00
Pierre-Yves David
f105df9465 bundle2: fix names for error part handler
The name is not very important but copy paste banshee got there. We make
distinctive name.
2015-04-11 16:55:14 -04:00
Pierre-Yves David
c24d1f37c9 obsolete: experimental flag to get debug about obsmarkers exchange
The obsolescence markers exchange is still experimental. We (developer) need
more information about what is going on. I'm adding an experimental flag to add
display the amount of data exchanged during bundle2 exchanges.
2015-04-14 11:44:04 -04:00
Pierre-Yves David
af7d20b000 bundle2: rename format, parts and config to final names
It is finally time to freeze the bundle2 format! To do so we:
- rename HG2Y to HG20,
- drop "b2x:" prefix from all part names,
- rename capability to "bundle2-exp" to "bundle2"
- rename the hook flag from 'bundle2-exp' to 'bundle2'
2015-04-09 16:25:48 -04:00
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
Pierre-Yves David
29c25aabd5 bundle2: ignore advisory part with unknown parameters
Advisory parts are advisory. If a handler exists but does not support the
proper parameters, we can safely ignore it.

Test has been updated to include this case.
2014-05-27 12:16:45 -07:00
Pierre-Yves David
da0446d1b9 bundle2: enforce all parameters in a part to be handled
Once we picked a handler, we check that all mandatory parameter keys are
properly supported. If not we raise an exception.

We added a test for this case.

The code now fails for any part with unknown mandatory parameters. We will
ignore such errors for advisory parts in a later changeset.
2014-05-27 12:01:00 -07:00
Pierre-Yves David
5b7edfc76e bundle2: declare supported parameters for all handlers
We now update all existing handlers with the supported parameters information.
2014-05-28 11:40:07 -07:00
Pierre-Yves David
3e4ee45f47 bundle2: make it possible to declare params handled by a part handler
If we are to enforce the mandatory aspect of parameter, we need a way to
discover what a handler supports. The best option we end up with is this a simple
declaration of known parameters at registration time.

We simply plug the list of parameters on the function object because Python lets
us do that and there is no benefit for a more complicated way.

One of the handlers is updated for example and testing.
2014-05-27 11:49:48 -07:00
Pierre-Yves David
1b80836a48 bundle2: support transmission of params error over the wire
We picked a null character to split each parameter during the transfer. This is
fragile if the same character is used in parameter name. However other
codes will already behave in a strange way in that case, so we are not
introducing any regression. A better format may be picked for the final
version of the protocol.
2014-05-28 15:57:23 -07:00
Pierre-Yves David
72ac6a7248 bundle2: introduce a parttype attribute to BundleValueError
We will use the Exception for more that just unknown part type.
2014-05-28 15:51:19 -07:00
Pierre-Yves David
b5c6c1b880 bundle2: rename b2x:error:unknownpart to b2x:error:unsupportedcontent
This is a backward compatibility breakage per se. But bundle2 was explicitly
flagged as experimental, and this is one an error path anyway. So the worse
possible outcome from this change is to still have a crash but with a different
message.
2014-05-27 10:32:07 -07:00
Pierre-Yves David
d9f1652a77 bundle2: move exception classes into the error module
Exceptions should have known their place.
2014-05-28 15:31:05 -07:00
Pierre-Yves David
08bcb101f2 bundle2: rename UnknownPartError to BundleValueError
We are going to raise exceptions for a wider range of cases: unsupported
mandatory stream and part parameters.  We rename the exception with a wider
name.
2014-05-28 14:22:24 -07:00
Pierre-Yves David
096f428e53 bundle2: expose mandatory params in a mandatorykeys attribute
We expose all keys that MUST be processed in ``part.mandatorykeys``. This makes
it much easier to access the information. Enforcement of the mandatory
parameters is coming in later changesets.
2014-05-23 20:23:54 -07:00
Pierre-Yves David
467e401b10 bundle2: use the new `part.params` dictionary
We use the new ``part.params`` dictionary to access the value of parameters instead of
creating one from the part's attributes.
2014-05-26 18:45:43 -07:00
Pierre-Yves David
75a728d5f5 bundle2: introduce a `params` dictionary on unbundled parts
This exposes all parameters the part received into a ``part.params`` dictionary.
This should be much easier to use.

This dictionary itself does not expose the mandatory or advisory aspect of
parameters, but no current users of bundle2 actually enforce any of this logic.
Coming changesets will improve this aspect.
2014-05-23 17:26:57 -07:00
Pierre-Yves David
ecdd6aaf9e bundle2: make sure unbundled part param are read-only
My old uncle Robert once trusted an API user. We never saw him again.
2014-05-23 17:17:39 -07:00
Pierre-Yves David
ee0bc34f9d bundle2: introduce an `_initparams` method
The handling of parameters will become much more sophisticated in the coming
changesets. So we extract the logic in a function to not pollute the generic
logic.
2014-05-28 10:04:02 -07:00
Pierre-Yves David
17c8c5b1eb bundle2: forbid duplicate parameter keys
No rules were specified about parameter key uniqueness. We document that keys
should be unique and document it. This opens the way to a more friendly (read
dictionary like) way to access value of parameters in the code.
2014-05-22 12:52:09 -07:00
Pierre-Yves David
7023ca67e5 bundle2: update part creators to `addparam` when relevant
In some cases, the use of ``addparam`` makes code much clearer.
2014-05-23 16:46:30 -07:00
Pierre-Yves David
76215be0d0 bundle2: introduce a `addparam` method on part
We make it easier to add new parameters after the part creation. As for the
``data`` attribute we make sure the part generation has not begun yet.
2014-05-22 11:38:40 -07:00
Pierre-Yves David
3c42f04f04 bundle2: the ability to set `data` attribute of the part is now official
We make it safe to set the data attribute after part creation. It is an allowed
operation as long as the part has not started to be generated.
2014-05-22 11:21:26 -07:00
Pierre-Yves David
2ece793be7 bundle2: introduce a ReadOnlyPartError exception
As we will introduce functions to alter already created parts, we need a proper
exception to raise when code tries to alter a part that cannot be altered anymore.
2014-05-24 16:08:05 -07:00
Pierre-Yves David
4248dc3512 bundle2: warn about error during initialization in `newpart` docstring
As we are moving toward being able to alter a part after its creation, we need
to make the implication of the part being already part of the bundle2 clear.
2014-05-23 16:20:30 -07:00
Pierre-Yves David
3b20774c58 bundle2: track life cycle of parts
We introduce a ``_generated`` attribute on parts. Coming changesets will
make it easier to update a part's contents after its creation. We need a way to track
if the part is still open to modification or if it is currently being generated
and should not be touched anymore.

As a bonus, we can now detect and crash if someone manages to write bogus code
to get a part generated twice.
2014-05-22 11:14:02 -07:00
Pierre-Yves David
121338752e bundle2: update all `addpart callers to newpart`
The new method is what we want in all current cases.
2014-05-23 15:59:19 -07:00
Pierre-Yves David
a618942ce3 bundle2: have `newpart` automatically add the part to the bundle
The created part is automatically added to the bundle as this is most certainly
the intent of the user code.
2014-05-23 15:54:18 -07:00
Pierre-Yves David
637e050d21 bundle2: add a `newpart method to bundle20`
Creating new parts is the most common operation people do when exposed to a
bundler. We create a dedicated method on the bundler object for it. This will
simplify the code and also avoid having to import the ``mercurial.bundle2``
module in multiple places.

One part creators have been updated for testing purpose.
2014-05-23 15:45:46 -07:00
Pierre-Yves David
6480c98ec3 bundle2: small doc update on the bundler
The `bundle20` class contains methods to help define the content and methods
to generate the actual stream. We add small doc headers to help distinguish
between the two.
2014-05-22 10:48:37 -07:00
Pierre-Yves David
b4b66836e8 bundle2: gracefully handle PushRaced error during unbundle
Same drill again. We catch the PushRaced error, check if it cames from
a bundle2 processing, if so we turn it into a bundle2 with a part
transporting error information to be reraised client side.
2014-04-21 17:51:58 -07:00
Pierre-Yves David
eb0866dfad bundle2: add an error message to push race error
Errors with no explanations makes my uncle Bob sad.
2014-04-21 20:04:54 -07:00
Pierre-Yves David
716843e5d3 bundle2: fix raising errors during heads checking
If the heads on the server differ from the ones reported seen by the client at
bundle time, we raise a PushRaced exception. However, the part raising the
exception was broken.

To fix it, we move the PushRaced class in the error module so it can be
accessible everywhere without an import cycle.

A test is also added to prevent regression.
2014-04-21 18:59:09 -07:00
Pierre-Yves David
f5bff0c11f bundle2: gracefully handle UnknownPartError during unbundle
Same as for Abort error, we catch the error, encode it into a bundle2 reply
(expected by the client) and stream this reply. The client processing of the
error will raise the exception again.
2014-04-21 16:02:03 -07:00
Pierre-Yves David
8265035568 bundle2: use a more specific UnknownPartError when no handler is found
KeyError is very generic, we need something more specific for proper error
handling.
2014-04-21 19:42:40 -07:00
Pierre-Yves David
3085949133 bundle2: gracefully handle abort during unbundle
Clients expect a bundle2 reply to their bundle2 submission. So we
catch the Abort error and turn it into a bundle2 containing a part
transporting the exception data. The unbundling of this reply will
raise the error again.
2014-04-21 15:48:52 -07:00
Pierre-Yves David
3385347d38 bundle2: decorate exception raised during bundle processing
This is a small hack to help us do some graceful error handling in bundle2
without major refactoring. See embedded comment for details.
2014-04-22 11:22:41 -07:00
Pierre-Yves David
fd614e4d04 bundle2: move all parts into a bx2 namespace
All currently core parts are moved to a `bx2` namespace (for "bundle 2
experimental"). This should avoid conflicts between the final stable
format and the one about to be released.
2014-04-17 15:45:12 -04:00
Pierre-Yves David
7e653a9c0f bundle2: use HG2X in the header
The current implementation of bundle2 is still very experimental and the 3.0
freeze is yesterday. The current bundle2 format has never been field-tested, so
we rename the header to HG2X. This leaves the HG20 header available for real
usage as a stable format in Mercurial 3.1.

We won't guarantee that future mercurial versions will keep supporting this
`HG2X` format.
2014-04-17 15:27:54 -04:00
Pierre-Yves David
9bb9dc1703 bundle2: capabilities encoding 2014-04-17 01:44:53 -04:00
Pierre-Yves David
211041404c bundle2: extract capabilities decoding
We'll need to reuse this in more places (at least pull and push).
2014-04-17 01:09:05 -04:00
Pierre-Yves David
f2ead829c7 bundle2: protect capabilities name and values with url quoting
This lift limitations of the text based encoding.
2014-04-17 01:03:33 -04:00
Pierre-Yves David
f48478a77f bundle2: support for capabilities with values
The capabilities attributes of `bundle20` is now a dictionary and the reply caps
can encode capabilities with values.
2014-04-17 11:44:49 -04:00
Pierre-Yves David
b4784becd2 bundle2: add capabilities support in replycaps part
This part now contains a list of supported capabilities.
2014-04-17 11:32:30 -04:00
Pierre-Yves David
e273dad6f6 bundle2: adds a capabilities attribute on bundler20
This attribute conveys the capabilities supported by the destination of the
bundle. It is used to decide which parts to include in the bundle.

This is currently a set but will probably be turned into a dictionary to allow
capabilities with values.
2014-04-16 23:55:59 -04:00
Pierre-Yves David
1c2cd8594e bundle2: include stderr when capturing handlers output
We do not discriminate between stdout and stderr yet. But this will do for now.
2014-04-16 23:18:27 -04:00
Pierre-Yves David
53ffee95a2 bundle2: capture remote stdout while unbundling
When a reply is built, the bundle processing will capture the output of each
handler and sends it to the client in a dedicated part.

As a side effect, this add a "remote: " prefix to destination output on local
push. This is considered okay for now as:

1. bundle2 is still experimental,
2. Matt said he could be okay to change output for bundle2,
3. This keeps the implementation simple.

This changeset does it for stdout only. stderr will be done in a future changeset.
2014-04-16 14:22:24 -04:00
Pierre-Yves David
f7d4dc294b bundle2: introduce replycaps part for on-demand reply
The bundle2 processing does not create a bundle2 reply by default anymore.  It
is only done if the client requests it with a `replycaps` part. This part is
called `replycaps` as it will eventually contain data about which bundle2
capabilities are supported by the client.

We have to add a flag to the test command to control whether a reply is
generated or not.
2014-04-16 14:09:35 -04:00
Pierre-Yves David
88fa4f238f bundle2: use an official iterparts method to unbundle parts
Explicit is better than implicit.
2014-04-16 18:41:48 -04:00
Pierre-Yves David
4ba3ed7539 bundle2: make header reading optional
The `readbundle` function will consume the 4 first bytes to dispatch between
various unbundler. We introduce a way to inform `unbundle20` that the header
has been read and it can be trusted.
2014-04-15 13:54:54 -04:00
Pierre-Yves David
a214f21ef0 bundle2: use headerless HG10UN stream in changegroup
Using `readbundle` in the part handlers creates a circular import hell. We are
now using a simple `HG10UN` stream with no header. Some parameters may
later be introduced on the part to change parameter.

Producers are updated as well.
2014-04-14 14:46:32 -04:00
Pierre-Yves David
6661b09fe1 bundle2: add a "check:heads" handler
This part is intended to hold the same role as the `heads` argument of the
unbundle function. The client fill it with the known heads at bundle time and
the server will abort if its heads changed.
2014-04-11 06:43:01 -07:00
Mads Kiilerich
0e8795ccd6 spelling: fixes from spell checker 2014-04-13 19:01:00 +02:00
Pierre-Yves David
75b8e03941 bundle2: directly feed part to readbundle
Now that part payload can be read like a stream, we can directly use it to feed
the unbundle10 process.
2014-04-12 00:38:15 -04:00
Pierre-Yves David
acbb6d4494 bundle2: lazy unbundle of part payload
The `unbundle` part gains a `read` method to retrieve payload content.
This method behaves as a python file-like read method.

The bundle-processing code is updated to make sure a part is fully consumed before
another one is extracted.

Test output changes because the debug output is even more interleaved now.
2014-04-11 16:05:22 -04:00
Pierre-Yves David
1726c7ed72 bundle2: move unpackheader closure into the class
With the same argument as the other one, we move this closure into the
`unbundlepart` class.
2014-04-11 15:47:38 -04:00
Pierre-Yves David
a5bcb69da6 bundle2: move the fromheader closure into the class itself
The class is now directly related to this header data. We can sanely move it on
the class.

I do not like closures very much...
2014-04-11 15:46:09 -04:00
Pierre-Yves David
0819f89a04 bundle2: add an unbundle part responsible from unbundling part
We have a new unbundle class and it is now responsible from extracting its own
data. The top level bundler only extracts the header (to detect an end of stream
marker) then leaves everything else to the `unbundlepart` class. The ultimate
goal is to have `unbundlepart` responsible for lazily extracting its payload.

This is mostly code movement.
2014-04-11 15:43:16 -04:00
Pierre-Yves David
10657d6382 bundle2: extract stream/unpack logic in an unpackermixin
The coming `unbundlepart` will need the same kind of method than `unbundle20`
for unpacking data from the stream. We extract them into a mixin class before
the creation of `unbundlepart`.
2014-04-11 15:19:54 -04:00
Pierre-Yves David
e5b4ced868 bundle2: rename part to bundlepart
We are going to introduce an `unbundlepart` dedicated to reading bundle. So we
need to rename the one used to create bundle. Even if dedicated to creation, this
is still used for unbundling until we get the new class.
2014-04-11 07:36:14 -07:00
Pierre-Yves David
ef4a1b021a bundle2: comment to clarify why the handler call is where it is
The reason why it is here is not obvious. I'm the one who wrote it there in the
first place and almost moved it 2 weeks later.
2014-04-11 16:43:01 -04:00
Pierre-Yves David
be93303ad1 bundle2: support chunk iterator as part data
When the `part.data` attribute is an iterator, we assume it is an iterator of
chunks and use it.

We use a chunkbuffer to yield chunks of 4096 bytes.

The tests are updated to use this feature.
2014-04-11 08:04:16 -07:00
Pierre-Yves David
2cfe67ddd2 bundle2: extract a _payloadchunks method for part
We are preparing streaming capability for part. So the generation of payload
chunk will becomes more complex. We extract this part in its own function before
any changes.
2014-04-10 12:33:20 -07:00
Pierre-Yves David
c4bb78d90c bundle2: use reply part to return result of addchangegroup
We now have an official way to return the result of addchangegroup. The tests are
updated to check that the return bundle is properly created. It will be used
when push is bundle2 enabled.
2014-03-25 15:05:11 -07:00
Pierre-Yves David
e46e61d8b1 bundle2: produce a bundle2 reply
We do not know yet what kind of data future features and extensions will need to
exchange. To handle that, bundle2 allows to send arbitrary content to the
server. As a consequence, we need to be able to reply arbitrary content to the
client. And, we can use bundle2 to transmit those arbitrary data.

When a client will push a bundle2 to the server, the server will reply with a
bundle2 itself.

This changeset installs the first stone of this logic and test it.
2014-04-04 14:24:11 -07:00
Pierre-Yves David
90cfb42a5c bundle2: add reply awareness to unbundlerecords
We need an efficient way to handle bundle replies. The unbundle records class is
extended to carry such data.
2014-04-11 08:24:59 -07:00
Pierre-Yves David
311fe283fd bundle2: add an integer id to part
For sending response to a pushed bundle, we need to link reply parts to request
part. We introduce a part id for this purpose. This is a 32 bit unique
integer stored in the header.
2014-04-01 00:07:17 -07:00
Pierre-Yves David
ece6aaecdb bundle2: make it possible have a global transaction for the unbundling
We use the `gettransaction` method approach already used for pull. We
need this because we do not know beforehand if the bundle needs a
transaction to be created. And (1) we do not want to create a
transaction for nothing. (2) Some bundle2 bundles may be read-only and
do not require any lock or transaction to be held.
2014-04-02 23:56:49 -07:00
Pierre-Yves David
11a11c0625 bundle2: first crude version of bundling changeset with bundle2
The current changegroup format is put in a "changegroup" part and processed by
an appropriate handlers.

This is not production ready code, but let us start smoke testing.
2014-03-24 19:37:59 -07:00
Pierre-Yves David
5ab0b5facf bundle2: record processing results in the bundleoperation object
Part handlers can now add records to the `bundleoperation` object. This can be
used to help other parts or to let the caller of the unbundling process react
to the results.
2014-04-02 22:37:50 -07:00