Skip to content

Commit 32cd60a

Browse files
committed
Merge branch 'ac/deglobal-sparse-variables' into seen
* ac/deglobal-sparse-variables: environment: remove the global variable 'sparse_expect_files_outside_of_patterns' environment: move access to "core.sparsecheckoutcone" into repo_settings environment: move access to "core.sparsecheckout" into repo_settings
2 parents 4f5106f + 05d32fd commit 32cd60a

15 files changed

+46
-73
lines changed

builtin/backfill.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* We need this macro to access core_apply_sparse_checkout */
2-
#define USE_THE_REPOSITORY_VARIABLE
3-
41
#include "builtin.h"
52
#include "git-compat-util.h"
63
#include "config.h"
@@ -137,9 +134,9 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
137134
0);
138135

139136
repo_config(repo, git_default_config, NULL);
140-
137+
prepare_repo_settings(repo);
141138
if (ctx.sparse < 0)
142-
ctx.sparse = core_apply_sparse_checkout;
139+
ctx.sparse = repo->settings.sparse_checkout;
143140

144141
result = do_backfill(&ctx);
145142
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/grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static int grep_submodule(struct grep_opt *opt,
481481
* "forget" the sparse-index feature switch. As a result, the index
482482
* of these submodules are expanded unexpectedly.
483483
*
484-
* 2. "core_apply_sparse_checkout"
484+
* 2. "sparse_checkout"
485485
* When running `grep` in the superproject, this setting is
486486
* populated using the superproject's configs. However, once
487487
* initialized, this config is globally accessible and is read by
@@ -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. "sparse_checkout_cone"
495495
* ditto.
496496
*
497497
* Note that this list is not exhaustive.

builtin/mv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ 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 &&
576-
core_sparse_checkout_cone) {
575+
the_repository->settings.sparse_checkout &&
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: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
6262
int res;
6363

6464
setup_work_tree();
65-
if (!core_apply_sparse_checkout)
65+
if (!the_repository->settings.sparse_checkout)
6666
die(_("this worktree is not sparse"));
6767

6868
argc = parse_options(argc, argv, prefix,
@@ -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);
@@ -397,16 +397,16 @@ static int set_config(enum sparse_checkout_mode mode)
397397

398398
static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
399399
/* If not specified, use previous definition of cone mode */
400-
if (*cone_mode == -1 && core_apply_sparse_checkout)
401-
*cone_mode = core_sparse_checkout_cone;
400+
if (*cone_mode == -1 && the_repository->settings.sparse_checkout)
401+
*cone_mode = the_repository->settings.sparse_checkout_cone;
402402

403403
/* Set cone/non-cone mode appropriately */
404-
core_apply_sparse_checkout = 1;
404+
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

@@ -415,7 +415,7 @@ static int update_modes(int *cone_mode, int *sparse_index)
415415
int mode, record_mode;
416416

417417
/* Determine if we need to record the mode; ensure sparse checkout on */
418-
record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout;
418+
record_mode = (*cone_mode != -1) || !the_repository->settings.sparse_checkout;
419419

420420
mode = update_cone_mode(cone_mode);
421421
if (record_mode && set_config(mode))
@@ -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);
@@ -695,9 +695,9 @@ static int modify_pattern_list(struct strvec *args, int use_stdin,
695695
break;
696696
}
697697

698-
if (!core_apply_sparse_checkout) {
698+
if (!the_repository->settings.sparse_checkout) {
699699
set_config(MODE_ALL_PATTERNS);
700-
core_apply_sparse_checkout = 1;
700+
the_repository->settings.sparse_checkout = 1;
701701
changed_config = 1;
702702
}
703703

@@ -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]);
@@ -793,7 +793,7 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
793793
int ret;
794794

795795
setup_work_tree();
796-
if (!core_apply_sparse_checkout)
796+
if (!the_repository->settings.sparse_checkout)
797797
die(_("no sparse-checkout to add to"));
798798

799799
repo_read_index(the_repository);
@@ -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 {
@@ -902,7 +902,7 @@ static int sparse_checkout_reapply(int argc, const char **argv,
902902
};
903903

904904
setup_work_tree();
905-
if (!core_apply_sparse_checkout)
905+
if (!the_repository->settings.sparse_checkout)
906906
die(_("must be in a sparse-checkout to reapply sparsity patterns"));
907907

908908
reapply_opts.cone_mode = -1;
@@ -935,7 +935,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
935935
struct pattern_list pl;
936936

937937
/*
938-
* We do not exit early if !core_apply_sparse_checkout; due to the
938+
* We do not exit early if !sparse_checkout; due to the
939939
* ability for users to manually muck things up between
940940
* direct editing of .git/info/sparse-checkout
941941
* running read-tree -m u HEAD or update-index --skip-worktree
@@ -961,7 +961,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
961961
hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
962962
hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);
963963
pl.use_cone_patterns = 0;
964-
core_apply_sparse_checkout = 1;
964+
the_repository->settings.sparse_checkout = 1;
965965

966966
add_pattern("/*", empty_base, 0, &pl, 0);
967967

@@ -1042,7 +1042,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
10421042
check_rules_opts.cone_mode = 1;
10431043

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

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
/*

config.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,16 +1607,6 @@ static int git_default_core_config(const char *var, const char *value,
16071607
return 0;
16081608
}
16091609

1610-
if (!strcmp(var, "core.sparsecheckout")) {
1611-
core_apply_sparse_checkout = git_config_bool(var, value);
1612-
return 0;
1613-
}
1614-
1615-
if (!strcmp(var, "core.sparsecheckoutcone")) {
1616-
core_sparse_checkout_cone = git_config_bool(var, value);
1617-
return 0;
1618-
}
1619-
16201610
if (!strcmp(var, "core.precomposeunicode")) {
16211611
precomposed_unicode = git_config_bool(var, value);
16221612
return 0;
@@ -1641,17 +1631,6 @@ static int git_default_core_config(const char *var, const char *value,
16411631
return platform_core_config(var, value, ctx, cb);
16421632
}
16431633

1644-
static int git_default_sparse_config(const char *var, const char *value)
1645-
{
1646-
if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) {
1647-
sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
1648-
return 0;
1649-
}
1650-
1651-
/* Add other config variables here and to Documentation/config/sparse.adoc. */
1652-
return 0;
1653-
}
1654-
16551634
static int git_default_i18n_config(const char *var, const char *value)
16561635
{
16571636
if (!strcmp(var, "i18n.commitencoding")) {
@@ -1813,9 +1792,6 @@ int git_default_config(const char *var, const char *value,
18131792
return 0;
18141793
}
18151794

1816-
if (starts_with(var, "sparse."))
1817-
return git_default_sparse_config(var, value);
1818-
18191795
/* Add other config variables here and to Documentation/config.adoc. */
18201796
return 0;
18211797
}

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ enum pattern_match_result path_matches_pattern_list(
15161516

15171517
int init_sparse_checkout_patterns(struct index_state *istate)
15181518
{
1519-
if (!core_apply_sparse_checkout)
1519+
if (!istate->repo->settings.sparse_checkout)
15201520
return 1;
15211521
if (istate->sparse_checkout_patterns)
15221522
return 0;
@@ -3472,7 +3472,7 @@ int get_sparse_checkout_patterns(struct pattern_list *pl)
34723472
int res;
34733473
char *sparse_filename = get_sparse_checkout_filename();
34743474

3475-
pl->use_cone_patterns = core_sparse_checkout_cone;
3475+
pl->use_cone_patterns = the_repository->settings.sparse_checkout_cone;
34763476
res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL, 0);
34773477

34783478
free(sparse_filename);

environment.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +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_apply_sparse_checkout;
68-
int core_sparse_checkout_cone;
69-
int sparse_expect_files_outside_of_patterns;
7067
int merge_log_config = -1;
7168
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7269
unsigned long pack_size_limit_cfg;

environment.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ extern int precomposed_unicode;
159159
extern int protect_hfs;
160160
extern int protect_ntfs;
161161

162-
extern int core_apply_sparse_checkout;
163-
extern int core_sparse_checkout_cone;
164-
extern int sparse_expect_files_outside_of_patterns;
165-
166162
enum rebase_setup_type {
167163
AUTOREBASE_NEVER = 0,
168164
AUTOREBASE_LOCAL,

repo-settings.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ 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);
88+
repo_cfg_bool(r, "core.sparsecheckoutcone", &r->settings.sparse_checkout_cone, 0);
8789

8890
/*
8991
* The GIT_TEST_MULTI_PACK_INDEX variable is special in that

repo-settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ struct repo_settings {
6868
unsigned long big_file_threshold;
6969

7070
char *hooks_path;
71+
72+
int sparse_checkout;
73+
int sparse_checkout_cone;
7174
};
7275
#define REPO_SETTINGS_INIT { \
7376
.shared_repository = -1, \

sparse-index.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
@@ -150,7 +149,7 @@ static int index_has_unmerged_entries(struct index_state *istate)
150149

151150
int is_sparse_index_allowed(struct index_state *istate, int flags)
152151
{
153-
if (!core_apply_sparse_checkout || !core_sparse_checkout_cone)
152+
if (!istate->repo->settings.sparse_checkout || !istate->repo->settings.sparse_checkout_cone)
154153
return 0;
155154

156155
if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) {
@@ -668,7 +667,10 @@ static void clear_skip_worktree_from_present_files_full(struct index_state *ista
668667

669668
void clear_skip_worktree_from_present_files(struct index_state *istate)
670669
{
671-
if (!core_apply_sparse_checkout ||
670+
int sparse_expect_files_outside_of_patterns = 0;
671+
repo_config_get_bool(istate->repo, "sparse.expectfilesoutsideofpatterns",
672+
&sparse_expect_files_outside_of_patterns);
673+
if (!istate->repo->settings.sparse_checkout ||
672674
sparse_expect_files_outside_of_patterns)
673675
return;
674676

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
19241924
if (o->prefix)
19251925
update_sparsity_for_prefix(o->prefix, o->src_index);
19261926

1927-
if (!core_apply_sparse_checkout || !o->update)
1927+
if (!repo->settings.sparse_checkout || !o->update)
19281928
o->skip_sparse_checkout = 1;
19291929
if (!o->skip_sparse_checkout) {
19301930
memset(&pl, 0, sizeof(pl));

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ static void wt_status_check_sparse_checkout(struct repository *r,
17731773
int skip_worktree = 0;
17741774
int i;
17751775

1776-
if (!core_apply_sparse_checkout || r->index->cache_nr == 0) {
1776+
if (!r->settings.sparse_checkout || r->index->cache_nr == 0) {
17771777
/*
17781778
* Don't compute percentage of checked out files if we
17791779
* aren't in a sparse checkout or would get division by 0.

0 commit comments

Comments
 (0)