Skip to content

Commit 4ba54e4

Browse files
committed
environment: move access to "core.sparseCheckout" into repo settings
The `core.sparseCheckout` config value is stored in the global variable `core_apply_sparse_checkout`. This may cause issues in the case where one is handling multiple different repositories in a Git single process with different values for that config key. The global state also blocks the goal of libifying Git. Refactor the code to store it in `sparse_checkout` in `struct repo-settings` and update the callers Note that in `builtin/sparse-checkout.c`, `struct repository` parameter in `sparse_checkout_list()` is used to avoid the use of `the_repository` and `update_cone_mode()` is also adapted to accept `struct repository`. Based-on-patch-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
1 parent d8af7ca commit 4ba54e4

File tree

13 files changed

+26
-30
lines changed

13 files changed

+26
-30
lines changed

builtin/backfill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
139139
repo_config(repo, git_default_config, NULL);
140140

141141
if (ctx.sparse < 0)
142-
ctx.sparse = core_apply_sparse_checkout;
142+
ctx.sparse = repo->settings.sparse_checkout;
143143

144144
result = do_backfill(&ctx);
145145
backfill_context_clear(&ctx);

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ static int git_sparse_checkout_init(const char *repo)
623623
* We must apply the setting in the current process
624624
* for the later checkout to use the sparse-checkout file.
625625
*/
626-
core_apply_sparse_checkout = 1;
626+
the_repository->settings.sparse_checkout = 1;
627627

