Skip to content

Commit 5002be1

Browse files
ayu-chgitster
authored andcommitted
environment: move access to "core.sparsecheckoutcone" into repo_settings
The setting "core.sparsecheckoutcone" is stored in the global `core_sparse_checkout_cone` and is populated in config.c. Refactor the code to store it in the variable `sparse_checkout_cone` in the struct `repo_settings`. Call `prepare_repo_settings()` where necessary to ensure the `struct repo_settings` is initialized before use: - In "dir.c", the function accessing the setting is usually called after `prepare_repo_settings()`, except for one code path in "unpack-trees.c", so add a call there. Avoid redundant calls to `prepare_repo_settings()` where it is already present: - In "builtin/mv.c" and "builtin/sparse-checkout.c", it is already invoked in their respective `cmd_*()` functions. - In "sparse-index.c", `prepare_repo_settings` is already called before the setting is accessed. This change is part of an ongoing effort to eliminate global variables, improve modularity and help libify the codebase. Mentored-by: Christian Couder <[email protected]> Mentored-by: Ghanshyam Thakkar <[email protected]> Signed-off-by: Ayush Chandekar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 50a345c commit 5002be1

File tree

11 files changed

+22
-25
lines changed

11 files changed

+22
-25
lines changed

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static int grep_submodule(struct grep_opt *opt,
491491
* dictate the behavior for the submodule, making it "forget" its
492492
* sparse-checkout state.
493493
*
494-
* 3. "core_sparse_checkout_cone"
494+
* 3. "settings.sparse_checkout_cone"
495495
* ditto.
496496
*
497497
* Note that this list is not exhaustive.

builtin/mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ int cmd_mv(int argc,
573573
prepare_repo_settings(the_repository);
574574
if (ignore_sparse &&
575575
the_repository->settings.sparse_checkout &&
576-
core_sparse_checkout_cone) {
576+
the_repository->settings.sparse_checkout_cone) {
577577
/*
578578
* NEEDSWORK: we are *not* paying attention to
579579
* "out-to-out" move (<source> is out-of-cone and

builtin/sparse-checkout.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
7171

7272
memset(&pl, 0, sizeof(pl));
7373

74-
pl.use_cone_patterns = core_sparse_checkout_cone;
74+
pl.use_cone_patterns = the_repository->settings.sparse_checkout_cone;
7575

7676
sparse_filename = get_sparse_checkout_filename();
7777
res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
@@ -352,7 +352,7 @@ static int write_patterns_and_update(struct pattern_list *pl)
352352
if (!fp)
353353
die_errno(_("unable to fdopen %s"), get_lock_file_path(&lk));
354354

355-
if (core_sparse_checkout_cone)
355+
if (the_repository->settings.sparse_checkout_cone)
356356
write_cone_to_file(fp, pl);
357357
else
358358
write_patterns_to_file(fp, pl);
@@ -398,15 +398,15 @@ static int set_config(enum sparse_checkout_mode mode)
398398
static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
399399
/* If not specified, use previous definition of cone mode */
400400
if (*cone_mode == -1 && the_repository->settings.sparse_checkout)
401-
*cone_mode = core_sparse_checkout_cone;
401+
*cone_mode = the_repository->settings.sparse_checkout_cone;
402402

403403
/* Set cone/non-cone mode appropriately */
404404
the_repository->settings.sparse_checkout = 1;
405405
if (*cone_mode == 1 || *cone_mode == -1) {
406-
core_sparse_checkout_cone = 1;
406+
the_repository->settings.sparse_checkout_cone = 1;
407407
return MODE_CONE_PATTERNS;
408408
}
409-
core_sparse_checkout_cone = 0;
409+
the_repository->settings.sparse_checkout_cone = 0;
410410
return MODE_ALL_PATTERNS;
411411
}
412412

@@ -572,7 +572,7 @@ static void add_patterns_from_input(struct pattern_list *pl,
572572
FILE *file)
573573
{
574574
int i;
575-
if (core_sparse_checkout_cone) {
575+
if (the_repository->settings.sparse_checkout_cone) {
576576
struct strbuf line = STRBUF_INIT;
577577

578578
hashmap_init(&pl->recursive_hashmap, pl_hashmap_cmp, NULL, 0);
@@ -637,7 +637,7 @@ static void add_patterns_cone_mode(int argc, const char **argv,
637637
use_stdin ? stdin : NULL);
638638

639639
memset(&existing, 0, sizeof(existing));
640-
existing.use_cone_patterns = core_sparse_checkout_cone;
640+
existing.use_cone_patterns = the_repository->settings.sparse_checkout_cone;
641641

642642
if (add_patterns_from_file_to_list(sparse_filename, "", 0,
643643
&existing, NULL, 0))
@@ -683,7 +683,7 @@ static int modify_pattern_list(struct strvec *args, int use_stdin,
683683

684684
switch (m) {
685685
case ADD:
686-
if (core_sparse_checkout_cone)
686+
if (the_repository->settings.sparse_checkout_cone)
687687
add_patterns_cone_mode(args->nr, args->v, pl, use_stdin);
688688
else
689689
add_patterns_literal(args->nr, args->v, pl, use_stdin);
@@ -719,7 +719,7 @@ static void sanitize_paths(struct strvec *args,
719719
if (!args->nr)
720720
return;
721721

722-
if (prefix && *prefix && core_sparse_checkout_cone) {
722+
if (prefix && *prefix && the_repository->settings.sparse_checkout_cone) {
723723
/*
724724
* The args are not pathspecs, so unfortunately we
725725
* cannot imitate how cmd_add() uses parse_pathspec().
@@ -736,10 +736,10 @@ static void sanitize_paths(struct strvec *args,
736736
if (skip_checks)
737737
return;
738738

739-
if (prefix && *prefix && !core_sparse_checkout_cone)
739+
if (prefix && *prefix && !the_repository->settings.sparse_checkout_cone)
740740
die(_("please run from the toplevel directory in non-cone mode"));
741741

742-
if (core_sparse_checkout_cone) {
742+
if (the_repository->settings.sparse_checkout_cone) {
743743
for (i = 0; i < args->nr; i++) {
744744
if (args->v[i][0] == '/')
745745
die(_("specify directories rather than patterns (no leading slash)"));
@@ -761,7 +761,7 @@ static void sanitize_paths(struct strvec *args,
761761
if (S_ISSPARSEDIR(ce->ce_mode))
762762
continue;
763763

764-
if (core_sparse_checkout_cone)
764+
if (the_repository->settings.sparse_checkout_cone)
765765
die(_("'%s' is not a directory; to treat it as a directory anyway, rerun with --skip-checks"), args->v[i]);
766766
else
767767
warning(_("pass a leading slash before paths such as '%s' if you want a single file (see NON-CONE PROBLEMS in the git-sparse-checkout manual)."), args->v[i]);
@@ -864,7 +864,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
864864
* non-cone mode, if nothing is specified, manually select just the
865865
* top-level directory (much as 'init' would do).
866866
*/
867-
if (!core_sparse_checkout_cone && !set_opts.use_stdin && argc == 0) {
867+
if (!the_repository->settings.sparse_checkout_cone && !set_opts.use_stdin && argc == 0) {
868868
for (int i = 0; i < default_patterns_nr; i++)
869869
strvec_push(&patterns, default_patterns[i]);
870870
} else {
@@ -1041,7 +1041,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
10411041
check_rules_opts.cone_mode = 1;
10421042

10431043
update_cone_mode(&check_rules_opts.cone_mode);
1044-
pl.use_cone_patterns = core_sparse_checkout_cone;
1044+
pl.use_cone_patterns = the_repository->settings.sparse_checkout_cone;
10451045
if (check_rules_opts.rules_file) {
10461046
fp = xfopen(check_rules_opts.rules_file, "r");
10471047
add_patterns_from_input(&pl, argc, argv, fp);

config.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,11 +1612,6 @@ static int git_default_core_config(const char *var, const char *value,
16121612
return 0;
16131613
}
16141614

1615-
if (!strcmp(var, "core.sparsecheckoutcone")) {
1616-
core_sparse_checkout_cone = git_config_bool(var, value);
1617-
return 0;
1618-
}
1619-
16201615
if (!strcmp(var, "core.precomposeunicode")) {
16211616
precomposed_unicode = git_config_bool(var, value);
16221617
return 0;

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@ int get_sparse_checkout_patterns(struct pattern_list *pl)
34603460
int res;
34613461
char *sparse_filename = get_sparse_checkout_filename();
34623462

3463-
pl->use_cone_patterns = core_sparse_checkout_cone;
3463+
pl->use_cone_patterns = the_repository->settings.sparse_checkout_cone;
34643464
res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL, 0);
34653465

34663466
free(sparse_filename);

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
6464
#endif
6565
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
6666
int grafts_keep_true_parents;
67-
int core_sparse_checkout_cone;
6867
int sparse_expect_files_outside_of_patterns;
6968
int merge_log_config = -1;
7069
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */

environment.h

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

163-
extern int core_sparse_checkout_cone;
164163
extern int sparse_expect_files_outside_of_patterns;
165164

166165
enum rebase_setup_type {

repo-settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void prepare_repo_settings(struct repository *r)
8282
r->settings.pack_use_bitmap_boundary_traversal);
8383
repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1);
8484
repo_cfg_bool(r, "core.sparsecheckout", &r->settings.sparse_checkout, 0);
85+
repo_cfg_bool(r, "core.sparsecheckoutcone", &r->settings.sparse_checkout_cone, 0);
8586

8687
/*
8788
* The GIT_TEST_MULTI_PACK_INDEX variable is special in that

repo-settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ struct repo_settings {
6767
unsigned long big_file_threshold;
6868

6969
char *hooks_path;
70+
7071
int sparse_checkout;
72+
int sparse_checkout_cone;
7173
};
7274
#define REPO_SETTINGS_INIT { \
7375
.shared_repository = -1, \

sparse-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int index_has_unmerged_entries(struct index_state *istate)
151151
int is_sparse_index_allowed(struct index_state *istate, int flags)
152152
{
153153
prepare_repo_settings(istate->repo);
154-
if (!istate->repo->settings.sparse_checkout || !core_sparse_checkout_cone)
154+
if (!istate->repo->settings.sparse_checkout || !istate->repo->settings.sparse_checkout_cone)
155155
return 0;
156156

157157
if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) {

0 commit comments

Comments
 (0)