Skip to content

Commit 3145ea9

Browse files
bmwillgitster
authored andcommitted
upload-pack: introduce fetch server command
Introduce the 'fetch' server command. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5b872ff commit 3145ea9

File tree

5 files changed

+400
-0
lines changed

5 files changed

+400
-0
lines changed

Documentation/technical/protocol-v2.txt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,128 @@ The output of ls-refs is as follows:
199199
ref-attribute = (symref | peeled)
200200
symref = "symref-target:" symref-target
201201
peeled = "peeled:" obj-id
202+
203+
fetch
204+
~~~~~~~
205+
206+
`fetch` is the command used to fetch a packfile in v2. It can be looked
207+
at as a modified version of the v1 fetch where the ref-advertisement is
208+
stripped out (since the `ls-refs` command fills that role) and the
209+
message format is tweaked to eliminate redundancies and permit easy
210+
addition of future extensions.
211+
212+
Additional features not supported in the base command will be advertised
213+
as the value of the command in the capability advertisement in the form
214+
of a space separated list of features: "<command>=<feature 1> <feature 2>"
215+
216+
A `fetch` request can take the following arguments:
217+
218+
want <oid>
219+
Indicates to the server an object which the client wants to
220+
retrieve. Wants can be anything and are not limited to
221+
advertised objects.
222+
223+
have <oid>
224+
Indicates to the server an object which the client has locally.
225+
This allows the server to make a packfile which only contains
226+
the objects that the client needs. Multiple 'have' lines can be
227+
supplied.
228+
229+
done
230+
Indicates to the server that negotiation should terminate (or
231+
not even begin if performing a clone) and that the server should
232+
use the information supplied in the request to construct the
233+
packfile.
234+
235+
thin-pack
236+
Request that a thin pack be sent, which is a pack with deltas
237+
which reference base objects not contained within the pack (but
238+
are known to exist at the receiving end). This can reduce the
239+
network traffic significantly, but it requires the receiving end
240+
to know how to "thicken" these packs by adding the missing bases
241+
to the pack.
242+
243+
no-progress
244+
Request that progress information that would normally be sent on
245+
side-band channel 2, during the packfile transfer, should not be
246+
sent. However, the side-band channel 3 is still used for error
247+
responses.
248+
249+
include-tag
250+
Request that annotated tags should be sent if the objects they
251+
point to are being sent.
252+
253+
ofs-delta
254+
Indicate that the client understands PACKv2 with delta referring
255+
to its base by position in pack rather than by an oid. That is,
256+
they can read OBJ_OFS_DELTA (ake type 6) in a packfile.
257+
258+
The response of `fetch` is broken into a number of sections separated by
259+
delimiter packets (0001), with each section beginning with its section
260+
header.
261+
262+
output = *section
263+
section = (acknowledgments | packfile)
264+
(flush-pkt | delim-pkt)
265+
266+
acknowledgments = PKT-LINE("acknowledgments" LF)
267+
(nak | *ack)
268+
(ready)
269+
ready = PKT-LINE("ready" LF)
270+
nak = PKT-LINE("NAK" LF)
271+
ack = PKT-LINE("ACK" SP obj-id LF)
272+
273+
packfile = PKT-LINE("packfile" LF)
274+
*PKT-LINE(%x01-03 *%x00-ff)
275+
276+
acknowledgments section
277+
* If the client determines that it is finished with negotiations
278+
by sending a "done" line, the acknowledgments sections MUST be
279+
omitted from the server's response.
280+
281+
* Always begins with the section header "acknowledgments"
282+
283+
* The server will respond with "NAK" if none of the object ids sent
284+
as have lines were common.
285+
286+
* The server will respond with "ACK obj-id" for all of the
287+
object ids sent as have lines which are common.
288+
289+
* A response cannot have both "ACK" lines as well as a "NAK"
290+
line.
291+
292+
* The server will respond with a "ready" line indicating that
293+
the server has found an acceptable common base and is ready to
294+
make and send a packfile (which will be found in the packfile
295+
section of the same response)
296+
297+
* If the server has found a suitable cut point and has decided
298+
to send a "ready" line, then the server can decide to (as an
299+
optimization) omit any "ACK" lines it would have sent during
300+
its response. This is because the server will have already
301+
determined the objects it plans to send to the client and no
302+
further negotiation is needed.
303+
304+
packfile section
305+
* This section is only included if the client has sent 'want'
306+
lines in its request and either requested that no more
307+
negotiation be done by sending 'done' or if the server has
308+
decided it has found a sufficient cut point to produce a
309+
packfile.
310+
311+
* Always begins with the section header "packfile"
312+
313+
* The transmission of the packfile begins immediately after the
314+
section header
315+
316+
* The data transfer of the packfile is always multiplexed, using
317+
the same semantics of the 'side-band-64k' capability from
318+
protocol version 1. This means that each packet, during the
319+
packfile data stream, is made up of a leading 4-byte pkt-line
320+
length (typical of the pkt-line format), followed by a 1-byte
321+
stream code, followed by the actual data.
322+
323+
The stream code can be one of:
324+
1 - pack data
325+
2 - progress messages
326+
3 - fatal error message just before stream aborts

serve.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "argv-array.h"
77
#include "ls-refs.h"
88
#include "serve.h"
9+
#include "upload-pack.h"
910

1011
static int always_advertise(struct repository *r,
1112
struct strbuf *value)
@@ -54,6 +55,7 @@ struct protocol_capability {
5455
static struct protocol_capability capabilities[] = {
5556
{ "agent", agent_advertise, NULL },
5657
{ "ls-refs", always_advertise, ls_refs },
58+
{ "fetch", always_advertise, upload_pack_v2 },
5759
};
5860

5961
static void advertise_capabilities(void)

t/t5701-git-serve.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_expect_success 'test capability advertisement' '
99
version 2
1010
agent=git/$(git version | cut -d" " -f3)
1111
ls-refs
12+
fetch
1213
0000
1314
EOF
1415

0 commit comments

Comments
 (0)