628628
cmd.git_cmd = 1;
629629
if (run_command(&cmd)) {

builtin/mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ int cmd_mv(int argc,
572572
rename_index_entry_at(the_repository->index, pos, dst);
573573

574574
if (ignore_sparse &&
575-
core_apply_sparse_checkout &&
575+
the_repository->settings.sparse_checkout &&
576576
core_sparse_checkout_cone) {
577577
/*
578578
* NEEDSWORK: we are *not* paying attention to

builtin/sparse-checkout.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static char const * const builtin_sparse_checkout_list_usage[] = {
5353
};
5454

5555
static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
56-
struct repository *repo UNUSED)
56+
struct repository *repo)
5757
{
5858
static struct option builtin_sparse_checkout_list_options[] = {
5959
OPT_END(),
@@ -63,7 +63,7 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
6363
int res;
6464

6565
setup_work_tree();
66-
if (!core_apply_sparse_checkout)
66+
if (!repo->settings.sparse_checkout)
6767
die(_("this worktree is not sparse"));
6868

6969
argc = parse_options(argc, argv, prefix,
@@ -398,13 +398,13 @@ static int set_config(struct repository *repo,
398398
return 0;
399399
}
400400

401-
static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
401+
static enum sparse_checkout_mode update_cone_mode(struct repository *repo, int *cone_mode) {
402402
/* If not specified, use previous definition of cone mode */
403-
if (*cone_mode == -1 && core_apply_sparse_checkout)
403+
if (*cone_mode == -1 && repo->settings.sparse_checkout)
404404
*cone_mode = core_sparse_checkout_cone;
405405

406406
/* Set cone/non-cone mode appropriately */
407-
core_apply_sparse_checkout = 1;
407+
repo->settings.sparse_checkout = 1;
408408
if (*cone_mode == 1 || *cone_mode == -1) {
409409
core_sparse_checkout_cone = 1;
410410
return MODE_CONE_PATTERNS;
@@ -418,9 +418,9 @@ static int update_modes(struct repository *repo, int *cone_mode, int *sparse_ind
418418
int mode, record_mode;
419419

420420
/* Determine if we need to record the mode; ensure sparse checkout on */
421-
record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout;
421+
record_mode = (*cone_mode != -1) || !repo->settings.sparse_checkout;
422422

423-
mode = update_cone_mode(cone_mode);
423+
mode = update_cone_mode(repo, cone_mode);
424424
if (record_mode && set_config(repo, mode))
425425
return 1;
426426

@@ -699,9 +699,9 @@ static int modify_pattern_list(struct repository *repo,
699699
break;
700700
}
701701

702-
if (!core_apply_sparse_checkout) {
702+
if (!repo->settings.sparse_checkout) {
703703
set_config(repo, MODE_ALL_PATTERNS);
704-
core_apply_sparse_checkout = 1;
704+
repo->settings.sparse_checkout = 1;
705705
changed_config = 1;
706706
}
707707

@@ -798,7 +798,7 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
798798
int ret;
799799

800800
setup_work_tree();
801-
if (!core_apply_sparse_checkout)
801+
if (!repo->settings.sparse_checkout)
802802
die(_("no sparse-checkout to add to"));
803803

804804
repo_read_index(repo);
@@ -907,7 +907,7 @@ static int sparse_checkout_reapply(int argc, const char **argv,
907907
};
908908

909909
setup_work_tree();
910-
if (!core_apply_sparse_checkout)
910+
if (!repo->settings.sparse_checkout)
911911
die(_("must be in a sparse-checkout to reapply sparsity patterns"));
912912

913913
reapply_opts.cone_mode = -1;
@@ -969,7 +969,7 @@ static int sparse_checkout_clean(int argc, const char **argv,
969969
};
970970

971971
setup_work_tree();
972-
if (!core_apply_sparse_checkout)
972+
if (!repo->settings.sparse_checkout)
973973
die(_("must be in a sparse-checkout to clean directories"));
974974
if (!core_sparse_checkout_cone)
975975
die(_("must be in a cone-mode sparse-checkout to clean directories"));
@@ -1061,7 +1061,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
10611061
hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
10621062
hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);
10631063
pl.use_cone_patterns = 0;
1064-
core_apply_sparse_checkout = 1;
1064+
repo->settings.sparse_checkout = 1;
10651065

10661066
add_pattern("/*", empty_base, 0, &pl, 0);
10671067

@@ -1144,7 +1144,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
11441144
if (check_rules_opts.rules_file && check_rules_opts.cone_mode < 0)
11451145
check_rules_opts.cone_mode = 1;
11461146

1147-
update_cone_mode(&check_rules_opts.cone_mode);
1147+
update_cone_mode(repo, &check_rules_opts.cone_mode);
11481148
pl.use_cone_patterns = core_sparse_checkout_cone;
11491149
if (check_rules_opts.rules_file) {
11501150
fp = xfopen(check_rules_opts.rules_file, "r");

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static int add_worktree(const char *path, const char *refname,
536536
* If the current worktree has sparse-checkout enabled, then copy
537537
* the sparse-checkout patterns from the current worktree.
538538
*/
539-
if (core_apply_sparse_checkout)
539+
if (the_repository->settings.sparse_checkout)
540540
copy_sparse_checkout(sb_repo.buf);
541541

542542
/*

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ enum pattern_match_result path_matches_pattern_list(
15511551

15521552
int init_sparse_checkout_patterns(struct index_state *istate)
15531553
{
1554-
if (!core_apply_sparse_checkout)
1554+
if (!istate->repo->settings.sparse_checkout)
15551555
return 1;
15561556
if (istate->sparse_checkout_patterns)
15571557
return 0;

environment.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
7575
#endif
7676
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
7777
int grafts_keep_true_parents;
78-
int core_apply_sparse_checkout;
7978
int core_sparse_checkout_cone;
8079
int sparse_expect_files_outside_of_patterns;
8180
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
@@ -544,11 +543,6 @@ static int git_default_core_config(const char *var, const char *value,
544543
return 0;
545544
}
546545

547-
if (!strcmp(var, "core.sparsecheckout")) {
548-
core_apply_sparse_checkout = git_config_bool(var, value);
549-
return 0;
550-
}
551-
552546
if (!strcmp(var, "core.sparsecheckoutcone")) {
553547
core_sparse_checkout_cone = git_config_bool(var, value);
554548
return 0;

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ extern int precomposed_unicode;
162162
extern int protect_hfs;
163163
extern int protect_ntfs;
164164

165-
extern int core_apply_sparse_checkout;
166165
extern int core_sparse_checkout_cone;
167166
extern int sparse_expect_files_outside_of_patterns;
168167

repo-settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void prepare_repo_settings(struct repository *r)
8484
&r->settings.pack_use_bitmap_boundary_traversal,
8585
r->settings.pack_use_bitmap_boundary_traversal);
8686
repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1);
87+
repo_cfg_bool(r, "core.sparsecheckout", &r->settings.sparse_checkout, 0);
8788

8889
/*
8990
* The GIT_TEST_MULTI_PACK_INDEX variable is special in that

repo-settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct repo_settings {
3939

4040
int shared_repository;
4141
int shared_repository_initialized;
42+
int sparse_checkout;
4243

4344
/*
4445
* Does this repository have core.useReplaceRefs=true (on by

0 commit comments

Comments
 (0)