]> granicus.if.org Git - git/commitdiff
fetch-pack, index-pack, transport: partial clone
authorJeff Hostetler <jeffhost@microsoft.com>
Fri, 8 Dec 2017 15:58:40 +0000 (15:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Dec 2017 17:58:51 +0000 (09:58 -0800)
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch-pack.c
fetch-pack.c
fetch-pack.h
transport-helper.c
transport.c
transport.h

index 15eeed7b177ace3baa21076eb0a2d493ef1caa76..795780763abf61f406e12959497c1d9c29663e00 100644 (file)
@@ -153,6 +153,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
                        args.no_dependents = 1;
                        continue;
                }
+               if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
+                       parse_list_objects_filter(&args.filter_options, arg);
+                       continue;
+               }
                usage(fetch_pack_usage);
        }
        if (deepen_not.nr)
index 0798e0b8b28538963c7dcd1d3f0bc50350ed531c..3c5f0640775bfaf270c6c9bcc38f0b31e08ea368 100644 (file)
@@ -29,6 +29,7 @@ static int deepen_not_ok;
 static int fetch_fsck_objects = -1;
 static int transfer_fsck_objects = -1;
 static int agent_supported;
+static int server_supports_filtering;
 static struct lock_file shallow_lock;
 static const char *alternate_shallow_file;
 
@@ -379,6 +380,8 @@ static int find_common(struct fetch_pack_args *args,
                        if (deepen_not_ok)      strbuf_addstr(&c, " deepen-not");
                        if (agent_supported)    strbuf_addf(&c, " agent=%s",
                                                            git_user_agent_sanitized());
+                       if (args->filter_options.choice)
+                               strbuf_addstr(&c, " filter");
                        packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
                        strbuf_release(&c);
                } else
@@ -407,6 +410,9 @@ static int find_common(struct fetch_pack_args *args,
                        packet_buf_write(&req_buf, "deepen-not %s", s->string);
                }
        }
+       if (server_supports_filtering && args->filter_options.choice)
+               packet_buf_write(&req_buf, "filter %s",
+                                args->filter_options.filter_spec);
        packet_buf_flush(&req_buf);
        state_len = req_buf.len;
 
@@ -969,6 +975,13 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        else
                prefer_ofs_delta = 0;
 
+       if (server_supports("filter")) {
+               server_supports_filtering = 1;
+               print_verbose(args, _("Server supports filter"));
+       } else if (args->filter_options.choice) {
+               warning("filtering not recognized by server, ignoring");
+       }
+
        if ((agent_feature = server_feature_value("agent", &agent_len))) {
                agent_supported = 1;
                if (agent_len)
index aeac1526445efdbe0c639056e3a4175ab3a697e9..3e224a18226ec6219b09387704baf178821c4c23 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "string-list.h"
 #include "run-command.h"
+#include "list-objects-filter-options.h"
 
 struct oid_array;
 
@@ -12,6 +13,7 @@ struct fetch_pack_args {
        int depth;
        const char *deepen_since;
        const struct string_list *deepen_not;
+       struct list_objects_filter_options filter_options;
        unsigned deepen_relative:1;
        unsigned quiet:1;
        unsigned keep_pack:1;
index c948d5215c22fbbb3e174e219017935741e9b2d5..0650ca003f777039c8375f6a61a993d81ab62f90 100644 (file)
@@ -671,6 +671,11 @@ static int fetch(struct transport *transport,
        if (data->transport_options.update_shallow)
                set_helper_option(transport, "update-shallow", "true");
 
+       if (data->transport_options.filter_options.choice)
+               set_helper_option(
+                       transport, "filter",
+                       data->transport_options.filter_options.filter_spec);
+
        if (data->fetch)
                return fetch_with_fetch(transport, nr_heads, to_fetch);
 
index f2fbc6f968c6ccca40204db951bcff358e6ef301..cce50f5bc3e868f07f5de4c93fcdafb12cef97e5 100644 (file)
@@ -166,6 +166,9 @@ static int set_git_option(struct git_transport_options *opts,
        } else if (!strcmp(name, TRANS_OPT_NO_DEPENDENTS)) {
                opts->no_dependents = !!value;
                return 0;
+       } else if (!strcmp(name, TRANS_OPT_LIST_OBJECTS_FILTER)) {
+               parse_list_objects_filter(&opts->filter_options, value);
+               return 0;
        }
        return 1;
 }
@@ -236,6 +239,7 @@ static int fetch_refs_via_pack(struct transport *transport,
        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;
 
        if (!data->got_remote_heads) {
                connect_setup(transport, 0);
index c49a8edc537cf9d829aa4b8108737529acf61807..31b1936f8caeb429273679875e321fba36bf7ca3 100644 (file)
@@ -4,6 +4,7 @@
 #include "cache.h"
 #include "run-command.h"
 #include "remote.h"
+#include "list-objects-filter-options.h"
 
 struct string_list;
 
@@ -23,6 +24,7 @@ struct git_transport_options {
        const char *uploadpack;
        const char *receivepack;
        struct push_cas_option *cas;
+       struct list_objects_filter_options filter_options;
 };
 
 enum transport_family {
@@ -221,6 +223,9 @@ void transport_check_allowed(const char *type);
  */
 #define TRANS_OPT_NO_DEPENDENTS "no-dependents"
 
+/* Filter objects for partial clone and fetch */
+#define TRANS_OPT_LIST_OBJECTS_FILTER "filter"
+
 /**
  * Returns 0 if the option was used, non-zero otherwise. Prints a
  * message to stderr if the option is not used.