Skip to content

Commit eafb126

Browse files
pks-tgitster
authored andcommitted
environment: stop storing "core.logAllRefUpdates" globally
The value of "core.logAllRefUpdates" is being stored in the global variable `log_all_ref_updates`. This design is somewhat aged nowadays, where it is entirely possible to access multiple repositories in the same process which all have different values for this setting. So using a single global variable to track it is plain wrong. Remove the global variable. Instead, we now provide a new function part of the repo-settings subsystem that parses the value for a specific repository. While that may require us to read the value multiple times, we work around this by reading it once when the ref backends are set up and caching the value there. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a20b88 commit eafb126

File tree

9 files changed

+32
-20
lines changed

9 files changed

+32
-20
lines changed

builtin/checkout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
951951
const char *old_desc, *reflog_msg;
952952
if (opts->new_branch) {
953953
if (opts->new_orphan_branch) {
954+
enum log_refs_config log_all_ref_updates =
955+
repo_settings_get_log_all_ref_updates(the_repository);
954956
char *refname;
955957

956958
refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);

config.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,16 +1452,6 @@ static int git_default_core_config(const char *var, const char *value,
14521452
return 0;
14531453
}
14541454

1455-
if (!strcmp(var, "core.logallrefupdates")) {
1456-
if (value && !strcasecmp(value, "always"))
1457-
log_all_ref_updates = LOG_REFS_ALWAYS;
1458-
else if (git_config_bool(var, value))
1459-
log_all_ref_updates = LOG_REFS_NORMAL;
1460-
else
1461-
log_all_ref_updates = LOG_REFS_NONE;
1462-
return 0;
1463-
}
1464-
14651455
if (!strcmp(var, "core.warnambiguousrefs")) {
14661456
warn_ambiguous_refs = git_config_bool(var, value);
14671457
return 0;

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ int sparse_expect_files_outside_of_patterns;
7777
int merge_log_config = -1;
7878
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7979
unsigned long pack_size_limit_cfg;
80-
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
8180
int max_allowed_tree_depth =
8281
#ifdef _MSC_VER
8382
/*

environment.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ extern int core_apply_sparse_checkout;
181181
extern int core_sparse_checkout_cone;
182182
extern int sparse_expect_files_outside_of_patterns;
183183

184-
extern enum log_refs_config log_all_ref_updates;
185-
186184
enum rebase_setup_type {
187185
AUTOREBASE_NEVER = 0,
188186
AUTOREBASE_LOCAL,

refs/files-backend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct files_ref_store {
7575
unsigned int store_flags;
7676

7777
char *gitcommondir;
78+
enum log_refs_config log_all_ref_updates;
7879

7980
struct ref_cache *loose;
8081

@@ -107,6 +108,7 @@ static struct ref_store *files_ref_store_init(struct repository *repo,
107108
refs->gitcommondir = strbuf_detach(&sb, NULL);
108109
refs->packed_ref_store =
109110
packed_ref_store_init(repo, refs->gitcommondir, flags);
111+
refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
110112

111113
chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
112114
chdir_notify_reparent("files-backend $GIT_COMMONDIR",
@@ -1704,7 +1706,7 @@ static int log_ref_setup(struct files_ref_store *refs,
17041706
const char *refname, int force_create,
17051707
int *logfd, struct strbuf *err)
17061708
{
1707-
enum log_refs_config log_refs_cfg = log_all_ref_updates;
1709+
enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
17081710
struct strbuf logfile_sb = STRBUF_INIT;
17091711
char *logfile;
17101712

refs/reftable-backend.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct reftable_ref_store {
5252
struct reftable_write_options write_options;
5353

5454
unsigned int store_flags;
55+
enum log_refs_config log_all_ref_updates;
5556
int err;
5657
};
5758

@@ -157,21 +158,21 @@ static struct reftable_stack *stack_for(struct reftable_ref_store *store,
157158
}
158159
}
159160

160-
static int should_write_log(struct ref_store *refs, const char *refname)
161+
static int should_write_log(struct reftable_ref_store *refs, const char *refname)
161162
{
162-
enum log_refs_config log_refs_cfg = log_all_ref_updates;
163+
enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
163164
if (log_refs_cfg == LOG_REFS_UNSET)
164165
log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
165166

166167
switch (log_refs_cfg) {
167168
case LOG_REFS_NONE:
168-
return refs_reflog_exists(refs, refname);
169+
return refs_reflog_exists(&refs->base, refname);
169170
case LOG_REFS_ALWAYS:
170171
return 1;
171172
case LOG_REFS_NORMAL:
172173
if (should_autocreate_reflog(log_refs_cfg, refname))
173174
return 1;
174-
return refs_reflog_exists(refs, refname);
175+
return refs_reflog_exists(&refs->base, refname);
175176
default:
176177
BUG("unhandled core.logAllRefUpdates value %d", log_refs_cfg);
177178
}
@@ -278,6 +279,7 @@ static struct ref_store *reftable_be_init(struct repository *repo,
278279
base_ref_store_init(&refs->base, repo, gitdir, &refs_be_reftable);
279280
strmap_init(&refs->worktree_stacks);
280281
refs->store_flags = store_flags;
282+
refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
281283

282284
refs->write_options.hash_id = repo->hash_algo->format_id;
283285
refs->write_options.default_permissions = calc_shared_perm(0666 & ~mask);
@@ -1220,7 +1222,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
12201222
} else if (!(u->flags & REF_SKIP_CREATE_REFLOG) &&
12211223
(u->flags & REF_HAVE_NEW) &&
12221224
(u->flags & REF_FORCE_CREATE_REFLOG ||
1223-
should_write_log(&arg->refs->base, u->refname))) {
1225+
should_write_log(arg->refs, u->refname))) {
12241226
struct reftable_log_record *log;
12251227
int create_reflog = 1;
12261228

repo-settings.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,19 @@ void prepare_repo_settings(struct repository *r)
124124
*/
125125
r->settings.command_requires_full_index = 1;
126126
}
127+
128+
enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)
129+
{
130+
const char *value;
131+
132+
if (!repo_config_get_string_tmp(repo, "core.logallrefupdates", &value)) {
133+
if (value && !strcasecmp(value, "always"))
134+
return LOG_REFS_ALWAYS;
135+
else if (git_config_bool("core.logallrefupdates", value))
136+
return LOG_REFS_NORMAL;
137+
else
138+
return LOG_REFS_NONE;
139+
}
140+
141+
return LOG_REFS_UNSET;
142+
}

repo-settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ struct repo_settings {
6565

6666
void prepare_repo_settings(struct repository *r);
6767

68+
/* Read the value for "core.logAllRefUpdates". */
69+
enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo);
70+
6871
#endif /* REPO_SETTINGS_H */

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ static int create_default_files(const char *template_path,
23542354
else {
23552355
git_config_set("core.bare", "false");
23562356
/* allow template config file to override the default */
2357-
if (log_all_ref_updates == LOG_REFS_UNSET)
2357+
if (repo_settings_get_log_all_ref_updates(the_repository) == LOG_REFS_UNSET)
23582358
git_config_set("core.logallrefupdates", "true");
23592359
if (needs_work_tree_config(original_git_dir, work_tree))
23602360
git_config_set("core.worktree", work_tree);

0 commit comments

Comments
 (0)