Skip to content

Commit 640d8b7

Browse files
jeffhostetlergitster
authored andcommitted
fetch-pack, index-pack, transport: partial clone
Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10ac85c commit 640d8b7

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

builtin/fetch-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
153153
args.no_dependents = 1;
154154
continue;
155155
}
156+
if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
157+
parse_list_objects_filter(&args.filter_options, arg);
158+
continue;
159+
}
156160
usage(fetch_pack_usage);
157161
}
158162
if (deepen_not.nr)

fetch-pack.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static int deepen_not_ok;
2929
static int fetch_fsck_objects = -1;
3030
static int transfer_fsck_objects = -1;
3131
static int agent_supported;
32+
static int server_supports_filtering;
3233
static struct lock_file shallow_lock;
3334
static const char *alternate_shallow_file;
3435

@@ -379,6 +380,8 @@ static int find_common(struct fetch_pack_args *args,
379380
if (deepen_not_ok) strbuf_addstr(&c, " deepen-not");
380381
if (agent_supported) strbuf_addf(&c, " agent=%s",
381382
git_user_agent_sanitized());
383+
if (args->filter_options.choice)
384+
strbuf_addstr(&c, " filter");
382385
packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
383386
strbuf_release(&c);
384387
} else
@@ -407,6 +410,9 @@ static int find_common(struct fetch_pack_args *args,
407410
packet_buf_write(&req_buf, "deepen-not %s", s->string);
408411
}
409412
}
413+
if (server_supports_filtering && args->filter_options.choice)
414+
packet_buf_write(&req_buf, "filter %s",
415+
args->filter_options.filter_spec);
410416
packet_buf_flush(&req_buf);
411417
state_len = req_buf.len;
412418

@@ -969,6 +975,13 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
969975
else
970976
prefer_ofs_delta = 0;
971977

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+
972985
if ((agent_feature = server_feature_value("agent", &agent_len))) {
973986
agent_supported = 1;
974987
if (agent_len)

fetch-pack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "string-list.h"
55
#include "run-command.h"
6+
#include "list-objects-filter-options.h"
67

78
struct oid_array;
89

@@ -12,6 +13,7 @@ struct fetch_pack_args {
1213
int depth;
1314
const char *deepen_since;
1415
const struct string_list *deepen_not;
16+
struct list_objects_filter_options filter_options;
1517
unsigned deepen_relative:1;
1618
unsigned quiet:1;
1719
unsigned keep_pack:1;

transport-helper.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,11 @@ static int fetch(struct transport *transport,
671671
if (data->transport_options.update_shallow)
672672
set_helper_option(transport, "update-shallow", "true");
673673

674+
if (data->transport_options.filter_options.choice)
675+
set_helper_option(
676+
transport, "filter",
677+
data->transport_options.filter_options.filter_spec);
678+
674679
if (data->fetch)
675680
return fetch_with_fetch(transport, nr_heads, to_fetch);
676681

transport.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ static int set_git_option(struct git_transport_options *opts,
166166
} else if (!strcmp(name, TRANS_OPT_NO_DEPENDENTS)) {
167167
opts->no_dependents = !!value;
168168
return 0;
169+
} else if (!strcmp(name, TRANS_OPT_LIST_OBJECTS_FILTER)) {
170+
parse_list_objects_filter(&opts->filter_options, value);
171+
return 0;
169172
}
170173
return 1;
171174
}
@@ -236,6 +239,7 @@ static int fetch_refs_via_pack(struct transport *transport,
236239
args.update_shallow = data->options.update_shallow;
237240
args.from_promisor = data->options.from_promisor;
238241
args.no_dependents = data->options.no_dependents;
242+
args.filter_options = data->options.filter_options;
239243

240244
if (!data->got_remote_heads) {
241245
connect_setup(transport, 0);

transport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "cache.h"
55
#include "run-command.h"
66
#include "remote.h"
7+
#include "list-objects-filter-options.h"
78

89
struct string_list;
910

@@ -23,6 +24,7 @@ struct git_transport_options {
2324
const char *uploadpack;
2425
const char *receivepack;
2526
struct push_cas_option *cas;
27+
struct list_objects_filter_options filter_options;
2628
};
2729

2830
enum transport_family {
@@ -221,6 +223,9 @@ void transport_check_allowed(const char *type);
221223
*/
222224
#define TRANS_OPT_NO_DEPENDENTS "no-dependents"
223225

226+
/* Filter objects for partial clone and fetch */
227+
#define TRANS_OPT_LIST_OBJECTS_FILTER "filter"
228+
224229
/**
225230
* Returns 0 if the option was used, non-zero otherwise. Prints a
226231
* message to stderr if the option is not used.

0 commit comments

Comments
 (0)