environment: stop storing "core.preferSymlinkRefs" globally

Same as the preceding commit, storing the "core.preferSymlinkRefs" value globally is misdesigned as this setting may be set per repository. There is only a single user of this value anyway, namely the "files" backend. So let's just remove the global variable and read the value of this setting when initializing the backend. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Sep 12, 2024 at 13:30 UTC 8e2e8a33f3558524adeceeb1e2e7b64a367b0d08
4 files changed +4 -8
config.c
-5
@@ -1447,11 +1447,6 @@ static int git_default_core_config(const char *var, const char *value,
1447 return 0;
1448 }
1449
1450 - if (!strcmp(var, "core.prefersymlinkrefs")) {
1451 - prefer_symlink_refs = git_config_bool(var, value);
1452 - return 0;
1453 - }
1454 -
1450 if (!strcmp(var, "core.warnambiguousrefs")) {
1451 warn_ambiguous_refs = git_config_bool(var, value);
1452 return 0;
environment.c
-1
@@ -34,7 +34,6 @@ int has_symlinks = 1;
34 int minimum_abbrev = 4, default_abbrev = -1;
35 int ignore_case;
36 int assume_unchanged;
37 -int prefer_symlink_refs;
37 int is_bare_repository_cfg = -1; /* unspecified */
38 int warn_ambiguous_refs = 1;
39 int warn_on_object_refname_ambiguity = 1;
environment.h
-1
@@ -156,7 +156,6 @@ extern int has_symlinks;
156 extern int minimum_abbrev, default_abbrev;
157 extern int ignore_case;
158 extern int assume_unchanged;
159 -extern int prefer_symlink_refs;
159 extern int warn_ambiguous_refs;
160 extern int warn_on_object_refname_ambiguity;
161 extern char *apply_default_whitespace;
refs/files-backend.c
+4 -1
@@ -1,6 +1,7 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2
3 #include "../git-compat-util.h"
4 +#include "../config.h"
5 #include "../copy.h"
6 #include "../environment.h"
7 #include "../gettext.h"
@@ -76,6 +77,7 @@ struct files_ref_store {
77
78 char *gitcommondir;
79 enum log_refs_config log_all_ref_updates;
80 + int prefer_symlink_refs;
81
82 struct ref_cache *loose;
83
@@ -109,6 +111,7 @@ static struct ref_store *files_ref_store_init(struct repository *repo,
111 refs->packed_ref_store =
112 packed_ref_store_init(repo, refs->gitcommondir, flags);
113 refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
114 + repo_config_get_bool(repo, "core.prefersymlinkrefs", &refs->prefer_symlink_refs);
115
116 chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
117 chdir_notify_reparent("files-backend $GIT_COMMONDIR",
@@ -2942,7 +2945,7 @@ static int files_transaction_finish(struct ref_store *ref_store,
2945 * We try creating a symlink, if that succeeds we continue to the
2946 * next update. If not, we try and create a regular symref.
2947 */
2945 - if (update->new_target && prefer_symlink_refs)
2948 + if (update->new_target && refs->prefer_symlink_refs)
2949 if (!create_ref_symlink(lock, update->new_target))
2950 continue;
2951