fetch-pack, index-pack, transport: partial clone

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Dec 8, 2017 at 15:58 UTC 640d8b72feaae0b96d5faa663ad624963e416d54
6 files changed +33
builtin/fetch-pack.c
+4
@@ -153,6 +153,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
153 args.no_dependents = 1;
154 continue;
155 }
156 + if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
157 + parse_list_objects_filter(&args.filter_options, arg);
158 + continue;
159 + }
160 usage(fetch_pack_usage);
161 }
162 if (deepen_not.nr)
fetch-pack.c
+13
@@ -29,6 +29,7 @@ static int deepen_not_ok;
29 static int fetch_fsck_objects = -1;
30 static int transfer_fsck_objects = -1;
31 static int agent_supported;
32 +static int server_supports_filtering;
33 static struct lock_file shallow_lock;
34 static const char *alternate_shallow_file;
35
@@ -379,6 +380,8 @@ static int find_common(struct fetch_pack_args *args,
380 if (deepen_not_ok) strbuf_addstr(&c, " deepen-not");
381 if (agent_supported) strbuf_addf(&c, " agent=%s",
382 git_user_agent_sanitized());
383 + if (args->filter_options.choice)
384 + strbuf_addstr(&c, " filter");
385 packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
386 strbuf_release(&c);
387 } else
@@ -407,6 +410,9 @@ static int find_common(struct fetch_pack_args *args,
410 packet_buf_write(&req_buf, "deepen-not %s", s->string);
411 }
412 }
413 + if (server_supports_filtering && args->filter_options.choice)
414 + packet_buf_write(&req_buf, "filter %s",
415 + args->filter_options.filter_spec);
416 packet_buf_flush(&req_buf);
417 state_len = req_buf.len;
418
@@ -969,6 +975,13 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
975 else
976 prefer_ofs_delta = 0;
977
978 + if (server_supports("filter")) {
979 + server_supports_filtering = 1;
980 + print_verbose(args, _("Server supports filter"));
981 + } else if (args->filter_options.choice) {
982 + warning("filtering not recognized by server, ignoring");
983 + }
984 +
985 if ((agent_feature = server_feature_value("agent", &agent_len))) {
986 agent_supported = 1;
987 if (agent_len)
fetch-pack.h
+2
@@ -3,6 +3,7 @@
3
4 #include "string-list.h"
5 #include "run-command.h"
6 +#include "list-objects-filter-options.h"
7
8 struct oid_array;
9
@@ -12,6 +13,7 @@ struct fetch_pack_args {
13 int depth;
14 const char *deepen_since;
15 const struct string_list *deepen_not;
16 + struct list_objects_filter_options filter_options;
17 unsigned deepen_relative:1;
18 unsigned quiet:1;
19 unsigned keep_pack:1;
transport-helper.c
+5
@@ -671,6 +671,11 @@ static int fetch(struct transport *transport,
671 if (data->transport_options.update_shallow)
672 set_helper_option(transport, "update-shallow", "true");
673
674 + if (data->transport_options.filter_options.choice)
675 + set_helper_option(
676 + transport, "filter",
677 + data->transport_options.filter_options.filter_spec);
678 +
679 if (data->fetch)
680 return fetch_with_fetch(transport, nr_heads, to_fetch);
681
transport.c
+4
@@ -166,6 +166,9 @@ static int set_git_option(struct git_transport_options *opts,
166 } else if (!strcmp(name, TRANS_OPT_NO_DEPENDENTS)) {
167 opts->no_dependents = !!value;
168 return 0;
169 + } else if (!strcmp(name, TRANS_OPT_LIST_OBJECTS_FILTER)) {
170 + parse_list_objects_filter(&opts->filter_options, value);
171 + return 0;
172 }
173 return 1;
174 }
@@ -236,6 +239,7 @@ static int fetch_refs_via_pack(struct transport *transport,
239 args.update_shallow = data->options.update_shallow;
240 args.from_promisor = data->options.from_promisor;
241 args.no_dependents = data->options.no_dependents;
242 + args.filter_options = data->options.filter_options;
243
244 if (!data->got_remote_heads) {
245 connect_setup(transport, 0);
transport.h
+5
@@ -4,6 +4,7 @@
4 #include "cache.h"
5 #include "run-command.h"
6 #include "remote.h"
7 +#include "list-objects-filter-options.h"
8
9 struct string_list;
10
@@ -23,6 +24,7 @@ struct git_transport_options {
24 const char *uploadpack;
25 const char *receivepack;
26 struct push_cas_option *cas;
27 + struct list_objects_filter_options filter_options;
28 };
29
30 enum transport_family {
@@ -221,6 +223,9 @@ void transport_check_allowed(const char *type);
223 */
224 #define TRANS_OPT_NO_DEPENDENTS "no-dependents"
225
226 +/* Filter objects for partial clone and fetch */
227 +#define TRANS_OPT_LIST_OBJECTS_FILTER "filter"
228 +
229 /**
230 * Returns 0 if the option was used, non-zero otherwise. Prints a
231 * message to stderr if the option is not used.