Skip to content

Commit fdbb0bc

Browse files
committed
fetch-pack: wire up and enable auto filter logic
Previous commits have set up an infrastructure for `--filter=auto` to automatically prepare a partial clone filter based on what the server advertised and the client accepted. Using that infrastructure, let's now enable the `--filter=auto` option in `git clone` by setting `allow_auto_filter` to 1. Let's also set `allow_auto_filter` to 1 in `transport.c`, as the transport layer must be able to accept the "auto" filter spec even if the invoking command hasn't fully parsed it yet. When an "auto" filter is requested, let's have the "fetch-pack.c" code in `do_fetch_pack_v2()` compute a filter and send it to the server. In `do_fetch_pack_v2()` the logic also needs to check for the "promisor-remote" capability and call `promisor_remote_reply()` to parse advertised remotes and populate the list of those accepted (and their filters). Signed-off-by: Christian Couder <[email protected]>
1 parent 0380bf8 commit fdbb0bc

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

builtin/clone.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,8 @@ int cmd_clone(int argc,
10011001
NULL
10021002
};
10031003

1004+
filter_options.allow_auto_filter = 1;
1005+
10041006
packet_trace_identity("clone");
10051007

10061008
repo_config(the_repository, git_clone_config, NULL);

fetch-pack.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "sigchain.h"
3636
#include "mergesort.h"
3737
#include "prio-queue.h"
38+
#include "promisor-remote.h"
3839

3940
static int transfer_unpack_limit = -1;
4041
static int fetch_unpack_limit = -1;
@@ -1661,6 +1662,25 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
16611662
struct string_list packfile_uris = STRING_LIST_INIT_DUP;
16621663
int i;
16631664
struct strvec index_pack_args = STRVEC_INIT;
1665+
const char *promisor_remote_config;
1666+
1667+
if (server_feature_v2("promisor-remote", &promisor_remote_config)) {
1668+
char *remote_name = promisor_remote_reply(promisor_remote_config);
1669+
free(remote_name);
1670+
}
1671+
1672+
if (args->filter_options.choice == LOFC_AUTO) {
1673+
struct strbuf errbuf = STRBUF_INIT;
1674+
char *constructed_filter = promisor_remote_construct_filter(r);
1675+
1676+
list_objects_filter_resolve_auto(&args->filter_options,
1677+
constructed_filter, &errbuf);
1678+
if (errbuf.len > 0)
1679+
die(_("couldn't resolve 'auto' filter: %s"), errbuf.buf);
1680+
1681+
free(constructed_filter);
1682+
strbuf_release(&errbuf);
1683+
}
16641684

16651685
negotiator = &negotiator_alloc;
16661686
if (args->refetch)

t/t5710-promisor-remote-capability.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,26 @@ test_expect_success "clone with promisor.storeFields=partialCloneFilter" '
409409
check_missing_objects server 1 "$oid"
410410
'
411411

412+
test_expect_success "clone with --filter=auto" '
413+
git -C server config promisor.advertise true &&
414+
test_when_finished "rm -rf client trace" &&
415+
416+
git -C server config remote.lop.partialCloneFilter "blob:limit=9500" &&
417+
test_config -C server promisor.sendFields "partialCloneFilter" &&
418+
419+
GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \
420+
-c remote.lop.promisor=true \
421+
-c remote.lop.url="file://$(pwd)/lop" \
422+
-c promisor.acceptfromserver=All \
423+
--no-local --filter=auto server client 2>err &&
424+
425+
grep "filter blob:limit=9500" trace &&
426+
! grep "filter auto" trace &&
427+
428+
# Check that the largest object is still missing on the server
429+
check_missing_objects server 1 "$oid"
430+
'
431+
412432
test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" '
413433
git -C server config promisor.advertise true &&
414434

transport.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
12191219
*/
12201220
struct git_transport_data *data = xcalloc(1, sizeof(*data));
12211221
list_objects_filter_init(&data->options.filter_options);
1222+
data->options.filter_options.allow_auto_filter = 1;
12221223
ret->data = data;
12231224
ret->vtable = &builtin_smart_vtable;
12241225
ret->smart_options = &(data->options);

0 commit comments

Comments
 (0)