repository: move global r_f_p_c to repo struct

Move repository_format_partial_clone, which is currently a global variable, into struct repository. (Full support for per-repository partial clone config will be done in a subsequent commit - this is split into its own commit because of the extent of the changes needed.) The new repo-specific variable cannot be set in check_repository_format_gently() (as is currently), because that function does not know which repo it is operating on (or even whether the value is important); therefore this responsibility is delegated to the outermost caller that knows. Of all the outermost callers that know (found by looking at all functions that call clear_repository_format()), I looked at those that either read from the main Git directory or write into a struct repository. These callers have been modified accordingly (write to the_repository in the former case and write to the given struct repository in the latter case). Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jun 17, 2021 at 10:13 UTC ebaf3bcf1aecdc31062ede80fca3a7c98202d8bb
5 files changed +23 -20
promisor-remote.c
+3 -10
@@ -5,13 +5,6 @@
5 #include "transport.h"
6 #include "strvec.h"
7
8 -static char *repository_format_partial_clone;
9 -
10 -void set_repository_format_partial_clone(char *partial_clone)
11 -{
12 - repository_format_partial_clone = xstrdup_or_null(partial_clone);
13 -}
14 -
8 static int fetch_objects(const char *remote_name,
9 const struct object_id *oids,
10 int oid_nr)
@@ -145,15 +138,15 @@ static void promisor_remote_init(void)
138
139 git_config(promisor_remote_config, NULL);
140
148 - if (repository_format_partial_clone) {
141 + if (the_repository->repository_format_partial_clone) {
142 struct promisor_remote *o, *previous;
143
151 - o = promisor_remote_lookup(repository_format_partial_clone,
144 + o = promisor_remote_lookup(the_repository->repository_format_partial_clone,
145 &previous);
146 if (o)
147 promisor_remote_move_to_tail(o, previous);
148 else
156 - promisor_remote_new(repository_format_partial_clone);
149 + promisor_remote_new(the_repository->repository_format_partial_clone);
150 }
151 }
152
promisor-remote.h
-6
@@ -32,10 +32,4 @@ int promisor_remote_get_direct(struct repository *repo,
32 const struct object_id *oids,
33 int oid_nr);
34
35 -/*
36 - * This should be used only once from setup.c to set the value we got
37 - * from the extensions.partialclone config option.
38 - */
39 -void set_repository_format_partial_clone(char *partial_clone);
40 -
35 #endif /* PROMISOR_REMOTE_H */
repository.c
+4
@@ -172,6 +172,10 @@ int repo_init(struct repository *repo,
172
173 repo_set_hash_algo(repo, format.hash_algo);
174
175 + /* take ownership of format.partial_clone */
176 + repo->repository_format_partial_clone = format.partial_clone;
177 + format.partial_clone = NULL;
178 +
179 if (worktree)
180 repo_set_worktree(repo, worktree);
181
repository.h
+3
@@ -139,6 +139,9 @@ struct repository {
139 /* True if commit-graph has been disabled within this process. */
140 int commit_graph_disabled;
141
142 + /* Configurations related to promisor remotes. */
143 + char *repository_format_partial_clone;
144 +
145 /* Configurations */
146
147 /* Indicate if a repository has a different 'commondir' from 'gitdir' */
setup.c
+13 -4
@@ -468,8 +468,6 @@ static enum extension_result handle_extension_v0(const char *var,
468 data->precious_objects = git_config_bool(var, value);
469 return EXTENSION_OK;
470 } else if (!strcmp(ext, "partialclone")) {
471 - if (!value)
472 - return config_error_nonbool(var);
471 data->partial_clone = xstrdup(value);
472 return EXTENSION_OK;
473 } else if (!strcmp(ext, "worktreeconfig")) {
@@ -566,7 +564,6 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
564 }
565
566 repository_format_precious_objects = candidate->precious_objects;
569 - set_repository_format_partial_clone(candidate->partial_clone);
567 repository_format_worktree_config = candidate->worktree_config;
568 string_list_clear(&candidate->unknown_extensions, 0);
569 string_list_clear(&candidate->v1_only_extensions, 0);
@@ -1193,6 +1190,11 @@ int discover_git_directory(struct strbuf *commondir,
1190 return -1;
1191 }
1192
1193 + /* take ownership of candidate.partial_clone */
1194 + the_repository->repository_format_partial_clone =
1195 + candidate.partial_clone;
1196 + candidate.partial_clone = NULL;
1197 +
1198 clear_repository_format(&candidate);
1199 return 0;
1200 }
@@ -1300,8 +1302,13 @@ const char *setup_git_directory_gently(int *nongit_ok)
1302 gitdir = DEFAULT_GIT_DIR_ENVIRONMENT;
1303 setup_git_env(gitdir);
1304 }
1303 - if (startup_info->have_repository)
1305 + if (startup_info->have_repository) {
1306 repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
1307 + /* take ownership of repo_fmt.partial_clone */
1308 + the_repository->repository_format_partial_clone =
1309 + repo_fmt.partial_clone;
1310 + repo_fmt.partial_clone = NULL;
1311 + }
1312 }
1313 /*
1314 * Since precompose_string_if_needed() needs to look at
@@ -1386,6 +1393,8 @@ void check_repository_format(struct repository_format *fmt)
1393 check_repository_format_gently(get_git_dir(), fmt, NULL);
1394 startup_info->have_repository = 1;
1395 repo_set_hash_algo(the_repository, fmt->hash_algo);
1396 + the_repository->repository_format_partial_clone =
1397 + xstrdup_or_null(fmt->partial_clone);
1398 clear_repository_format(&repo_fmt);
1399 }
1400