From: Junio C Hamano Date: Fri, 30 Mar 2018 01:27:21 +0000 (-0700) Subject: Merge branch 'bw/protocol-v2' into next X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/be7f9987123d73df9bde6684ba5f5a79f37b453e Merge branch 'bw/protocol-v2' into next The beginning of the next-gen transfer protocol. * bw/protocol-v2: (35 commits) remote-curl: don't request v2 when pushing remote-curl: implement stateless-connect command http: eliminate "# service" line when using protocol v2 http: don't always add Git-Protocol header http: allow providing extra headers for http requests remote-curl: store the protocol version the server responded with remote-curl: create copy of the service name pkt-line: add packet_buf_write_len function transport-helper: introduce stateless-connect transport-helper: refactor process_connect_service transport-helper: remove name parameter connect: don't request v2 when pushing connect: refactor git_connect to only get the protocol version once fetch-pack: support shallow requests fetch-pack: perform a fetch using v2 upload-pack: introduce fetch server command push: pass ref prefixes when pushing fetch: pass ref prefixes when fetching ls-remote: pass ref prefixes when requesting a remote's refs transport: convert transport_get_remote_refs to take a list of ref prefixes ... --- be7f9987123d73df9bde6684ba5f5a79f37b453e diff --cc builtin/clone.c index 101c27a593,4db3079acc..d4dd3b8f73 --- a/builtin/clone.c +++ b/builtin/clone.c @@@ -1125,16 -1101,10 +1125,16 @@@ int cmd_clone(int argc, const char **ar transport_set_option(transport, TRANS_OPT_UPLOADPACK, option_upload_pack); - if (transport->smart_options && !deepen) + if (filter_options.choice) { + transport_set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, + filter_options.filter_spec); + transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1"); + } + + if (transport->smart_options && !deepen && !filter_options.choice) transport->smart_options->check_self_contained_and_connected = 1; - refs = transport_get_remote_refs(transport); + refs = transport_get_remote_refs(transport, NULL); if (refs) { mapped_refs = wanted_peer_refs(refs, refspec); diff --cc builtin/fetch-pack.c index a7bc1366ab,f9d7d0b5a5..1a1bc63566 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@@ -52,9 -53,8 +53,10 @@@ int cmd_fetch_pack(int argc, const cha struct fetch_pack_args args; struct oid_array shallow = OID_ARRAY_INIT; struct string_list deepen_not = STRING_LIST_INIT_DUP; + struct packet_reader reader; + fetch_if_missing = 0; + packet_trace_identity("fetch-pack"); memset(&args, 0, sizeof(args)); diff --cc fetch-pack.h index 3e224a1822,7afca73056..6afa08b48b --- a/fetch-pack.h +++ b/fetch-pack.h @@@ -3,7 -3,7 +3,8 @@@ #include "string-list.h" #include "run-command.h" + #include "protocol.h" +#include "list-objects-filter-options.h" struct oid_array; diff --cc remote-curl.c index a7c4c9b5ff,595447b16e..4f779eee54 --- a/remote-curl.c +++ b/remote-curl.c @@@ -13,7 -14,7 +14,8 @@@ #include "credential.h" #include "sha1-array.h" #include "send-pack.h" + #include "protocol.h" +#include "quote.h" static struct remote *remote; /* always ends with a trailing slash */ diff --cc transport.c index b9dfa11bd2,342db492ca..90a9eb518d --- a/transport.c +++ b/transport.c @@@ -238,21 -252,29 +261,32 @@@ static int fetch_refs_via_pack(struct t data->options.check_self_contained_and_connected; args.cloning = transport->cloning; args.update_shallow = data->options.update_shallow; + args.from_promisor = data->options.from_promisor; + args.no_dependents = data->options.no_dependents; + args.filter_options = data->options.filter_options; + args.stateless_rpc = transport->stateless_rpc; - if (!data->got_remote_heads) { - connect_setup(transport, 0); - get_remote_heads(data->fd[0], NULL, 0, &refs_tmp, 0, - NULL, &data->shallow); - data->got_remote_heads = 1; + if (!data->got_remote_heads) + refs_tmp = get_refs_via_connect(transport, 0, NULL); + + switch (data->version) { + case protocol_v2: + refs = fetch_pack(&args, data->fd, data->conn, + refs_tmp ? refs_tmp : transport->remote_refs, + dest, to_fetch, nr_heads, &data->shallow, + &transport->pack_lockfile, data->version); + break; + case protocol_v1: + case protocol_v0: + refs = fetch_pack(&args, data->fd, data->conn, + refs_tmp ? refs_tmp : transport->remote_refs, + dest, to_fetch, nr_heads, &data->shallow, + &transport->pack_lockfile, data->version); + break; + case protocol_unknown_version: + BUG("unknown protocol version"); } - refs = fetch_pack(&args, data->fd, data->conn, - refs_tmp ? refs_tmp : transport->remote_refs, - dest, to_fetch, nr_heads, &data->shallow, - &transport->pack_lockfile); close(data->fd[0]); close(data->fd[1]); if (finish_connect(data->conn)) diff --cc upload-pack.c index 4a82602be5,4c9428c2db..87b4d32a6e --- a/upload-pack.c +++ b/upload-pack.c @@@ -20,13 -17,8 +19,9 @@@ #include "argv-array.h" #include "prio-queue.h" #include "protocol.h" +#include "quote.h" - - static const char * const upload_pack_usage[] = { - N_("git upload-pack [] "), - NULL - }; + #include "upload-pack.h" + #include "serve.h" /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@@ -770,55 -860,15 +878,22 @@@ static void receive_needs(void if (!line) break; - if (skip_prefix(line, "shallow ", &arg)) { - struct object_id oid; - struct object *object; - if (get_oid_hex(arg, &oid)) - die("invalid shallow line: %s", line); - object = parse_object(&oid); - if (!object) - continue; - if (object->type != OBJ_COMMIT) - die("invalid shallow object %s", oid_to_hex(&oid)); - if (!(object->flags & CLIENT_SHALLOW)) { - object->flags |= CLIENT_SHALLOW; - add_object_array(object, NULL, &shallows); - } + if (process_shallow(line, &shallows)) continue; - } - if (skip_prefix(line, "deepen ", &arg)) { - char *end = NULL; - depth = strtol(arg, &end, 0); - if (!end || *end || depth <= 0) - die("Invalid deepen: %s", line); + if (process_deepen(line, &depth)) continue; - } - if (skip_prefix(line, "deepen-since ", &arg)) { - char *end = NULL; - deepen_since = parse_timestamp(arg, &end, 0); - if (!end || *end || !deepen_since || - /* revisions.c's max_age -1 is special */ - deepen_since == -1) - die("Invalid deepen-since: %s", line); - deepen_rev_list = 1; + if (process_deepen_since(line, &deepen_since, &deepen_rev_list)) continue; - } - if (skip_prefix(line, "deepen-not ", &arg)) { - char *ref = NULL; - struct object_id oid; - if (expand_ref(arg, strlen(arg), &oid, &ref) != 1) - die("git upload-pack: ambiguous deepen-not: %s", line); - string_list_append(&deepen_not, ref); - free(ref); - deepen_rev_list = 1; + if (process_deepen_not(line, &deepen_not, &deepen_rev_list)) continue; - } + + if (skip_prefix(line, "filter ", &arg)) { + if (!filter_capability_requested) + die("git upload-pack: filtering capability not negotiated"); + parse_list_objects_filter(&filter_options, arg); + continue; + } ++ if (!skip_prefix(line, "want ", &arg) || get_oid_hex(arg, &oid_buf)) die("git upload-pack: protocol error, "