Skip to content

Commit ebaf3bc

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebf3c04 commit ebaf3bc

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

promisor-remote.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
#include "transport.h"
66
#include "strvec.h"
77

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-
158
static int fetch_objects(const char *remote_name,
169
const struct object_id *oids,
1710
int oid_nr)
@@ -145,15 +138,15 @@ static void promisor_remote_init(void)
145138

146139
git_config(promisor_remote_config, NULL);
147140

148-
if (repository_format_partial_clone) {
141+
if (the_repository->repository_format_partial_clone) {
149142
struct promisor_remote *o, *previous;
150143

151-
o = promisor_remote_lookup(repository_format_partial_clone,
144+
o = promisor_remote_lookup(the_repository->repository_format_partial_clone,
152145
&previous);
153146
if (o)
154147
promisor_remote_move_to_tail(o, previous);
155148
else
156-
promisor_remote_new(repository_format_partial_clone);
149+
promisor_remote_new(the_repository->repository_format_partial_clone);
157150
}
158151
}
159152

promisor-remote.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,4 @@ int promisor_remote_get_direct(struct repository *repo,
3232
const struct object_id *oids,
3333
int oid_nr);
3434

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-
4135
#endif /* PROMISOR_REMOTE_H */

repository.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ int repo_init(struct repository *repo,
172172

173173
repo_set_hash_algo(repo, format.hash_algo);
174174

175+
/* take ownership of format.partial_clone */
176+
repo->repository_format_partial_clone = format.partial_clone;
177+
format.partial_clone = NULL;
178+
175179
if (worktree)
176180
repo_set_worktree(repo, worktree);
177181

repository.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ struct repository {
139139
/* True if commit-graph has been disabled within this process. */
140140
int commit_graph_disabled;
141141

142+
/* Configurations related to promisor remotes. */
143+
char *repository_format_partial_clone;
144+
142145
/* Configurations */
143146

144147
/* Indicate if a repository has a different 'commondir' from 'gitdir' */

setup.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,6 @@ static enum extension_result handle_extension_v0(const char *var,
468468
data->precious_objects = git_config_bool(var, value);
469469
return EXTENSION_OK;
470470
} else if (!strcmp(ext, "partialclone")) {
471-
if (!value)
472-
return config_error_nonbool(var);
473471
data->partial_clone = xstrdup(value);
474472
return EXTENSION_OK;
475473
} else if (!strcmp(ext, "worktreeconfig")) {
@@ -566,7 +564,6 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
566564
}
567565

568566
repository_format_precious_objects = candidate->precious_objects;
569-
set_repository_format_partial_clone(candidate->partial_clone);
570567
repository_format_worktree_config = candidate->worktree_config;
571568
string_list_clear(&candidate->unknown_extensions, 0);
572569
string_list_clear(&candidate->v1_only_extensions, 0);
@@ -1193,6 +1190,11 @@ int discover_git_directory(struct strbuf *commondir,
11931190
return -1;
11941191
}
11951192

1193+
/* take ownership of candidate.partial_clone */
1194+
the_repository->repository_format_partial_clone =
1195+
candidate.partial_clone;
1196+
candidate.partial_clone = NULL;
1197+
11961198
clear_repository_format(&candidate);
11971199
return 0;
11981200
}
@@ -1300,8 +1302,13 @@ const char *setup_git_directory_gently(int *nongit_ok)
13001302
gitdir = DEFAULT_GIT_DIR_ENVIRONMENT;
13011303
setup_git_env(gitdir);
13021304
}
1303-
if (startup_info->have_repository)
1305+
if (startup_info->have_repository) {
13041306
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+
}
13051312
}
13061313
/*
13071314
* Since precompose_string_if_needed() needs to look at
@@ -1386,6 +1393,8 @@ void check_repository_format(struct repository_format *fmt)
13861393
check_repository_format_gently(get_git_dir(), fmt, NULL);
13871394
startup_info->have_repository = 1;
13881395
repo_set_hash_algo(the_repository, fmt->hash_algo);
1396+
the_repository->repository_format_partial_clone =
1397+
xstrdup_or_null(fmt->partial_clone);
13891398
clear_repository_format(&repo_fmt);
13901399
}
13911400

0 commit comments

Comments
 (0)