path: root/upload-pack.c
diff options
authorJonathan Tan <>2021-05-04 21:16:01 (GMT)
committerJunio C Hamano <>2021-05-05 01:41:29 (GMT)
commit9c1e657a8fd26fa3ed8d13fb8c796cef8db8b124 (patch)
tree79ed7a1763a89a1be268af86dda6110a2d0c2a1a /upload-pack.c
parent6871d0cec62dc12d0c5f7390eee8a80614919578 (diff)
fetch: teach independent negotiation (no packfile)
Currently, the packfile negotiation step within a Git fetch cannot be done independent of sending the packfile, even though there is at least one application wherein this is useful. Therefore, make it possible for this negotiation step to be done independently. A subsequent commit will use this for one such application - push negotiation. This feature is for protocol v2 only. (An implementation for protocol v0 would require a separate implementation in the fetch, transport, and transport helper code.) In the protocol, the main hindrance towards independent negotiation is that the server can unilaterally decide to send the packfile. This is solved by a "wait-for-done" argument: the server will then wait for the client to say "done". In practice, the client will never say it; instead it will cease requests once it is satisfied. In the client, the main change lies in the transport and transport helper code. fetch_refs_via_pack() performs everything needed - protocol version and capability checks, and the negotiation itself. There are 2 code paths that do not go through fetch_refs_via_pack() that needed to be individually excluded: the bundle transport (excluded through requiring smart_options, which the bundle transport doesn't support) and transport helpers that do not support takeover. If or when we support independent negotiation for protocol v0, we will need to modify these 2 code paths to support it. But for now, report failure if independent negotiation is requested in these cases. Signed-off-by: Jonathan Tan <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'upload-pack.c')
1 files changed, 13 insertions, 5 deletions
diff --git a/upload-pack.c b/upload-pack.c
index e19583a..b432ef0 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -103,6 +103,7 @@ struct upload_pack_data {
unsigned use_ofs_delta : 1;
unsigned no_progress : 1;
unsigned use_include_tag : 1;
+ unsigned wait_for_done : 1;
unsigned allow_filter : 1;
unsigned allow_filter_fallback : 1;
unsigned long tree_filter_max_depth;
@@ -1496,6 +1497,10 @@ static void process_args(struct packet_reader *request,
data->done = 1;
+ if (!strcmp(arg, "wait-for-done")) {
+ data->wait_for_done = 1;
+ continue;
+ }
/* Shallow related arguments */
if (process_shallow(arg, &data->shallows))
@@ -1578,7 +1583,7 @@ static int send_acks(struct upload_pack_data *data, struct oid_array *acks)
- if (ok_to_give_up(data)) {
+ if (!data->wait_for_done && ok_to_give_up(data)) {
/* Send Ready */
packet_writer_write(&data->writer, "ready\n");
return 1;
@@ -1668,10 +1673,13 @@ int upload_pack_v2(struct repository *r, struct strvec *keys,
process_args(request, &data);
- if (! {
+ if (! && !data.wait_for_done) {
- * Request didn't contain any 'want' lines,
- * guess they didn't want anything.
+ * Request didn't contain any 'want' lines (and
+ * the request does not contain
+ * "wait-for-done", in which it is reasonable
+ * to just send 'have's without 'want's); guess
+ * they didn't want anything.
state = FETCH_DONE;
} else if ( {
@@ -1723,7 +1731,7 @@ int upload_pack_advertise(struct repository *r,
int allow_sideband_all_value;
char *str = NULL;
- strbuf_addstr(value, "shallow");
+ strbuf_addstr(value, "shallow wait-for-done");
if (!repo_config_get_bool(the_repository,