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>

Christian Couder committed Feb 16, 2026 at 14:23 UTC fe5335974323da5e829676735cc32d89422d58ba
1 file changed +11 -5
builtin/clone.c
+11 -5
@@ -77,7 +77,6 @@ static struct string_list option_required_reference = STRING_LIST_INIT_NODUP;
77 static struct string_list option_optional_reference = STRING_LIST_INIT_NODUP;
78 static int max_jobs = -1;
79 static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP;
80 -static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
80 static int config_filter_submodules = -1; /* unspecified */
81 static int option_remote_submodules;
82
@@ -634,7 +633,9 @@ static int git_sparse_checkout_init(const char *repo)
633 return result;
634 }
635
637 -static int checkout(int submodule_progress, int filter_submodules,
636 +static int checkout(int submodule_progress,
637 + struct list_objects_filter_options *filter_options,
638 + int filter_submodules,
639 enum ref_storage_format ref_storage_format)
640 {
641 struct object_id oid;
@@ -723,9 +724,9 @@ static int checkout(int submodule_progress, int filter_submodules,
724 strvec_pushf(&cmd.args, "--ref-format=%s",
725 ref_storage_format_to_name(ref_storage_format));
726
726 - if (filter_submodules && filter_options.choice)
727 + if (filter_submodules && filter_options->choice)
728 strvec_pushf(&cmd.args, "--filter=%s",
728 - expand_list_objects_filter_spec(&filter_options));
729 + expand_list_objects_filter_spec(filter_options));
730
731 if (option_single_branch >= 0)
732 strvec_push(&cmd.args, option_single_branch ?
@@ -903,6 +904,7 @@ int cmd_clone(int argc,
904 enum transport_family family = TRANSPORT_FAMILY_ALL;
905 struct string_list option_config = STRING_LIST_INIT_DUP;
906 int option_dissociate = 0;
907 + struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
908 int option_filter_submodules = -1; /* unspecified */
909 struct string_list server_options = STRING_LIST_INIT_NODUP;
910 const char *bundle_uri = NULL;
@@ -1624,9 +1626,13 @@ int cmd_clone(int argc,
1626 return 1;
1627
1628 junk_mode = JUNK_LEAVE_REPO;
1627 - err = checkout(submodule_progress, filter_submodules,
1629 + err = checkout(submodule_progress,
1630 + &filter_options,
1631 + filter_submodules,
1632 ref_storage_format);
1633
1634 + list_objects_filter_release(&filter_options);
1635 +
1636 string_list_clear(&option_not, 0);
1637 string_list_clear(&option_config, 0);
1638 string_list_clear(&server_options, 0);