{"thread":{"id":"63227","subject":"Re: [PREVIEW] add --must-filter option for fetch and clone","startedAt":"2025-03-31T16:16:26Z","lastAt":"2025-03-31T16:16:26Z","messageCount":1,"participants":["John Giorshev"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"515387","messageId":"CADJmAEjLevd+vx=7rChd26Qf9Az8Qz96hyE3KJZFXikbkBQj8w@mail.gmail.com","threadId":"63227","inReplyTo":"CADJmAEg6M=FJcndQQ45odztyAq8jATonEwXjrkuoZuZ=WXh7vQ@mail.gmail.com","subject":"Re: [PREVIEW] add --must-filter option for fetch and clone","fromName":"John Giorshev","fromEmail":"john.giorshev1@gmail.com","sentAt":"2025-03-31T16:16:15Z","receivedAt":"2025-03-31T16:16:26Z","isPatch":false,"sender":{"key":"john.giorshev1@gmail.com","avatar":null},"body":"On Mon, Mar 31, 2025 at 12:10 PM John Giorshev <john.giorshev1@gmail.com> wrote:\n>\n> cc'ing reviewers. thanks.\n>\n> context:\n>  - https://stackoverflow.com/q/79413099/15534181\n>  - https://public-inbox.org/git/20250225013227.GB752084@coredump.intra.peff.net/\n>\n> On Sat, Mar 1, 2025 at 3:30 PM John Giorshev via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n> >\n> > From: John Giorshev <john.giorshev1@gmail.com>\n> >\n> > Signed-off-by: John Giorshev <john.giorshev1@gmail.com>\n> > ---\n> >     add --must-filter, give error on filter not supported instead of warn\n> >\n> >     from:\n> >     https://public-inbox.org/git/20250225013227.GB752084@coredump.intra.peff.net/\n> >\n> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1869%2Fjagprog5%2Fmaster-v1\n> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1869/jagprog5/master-v1\n> > Pull-Request: https://github.com/gitgitgadget/git/pull/1869\n> >\n> >  builtin/clone.c          |  6 ++++++\n> >  builtin/fetch.c          |  7 ++++++-\n> >  fetch-pack.c             |  8 ++++++--\n> >  fetch-pack.h             |  1 +\n> >  t/t0410-partial-clone.sh | 17 +++++++++++++++++\n> >  transport.c              |  1 +\n> >  transport.h              |  1 +\n> >  7 files changed, 38 insertions(+), 3 deletions(-)\n> >\n> > diff --git a/builtin/clone.c b/builtin/clone.c\n> > index f9a2ecbe9cc..7000b0ecd36 100644\n> > --- a/builtin/clone.c\n> > +++ b/builtin/clone.c\n> > @@ -887,6 +887,7 @@ int cmd_clone(int argc,\n> >         enum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;\n> >         const int do_not_override_repo_unix_permissions = -1;\n> >         int option_reject_shallow = -1; /* unspecified */\n> > +       int must_filter = 0;\n> >         int deepen = 0;\n> >         char *option_template = NULL, *option_depth = NULL, *option_since = NULL;\n> >         char *option_origin = NULL;\n> > @@ -915,6 +916,8 @@ int cmd_clone(int argc,\n> >                          N_(\"force progress reporting\")),\n> >                 OPT_BOOL(0, \"reject-shallow\", &option_reject_shallow,\n> >                          N_(\"don't clone shallow repository\")),\n> > +               OPT_BOOL(0, \"must-filter\", &must_filter,\n> > +                        N_(\"error on filter not supported by server\")),\n> >                 OPT_BOOL('n', \"no-checkout\", &option_no_checkout,\n> >                          N_(\"don't create a checkout\")),\n> >                 OPT_BOOL(0, \"bare\", &option_bare, N_(\"create a bare repository\")),\n> > @@ -1333,6 +1336,9 @@ int cmd_clone(int argc,\n> >         transport_set_verbosity(transport, option_verbosity, option_progress);\n> >         transport->family = family;\n> >         transport->cloning = 1;\n> > +       if (transport->smart_options) {\n> > +               transport->smart_options->must_filter = must_filter;\n> > +       }\n> >\n> >         if (is_bundle) {\n> >                 struct bundle_header header = BUNDLE_HEADER_INIT;\n> > diff --git a/builtin/fetch.c b/builtin/fetch.c\n> > index 1c740d5aac3..1f3cdf53148 100644\n> > --- a/builtin/fetch.c\n> > +++ b/builtin/fetch.c\n> > @@ -84,7 +84,7 @@ static int prune_tags = -1; /* unspecified */\n> >\n> >  static int append, dry_run, force, keep, update_head_ok;\n> >  static int write_fetch_head = 1;\n> > -static int verbosity, deepen_relative, set_upstream, refetch;\n> > +static int verbosity, deepen_relative, set_upstream, refetch, must_filter;\n> >  static int progress = -1;\n> >  static int tags = TAGS_DEFAULT, update_shallow, deepen;\n> >  static int atomic_fetch;\n> > @@ -1508,6 +1508,9 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)\n> >         transport = transport_get(remote, NULL);\n> >         transport_set_verbosity(transport, verbosity, progress);\n> >         transport->family = family;\n> > +       if (transport->smart_options) {\n> > +               transport->smart_options->must_filter = must_filter;\n> > +       }\n> >         if (upload_pack)\n> >                 set_option(transport, TRANS_OPT_UPLOADPACK, upload_pack);\n> >         if (keep)\n> > @@ -2322,6 +2325,8 @@ int cmd_fetch(int argc,\n> >                          N_(\"append to .git/FETCH_HEAD instead of overwriting\")),\n> >                 OPT_BOOL(0, \"atomic\", &atomic_fetch,\n> >                          N_(\"use atomic transaction to update references\")),\n> > +               OPT_BOOL(0, \"must-filter\", &must_filter,\n> > +                        N_(\"error on filter not supported by server\")),\n> >                 OPT_STRING(0, \"upload-pack\", &upload_pack, N_(\"path\"),\n> >                            N_(\"path to upload pack on remote end\")),\n> >                 OPT__FORCE(&force, N_(\"force overwrite of local reference\"), 0),\n> > diff --git a/fetch-pack.c b/fetch-pack.c\n> > index 1ed5e11dd56..0cf59c1bc82 100644\n> > --- a/fetch-pack.c\n> > +++ b/fetch-pack.c\n> > @@ -319,9 +319,13 @@ static void send_filter(struct fetch_pack_args *args,\n> >                         trace2_data_string(\"fetch\", the_repository,\n> >                                            \"filter/effective\", spec);\n> >                 } else {\n> > -                       warning(\"filtering not recognized by server, ignoring\");\n> > -                       trace2_data_string(\"fetch\", the_repository,\n> > +                       if (args->must_filter) {\n> > +                               die(\"filtering not recognized by server\");\n> > +                       } else {\n> > +                               warning(\"filtering not recognized by server, ignoring\");\n> > +                               trace2_data_string(\"fetch\", the_repository,\n> >                                            \"filter/unsupported\", spec);\n> > +                       }\n> >                 }\n> >         } else {\n> >                 trace2_data_string(\"fetch\", the_repository,\n> > diff --git a/fetch-pack.h b/fetch-pack.h\n> > index 9d3470366f8..01ab94fc24b 100644\n> > --- a/fetch-pack.h\n> > +++ b/fetch-pack.h\n> > @@ -40,6 +40,7 @@ struct fetch_pack_args {\n> >         unsigned cloning:1;\n> >         unsigned update_shallow:1;\n> >         unsigned reject_shallow_remote:1;\n> > +       unsigned must_filter:1;\n> >         unsigned deepen:1;\n> >         unsigned refetch:1;\n> >\n> > diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh\n> > index 2a5bdbeeb87..0166c491ca5 100755\n> > --- a/t/t0410-partial-clone.sh\n> > +++ b/t/t0410-partial-clone.sh\n> > @@ -48,6 +48,23 @@ test_expect_success 'convert shallow clone to partial clone' '\n> >         test_cmp_config -C client 1 core.repositoryformatversion\n> >  '\n> >\n> > +test_expect_failure 'must filter clone' '\n> > +       rm -fr server client &&\n> > +       test_create_repo server &&\n> > +       test_commit -C server my_commit 1 &&\n> > +       test_commit -C server my_commit2 1 &&\n> > +       git clone --filter=\"blob:none\" --must-filter \"file://$(pwd)/server\" client\n> > +'\n> > +\n> > +test_expect_failure 'must filter fetch' '\n> > +       rm -fr server client &&\n> > +       test_create_repo server &&\n> > +       test_commit -C server my_commit 1 &&\n> > +       test_commit -C server my_commit2 1 &&\n> > +       git clone --depth=1 \"file://$(pwd)/server\" client &&\n> > +       git -C client fetch --unshallow --filter=\"blob:none\" --must-filter\n> > +'\n> > +\n> >  test_expect_success DEFAULT_REPO_FORMAT 'convert to partial clone with noop extension' '\n> >         rm -fr server client &&\n> >         test_create_repo server &&\n> > diff --git a/transport.c b/transport.c\n> > index 6c2801bcbd9..0543821399d 100644\n> > --- a/transport.c\n> > +++ b/transport.c\n> > @@ -450,6 +450,7 @@ static int fetch_refs_via_pack(struct transport *transport,\n> >         args.quiet = (transport->verbose < 0);\n> >         args.no_progress = !transport->progress;\n> >         args.depth = data->options.depth;\n> > +       args.must_filter = data->options.must_filter;\n> >         args.deepen_since = data->options.deepen_since;\n> >         args.deepen_not = data->options.deepen_not;\n> >         args.deepen_relative = data->options.deepen_relative;\n> > diff --git a/transport.h b/transport.h\n> > index 44100fa9b7f..0ffc8d273ab 100644\n> > --- a/transport.h\n> > +++ b/transport.h\n> > @@ -16,6 +16,7 @@ struct git_transport_options {\n> >         unsigned reject_shallow : 1;\n> >         unsigned deepen_relative : 1;\n> >         unsigned refetch : 1;\n> > +       unsigned must_filter : 1;\n> >\n> >         /* see documentation of corresponding flag in fetch-pack.h */\n> >         unsigned from_promisor : 1;\n> >\n> > base-commit: a554262210b4a2ee6fa2d594e1f09f5830888c56\n> > --\n> > gitgitgadget\n"}]}