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.

--HG--
extra : rebase_source : e5ac0c58e81ac8fc28a8a69ae0bc96b33acde5f4
extra : amend_source : bf0edde8df61bdd58d4d127e41e0376644315c11
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.

--HG--
extra : rebase_source : e76de42a6ad04b0f5596c3aa901605acba218c5b
extra : amend_source : 7d6e2794d0694e53830158e54b5c54578885ebe1
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.

--HG--
extra : rebase_source : 5d48081f3acbd600d7a5370f480725c239c9ce9f
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.

--HG--
extra : rebase_source : 0071eac2d52f07e47e01b1e6ffbbd041bf2391ad
extra : amend_source : eef70dbaa4e011ebad31c6ec8518213c046d6d75
changegroup: move chunk extraction into a getchunks method of unbundle10

This code used to be in `writebundle` only. We needs to make it more broadly
available for bundle2. The "changegroup" bundle2 part has to retrieve the
binary content of changegroup stream. We moved the chunks retrieving code into
the `unbundle10` object directly and the `writebundle` code is now using that.

This split is useful for bundle2 purpose, we want to be able to easily stream
changegroup content in a part.

To keep thing simples, we kept compression out of the new methods. If it make
more sense in the future, compression may get included in this function too.

--HG--
extra : rebase_source : 5b851a3b8d3589a820de7380b03b69ce3a78736a
extra : amend_source : 6dfdc327f44f8e52e18b01df44dd9658f1480382
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.

--HG--
extra : rebase_source : e4bf433e95e0f92e1869510a36d9457b117058ad
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.

--HG--
extra : rebase_source : b14cb7fa7e035af295eeb21416f7d63c988baf0d
extra : amend_source : 04e14bc1567f04ffc26fbaf5d66760cc228c0a7d
bundle2: lazily generate the changegroup part in exchange.getbundle

Now that we have lazy generation of parts, let's use it.

--HG--
extra : amend_source : 3ea40fd70bd3af907c309c2996f233c857a7b463
bundle2: use chunkbuffer for exchange.getbundle

We can use `util.chunkbuffer` instead.

--HG--
extra : rebase_source : d4a44b9c1b64e0e14ec805afb2627c62a2cf6467
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.

--HG--
extra : rebase_source : 6f76ff48acf60ac75ecb7a53e78cb2fa03c8c3f0
extra : amend_source : 2216267a8961f2392e6cb92f892b18afc17873a6
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.

--HG--
extra : rebase_source : 867971073ebdba99a64e0114ea6289e051923684