Re: [PREVIEW] add --must-filter option for fetch and clone

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux