Skip to content

Commit 3b32210

Browse files
committed
Merge branch 'ob/core-attributesfile-in-repository' into seen
The core.attributesfile is intended to be set per repository, but were kept track of by a single global variable in-core, which has been corrected by moving it to per-repository data structure. * ob/core-attributesfile-in-repository: environment: move "branch.autoSetupMerge" into `struct repo_config_values` environment: stop using core.sparseCheckout globally environment: stop storing `core.attributesFile` globally
2 parents e1bef88 + 03dfb92 commit 3b32210

20 files changed

+104
-42
lines changed

attr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,11 @@ const char *git_attr_system_file(void)
881881

882882
const char *git_attr_global_file(void)
883883
{
884-
if (!git_attributes_file)
885-
git_attributes_file = xdg_config_home("attributes");
884+
struct repo_config_values *cfg = repo_config_values(the_repository);
885+
if (!cfg->attributes_file)
886+
cfg->attributes_file = xdg_config_home("attributes");
886887

887-
return git_attributes_file;
888+
return cfg->attributes_file;
888889
}
889890

890891
int git_attr_system_is_enabled(void)

branch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ enum branch_track {
1515
BRANCH_TRACK_SIMPLE,
1616
};
1717

18-
extern enum branch_track git_branch_track;
19-
2018
/* Functions for acting on the information about branches. */
2119

2220
/**

builtin/backfill.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
128128
N_("Restrict the missing objects to the current sparse-checkout")),
129129
OPT_END(),
130130
};
131+
struct repo_config_values *cfg = repo_config_values(the_repository);
131132

132133
show_usage_with_options_if_asked(argc, argv,
133134
builtin_backfill_usage, options);
@@ -138,7 +139,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
138139
repo_config(repo, git_default_config, NULL);
139140

140141
if (ctx.sparse < 0)
141-
ctx.sparse = core_apply_sparse_checkout;
142+
ctx.sparse = cfg->apply_sparse_checkout;
142143

143144
result = do_backfill(&ctx);
144145
backfill_context_clear(&ctx);

builtin/branch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ int cmd_branch(int argc,
724724
static struct ref_sorting *sorting;
725725
struct string_list sorting_options = STRING_LIST_INIT_DUP;
726726
struct ref_format format = REF_FORMAT_INIT;
727+
struct repo_config_values *cfg = repo_config_values(the_repository);
727728
int ret;
728729

729730
struct option options[] = {
@@ -795,7 +796,7 @@ int cmd_branch(int argc,
795796
if (!sorting_options.nr)
796797
string_list_append(&sorting_options, "refname");
797798

798-
track = git_branch_track;
799+
track = cfg->branch_track;
799800

800801
head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
801802
0, &head_oid, NULL);

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,7 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts,
16081608
static int checkout_branch(struct checkout_opts *opts,
16091609
struct branch_info *new_branch_info)
16101610
{
1611+
struct repo_config_values *cfg = repo_config_values(the_repository);
16111612
int noop_switch = (!new_branch_info->name &&
16121613
!opts->new_branch &&
16131614
!opts->force_detach);
@@ -1651,7 +1652,7 @@ static int checkout_branch(struct checkout_opts *opts,
16511652
if (opts->track != BRANCH_TRACK_UNSPECIFIED)
16521653
die(_("'%s' cannot be used with '%s'"), "--detach", "-t");
16531654
} else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
1654-
opts->track = git_branch_track;
1655+
opts->track = cfg->branch_track;
16551656

16561657
if (new_branch_info->name && !new_branch_info->commit)
16571658
die(_("Cannot switch branch to a non-commit '%s'"),

builtin/clone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,14 @@ static int git_sparse_checkout_init(const char *repo)
616616
{
617617
struct child_process cmd = CHILD_PROCESS_INIT;
618618
int result = 0;
619+
struct repo_config_values *cfg = repo_config_values(the_repository);
619620
strvec_pushl(&cmd.args, "-C", repo, "sparse-checkout", "set", NULL);
620621

621622
/*
622623
* We must apply the setting in the current process
623624
* for the later checkout to use the sparse-checkout file.
624625
*/
625-
core_apply_sparse_checkout = 1;
626+
cfg->apply_sparse_checkout = 1;
626627

