Skip to content

Commit db227bc

Browse files
committed
Merge branch 'ob/core-attributesfile-in-repository'
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 394c180 + cf50830 commit db227bc

21 files changed

Lines changed: 111 additions & 42 deletions

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
@@ -1603,6 +1603,7 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts,
16031603
static int checkout_branch(struct checkout_opts *opts,
16041604
struct branch_info *new_branch_info)
16051605
{
1606+
struct repo_config_values *cfg = repo_config_values(the_repository);
16061607
int noop_switch = (!new_branch_info->name &&
16071608
!opts->new_branch &&
16081609
!opts->force_detach);
@@ -1646,7 +1647,7 @@ static int checkout_branch(struct checkout_opts *opts,
16461647
if (opts->track != BRANCH_TRACK_UNSPECIFIED)
16471648
die(_("'%s' cannot be used with '%s'"), "--detach", "-t");
16481649
} else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
1649-
opts->track = git_branch_track;
1650+
opts->track = cfg->branch_track;
16501651

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

builtin/clone.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,15 @@ 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);
620+
619621
strvec_pushl(&cmd.args, "-C", repo, "sparse-checkout", "set", NULL);
620622

621623
/*
622624
* We must apply the setting in the current process
623625
* for the later checkout to use the sparse-checkout file.
624626
*/
625-
core_apply_sparse_checkout = 1;
627+
cfg->apply_sparse_checkout = 1;
626628

627629
cmd.git_cmd = 1;
628630
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,
@@ -397,12 +398,14 @@ static int set_config(struct repository *repo,
397398
}
398399

399400
static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
401+
struct repo_config_values *cfg = repo_config_values(the_repository);
402+
400403
/* If not specified, use previous definition of cone mode */
401-
if (*cone_mode == -1 && core_apply_sparse_checkout)
404+
if (*cone_mode == -1 && cfg->apply_sparse_checkout)
402405
*cone_mode = core_sparse_checkout_cone;
403406

404407
/* Set cone/non-cone mode appropriately */
405-
core_apply_sparse_checkout = 1;
408+
cfg->apply_sparse_checkout = 1;
406409
if (*cone_mode == 1 || *cone_mode == -1) {
407410
core_sparse_checkout_cone = 1;
408411
return MODE_CONE_PATTERNS;
@@ -414,9 +417,10 @@ static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
414417
static int update_modes(struct repository *repo, int *cone_mode, int *sparse_index)
415418
{
416419
int mode, record_mode;
420+
struct repo_config_values *cfg = repo_config_values(the_repository);
417421

418422
/* Determine if we need to record the mode; ensure sparse checkout on */
419-
record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout;
423+
record_mode = (*cone_mode != -1) || !cfg->apply_sparse_checkout;
420424

421425
mode = update_cone_mode(cone_mode);
422426
if (record_mode && set_config(repo, mode))
@@ -682,6 +686,7 @@ static int modify_pattern_list(struct repository *repo,
682686
int result;
683687
int changed_config = 0;
684688
struct pattern_list *pl = xcalloc(1, sizeof(*pl));
689+
struct repo_config_values *cfg = repo_config_values(the_repository);
685690

686691
switch (m) {
687692
case ADD:
@@ -697,9 +702,9 @@ static int modify_pattern_list(struct repository *repo,
697702
break;
698703
}
699704

700-
if (!core_apply_sparse_checkout) {
705+
if (!cfg->apply_sparse_checkout) {
701706
set_config(repo, MODE_ALL_PATTERNS);
702-
core_apply_sparse_checkout = 1;
707+
cfg->apply_sparse_checkout = 1;
703708
changed_config = 1;
704709
}
705710

@@ -794,9 +799,10 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
794799
};
795800
struct strvec patterns = STRVEC_INIT;
796801
int ret;
802+
struct repo_config_values *cfg = repo_config_values(the_repository);
797803

798804
setup_work_tree();
799-
if (!core_apply_sparse_checkout)
805+
if (!cfg->apply_sparse_checkout)
800806
die(_("no sparse-checkout to add to"));
801807

802808
repo_read_index(repo);
@@ -903,9 +909,10 @@ static int sparse_checkout_reapply(int argc, const char **argv,
903909
N_("toggle the use of a sparse index")),
904910
OPT_END(),
905911
};
912+
struct repo_config_values *cfg = repo_config_values(the_repository);
906913

907914
setup_work_tree();
908-
if (!core_apply_sparse_checkout)
915+
if (!cfg->apply_sparse_checkout)
909916
die(_("must be in a sparse-checkout to reapply sparsity patterns"));
910917

911918
reapply_opts.cone_mode = -1;
@@ -958,6 +965,7 @@ static int sparse_checkout_clean(int argc, const char **argv,
958965
size_t worktree_len;
959966
int force = 0, dry_run = 0, verbose = 0;
960967
int require_force = 1;
968+
struct repo_config_values *cfg = repo_config_values(the_repository);
961969

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

969977
setup_work_tree();
970-
if (!core_apply_sparse_checkout)
978+
if (!cfg->apply_sparse_checkout)
971979
die(_("must be in a sparse-checkout to clean directories"));
972980
if (!core_sparse_checkout_cone)
973981
die(_("must be in a cone-mode sparse-checkout to clean directories"));
@@ -1031,9 +1039,10 @@ static int sparse_checkout_disable(int argc, const char **argv,
10311039
OPT_END(),
10321040
};
10331041
struct pattern_list pl;
1042+
struct repo_config_values *cfg = repo_config_values(the_repository);
10341043

10351044
/*
1036-
* We do not exit early if !core_apply_sparse_checkout; due to the
1045+
* We do not exit early if !repo->config_values.apply_sparse_checkout; due to the
10371046
* ability for users to manually muck things up between
10381047
* direct editing of .git/info/sparse-checkout
10391048
* running read-tree -m u HEAD or update-index --skip-worktree
@@ -1059,7 +1068,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
10591068
hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
10601069
hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);
10611070
pl.use_cone_patterns = 0;
1062-
core_apply_sparse_checkout = 1;
1071+
cfg->apply_sparse_checkout = 1;
10631072

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

0 commit comments

Comments
 (0)