Skip to content

Commit 629b1ba

Browse files
committed
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 <[email protected]>
1 parent 9bcfa03 commit 629b1ba

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

builtin/clone.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ static struct string_list option_required_reference = STRING_LIST_INIT_NODUP;
7777
static struct string_list option_optional_reference = STRING_LIST_INIT_NODUP;
7878
static int max_jobs = -1;
7979
static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP;
80-
static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
8180
static int config_filter_submodules = -1; /* unspecified */
8281
static int option_remote_submodules;
8382

@@ -634,7 +633,9 @@ static int git_sparse_checkout_init(const char *repo)
634633
return result;
635634
}
636635

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,
638639
enum ref_storage_format ref_storage_format)
639640
{
640641
struct object_id oid;
@@ -723,9 +724,9 @@ static int checkout(int submodule_progress, int filter_submodules,
723724
strvec_pushf(&cmd.args, "--ref-format=%s",
724725
ref_storage_format_to_name(ref_storage_format));
725726

726-
if (filter_submodules && filter_options.choice)
727+
if (filter_submodules && filter_options->choice)
727728
strvec_pushf(&cmd.args, "--filter=%s",
728-
expand_list_objects_filter_spec(&filter_options));
729+
expand_list_objects_filter_spec(filter_options));
729730

730731
if (option_single_branch >= 0)
731732
strvec_push(&cmd.args, option_single_branch ?
@@ -903,6 +904,7 @@ int cmd_clone(int argc,
903904
enum transport_family family = TRANSPORT_FAMILY_ALL;
904905
struct string_list option_config = STRING_LIST_INIT_DUP;
905906
int option_dissociate = 0;
907+
struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
906908
int option_filter_submodules = -1; /* unspecified */
907909
struct string_list server_options = STRING_LIST_INIT_NODUP;
908910
const char *bundle_uri = NULL;
@@ -1625,9 +1627,13 @@ int cmd_clone(int argc,
16251627
return 1;
16261628

16271629
junk_mode = JUNK_LEAVE_REPO;
1628-
err = checkout(submodule_progress, filter_submodules,
1630+
err = checkout(submodule_progress,
1631+
&filter_options,
1632+
filter_submodules,
16291633
ref_storage_format);
16301634

1635+
list_objects_filter_release(&filter_options);
1636+
16311637
string_list_clear(&option_not, 0);
16321638
string_list_clear(&option_config, 0);
16331639
string_list_clear(&server_options, 0);

0 commit comments

Comments
 (0)