627628
cmd.git_cmd = 1;
628629
if (run_command(&cmd)) {

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static int grep_submodule(struct grep_opt *opt,
482482
* "forget" the sparse-index feature switch. As a result, the index
483483
* of these submodules are expanded unexpectedly.
484484
*
485-
* 2. "core_apply_sparse_checkout"
485+
* 2. "config_values_private_.apply_sparse_checkout"
486486
* When running `grep` in the superproject, this setting is
487487
* populated using the superproject's configs. However, once
488488
* initialized, this config is globally accessible and is read by

builtin/mv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ int cmd_mv(int argc,
238238
struct hashmap moved_dirs = HASHMAP_INIT(pathmap_cmp, NULL);
239239
struct strbuf pathbuf = STRBUF_INIT;
240240
int ret;
241+
struct repo_config_values *cfg = repo_config_values(the_repository);
241242

242243
repo_config(the_repository, git_default_config, NULL);
243244

@@ -572,7 +573,7 @@ int cmd_mv(int argc,
572573
rename_index_entry_at(the_repository->index, pos, dst);
573574

574575
if (ignore_sparse &&
575-
core_apply_sparse_checkout &&
576+
cfg->apply_sparse_checkout &&
576577
core_sparse_checkout_cone) {
577578
/*
578579
* NEEDSWORK: we are *not* paying attention to

builtin/push.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static NORETURN void die_push_simple(struct branch *branch,
151151
const char *advice_pushdefault_maybe = "";
152152
const char *advice_automergesimple_maybe = "";
153153
const char *short_upstream = branch->merge[0]->src;
154+
struct repo_config_values *cfg = repo_config_values(the_repository);
154155

155156
skip_prefix(short_upstream, "refs/heads/", &short_upstream);
156157

@@ -162,7 +163,7 @@ static NORETURN void die_push_simple(struct branch *branch,
162163
advice_pushdefault_maybe = _("\n"
163164
"To choose either option permanently, "
164165
"see push.default in 'git help config'.\n");
165-
if (git_branch_track != BRANCH_TRACK_SIMPLE)
166+
if (cfg->branch_track != BRANCH_TRACK_SIMPLE)
166167
advice_automergesimple_maybe = _("\n"
167168
"To avoid automatically configuring "
168169
"an upstream branch when its name\n"

builtin/sparse-checkout.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
6161
struct pattern_list pl;
6262
char *sparse_filename;
6363
int res;
64+
struct repo_config_values *cfg = repo_config_values(the_repository);
6465

6566
setup_work_tree();
66-
if (!core_apply_sparse_checkout)
67+
if (!cfg->apply_sparse_checkout)
6768
die(_("this worktree is not sparse"));
6869

6970
argc = parse_options(argc, argv, prefix,
@@ -398,12 +399,14 @@ static int set_config(struct repository *repo,
398399
}
399400

400401
static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
402+
struct repo_config_values *cfg = repo_config_values(the_repository);
403+
401404
/* If not specified, use previous definition of cone mode */
402-
if (*cone_mode == -1 && core_apply_sparse_checkout)
405+
if (*cone_mode == -1 && cfg->apply_sparse_checkout)
403406
*cone_mode = core_sparse_checkout_cone;
404407

405408
/* Set cone/non-cone mode appropriately */
406-
core_apply_sparse_checkout = 1;
409+
cfg->apply_sparse_checkout = 1;
407410
if (*cone_mode == 1 || *cone_mode == -1) {
408411
core_sparse_checkout_cone = 1;
409412
return MODE_CONE_PATTERNS;
@@ -415,9 +418,10 @@ static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
415418
static int update_modes(struct repository *repo, int *cone_mode, int *sparse_index)
416419
{
417420
int mode, record_mode;
421+
struct repo_config_values *cfg = repo_config_values(the_repository);
418422

419423
/* Determine if we need to record the mode; ensure sparse checkout on */
420-
record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout;
424+
record_mode = (*cone_mode != -1) || !cfg->apply_sparse_checkout;
421425

422426
mode = update_cone_mode(cone_mode);
423427
if (record_mode && set_config(repo, mode))
@@ -683,6 +687,7 @@ static int modify_pattern_list(struct repository *repo,
683687
int result;
684688
int changed_config = 0;
685689
struct pattern_list *pl = xcalloc(1, sizeof(*pl));
690+
struct repo_config_values *cfg = repo_config_values(the_repository);
686691

687692
switch (m) {
688693
case ADD:
@@ -698,9 +703,9 @@ static int modify_pattern_list(struct repository *repo,
698703
break;
699704
}
700705

701-
if (!core_apply_sparse_checkout) {
706+
if (!cfg->apply_sparse_checkout) {
702707
set_config(repo, MODE_ALL_PATTERNS);
703-
core_apply_sparse_checkout = 1;
708+
cfg->apply_sparse_checkout = 1;
704709
changed_config = 1;
705710
}
706711

@@ -795,9 +800,10 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
795800
};
796801
struct strvec patterns = STRVEC_INIT;
797802
int ret;
803+
struct repo_config_values *cfg = repo_config_values(the_repository);
798804

799805
setup_work_tree();
800-
if (!core_apply_sparse_checkout)
806+
if (!cfg->apply_sparse_checkout)
801807
die(_("no sparse-checkout to add to"));
802808

803809
repo_read_index(repo);
@@ -904,9 +910,10 @@ static int sparse_checkout_reapply(int argc, const char **argv,
904910
N_("toggle the use of a sparse index")),
905911
OPT_END(),
906912
};
913+
struct repo_config_values *cfg = repo_config_values(the_repository);
907914

908915
setup_work_tree();
909-
if (!core_apply_sparse_checkout)
916+
if (!cfg->apply_sparse_checkout)
910917
die(_("must be in a sparse-checkout to reapply sparsity patterns"));
911918

912919
reapply_opts.cone_mode = -1;
@@ -959,6 +966,7 @@ static int sparse_checkout_clean(int argc, const char **argv,
959966
size_t worktree_len;
960967
int force = 0, dry_run = 0, verbose = 0;
961968
int require_force = 1;
969+
struct repo_config_values *cfg = repo_config_values(the_repository);
962970

963971
struct option builtin_sparse_checkout_clean_options[] = {
964972
OPT__DRY_RUN(&dry_run, N_("dry run")),
@@ -968,7 +976,7 @@ static int sparse_checkout_clean(int argc, const char **argv,
968976
};
969977

970978
setup_work_tree();
971-
if (!core_apply_sparse_checkout)
979+
if (!cfg->apply_sparse_checkout)
972980
die(_("must be in a sparse-checkout to clean directories"));
973981
if (!core_sparse_checkout_cone)
974982
die(_("must be in a cone-mode sparse-checkout to clean directories"));
@@ -1032,9 +1040,10 @@ static int sparse_checkout_disable(int argc, const char **argv,
10321040
OPT_END(),
10331041
};
10341042
struct pattern_list pl;
1043+
struct repo_config_values *cfg = repo_config_values(the_repository);
10351044

10361045
/*
1037-
* We do not exit early if !core_apply_sparse_checkout; due to the
1046+
* We do not exit early if !repo->config_values.apply_sparse_checkout; due to the
10381047
* ability for users to manually muck things up between
10391048
* direct editing of .git/info/sparse-checkout
10401049
* running read-tree -m u HEAD or update-index --skip-worktree
@@ -1060,7 +1069,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
10601069
hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
10611070
hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);
10621071
pl.use_cone_patterns = 0;
1063-
core_apply_sparse_checkout = 1;
1072+
cfg->apply_sparse_checkout = 1;
10641073

10651074
add_pattern("/*", empty_base, 0, &pl, 0);
10661075

0 commit comments

Comments
 (0)