clone: make filter_options local to cmd_clone()

The `struct list_objects_filter_options filter_options` variable used
in "builtin/clone.c" to store the parsed filters specified by
`--filter=<filterspec>` is currently a static variable global to the
file.

As we are going to use it more in a following commit, it could become
a bit less easy to understand how it's managed.

To avoid that, let's make it clear that it's owned by cmd_clone() by
moving its definition into that function and making it non-static.

The only additional change to make this work is to pass it as an
argument to checkout(). So it's a small quite cheap cleanup anyway.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Christian Couder 2025-12-23 12:11:07 +01:00 committed by Junio C Hamano
parent 09b0cefcd8
commit 50cedfdf94

View File

@ -77,7 +77,6 @@ static struct string_list option_required_reference = STRING_LIST_INIT_NODUP;
static struct string_list option_optional_reference = STRING_LIST_INIT_NODUP;
static int max_jobs = -1;
static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP;
static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
static int config_filter_submodules = -1; /* unspecified */
static int option_remote_submodules;
@ -634,7 +633,9 @@ static int git_sparse_checkout_init(const char *repo)
return result;
}
static int checkout(int submodule_progress, int filter_submodules,
static int checkout(int submodule_progress,
struct list_objects_filter_options *filter_options,
int filter_submodules,
enum ref_storage_format ref_storage_format)
{
struct object_id oid;
@ -723,9 +724,9 @@ static int checkout(int submodule_progress, int filter_submodules,
strvec_pushf(&cmd.args, "--ref-format=%s",
ref_storage_format_to_name(ref_storage_format));
if (filter_submodules && filter_options.choice)
if (filter_submodules && filter_options->choice)
strvec_pushf(&cmd.args, "--filter=%s",
expand_list_objects_filter_spec(&filter_options));
expand_list_objects_filter_spec(filter_options));
if (option_single_branch >= 0)
strvec_push(&cmd.args, option_single_branch ?
@ -903,6 +904,7 @@ int cmd_clone(int argc,
enum transport_family family = TRANSPORT_FAMILY_ALL;
struct string_list option_config = STRING_LIST_INIT_DUP;
int option_dissociate = 0;
struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
int option_filter_submodules = -1; /* unspecified */
struct string_list server_options = STRING_LIST_INIT_NODUP;
const char *bundle_uri = NULL;
@ -1625,9 +1627,13 @@ int cmd_clone(int argc,
return 1;
junk_mode = JUNK_LEAVE_REPO;
err = checkout(submodule_progress, filter_submodules,
err = checkout(submodule_progress,
&filter_options,
filter_submodules,
ref_storage_format);
list_objects_filter_release(&filter_options);
string_list_clear(&option_not, 0);
string_list_clear(&option_config, 0);
string_list_clear(&server_options, 0);