84
unsigned int store_flags;
85
86
char *gitcommondir;
87
- enum log_refs_config log_all_ref_updates;
88
- int prefer_symlink_refs;
89
-
87
struct ref_cache *loose;
91
-
88
struct ref_store *packed_ref_store;
89
+
90
+ /*
91
+ * Options used when writing references. These are parsed from the
92
+ * config lazily on first use via `files_ref_store_write_options()` so
93
+ * that we don't have to access the configuration when initializing the
94
+ * ref store. Do not access these fields directly, but use the accessor
95
+ * instead.
96
+ */
97
+ struct files_ref_store_write_options {
98
+ enum log_refs_config log_all_ref_updates;
99
+ int prefer_symlink_refs;
100
+ bool initialized;
101
+ } write_opts_lazy_loaded;
102
};
103
104
static void clear_loose_ref_cache(struct files_ref_store *refs)
130
const struct config_context *ctx UNUSED,
131
void *payload)
132
{
124
- struct files_ref_store *refs = payload;
133
+ struct files_ref_store_write_options *opts = payload;
134
135
if (!strcmp(var, "core.prefersymlinkrefs")) {
127
- refs->prefer_symlink_refs = git_config_bool(var, value);
136
+ opts->prefer_symlink_refs = git_config_bool(var, value);
137
} else if (!strcmp(var, "core.logallrefupdates")) {
129
- refs->log_all_ref_updates = refs_parse_log_all_ref_updates_config(value);
138
+ opts->log_all_ref_updates = refs_parse_log_all_ref_updates_config(value);
139
}
140
141
return 0;
142
}
143
144
+static const struct files_ref_store_write_options *files_ref_store_write_options(struct files_ref_store *refs)
145
+{
146
+ struct files_ref_store_write_options *opts = &refs->write_opts_lazy_loaded;
147
+
148
+ if (opts->initialized)
149
+ return opts;
150
+
151
+ opts->log_all_ref_updates = LOG_REFS_UNSET;
152
+ repo_config(refs->base.repo, files_ref_store_config, opts);
153
+
154
+ opts->initialized = true;
155
+ return opts;
156
+}
157
+
158
/*
159
* Create a new submodule ref cache and add it to the internal
160
* set of caches.
179
refs->packed_ref_store =
180
packed_ref_store_init(repo, NULL, refs->gitcommondir, opts);
181
refs->store_flags = opts->access_flags;
159
- refs->log_all_ref_updates = LOG_REFS_UNSET;
182
161
- repo_config(repo, files_ref_store_config, refs);
183
chdir_notify_register(NULL, files_ref_store_reparent, refs);
184
185
strbuf_release(&refdir);
1911
const char *refname, int force_create,
1912
int *logfd, struct strbuf *err)
1913
{
1893
- enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
1914
+ enum log_refs_config log_refs_cfg = files_ref_store_write_options(refs)->log_all_ref_updates;
1915
struct strbuf logfile_sb = STRBUF_INIT;
1916
char *logfile;
1917
3322
{
3323
struct files_ref_store *refs =
3324
files_downcast(ref_store, 0, "ref_transaction_finish");
3325
+ const struct files_ref_store_write_options *write_opts = files_ref_store_write_options(refs);
3326
size_t i;
3327
int ret = 0;
3328
struct strbuf sb = STRBUF_INIT;
3362
* We try creating a symlink, if that succeeds we continue to the
3363
* next update. If not, we try and create a regular symref.
3364
*/
3343
- if (update->new_target && refs->prefer_symlink_refs)
3365
+ if (update->new_target && write_opts->prefer_symlink_refs)
3366
/*
3367
* By using the `NOT_CONSTANT()` trick, we can avoid
3368
* errors by `clang`'s `-Wunreachable` logic that would