1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-09 06:46:16 +02:00

repository: create disable_replace_refs()

Several builtins depend on being able to disable the replace references
so we actually operate on each object individually. These currently do
so by directly mutating the 'read_replace_refs' global.

A future change will move this global into a different place, so it will
be necessary to change all of these lines. However, we can simplify that
transition by abstracting the purpose of these global assignments with a
method call.

We will need to keep this read_replace_refs global forever, as we want
to make sure that we never use replace refs throughout the life of the
process if this method is called. Future changes may present a
repository-scoped version of the variable to represent that repository's
core.useReplaceRefs config value, but a zero-valued read_replace_refs
will always override such a setting.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee 2023-06-06 13:24:35 +00:00 committed by Junio C Hamano
parent b0afdce5da
commit d24eda4e03
13 changed files with 24 additions and 11 deletions

View File

@ -805,7 +805,7 @@ static int batch_objects(struct batch_options *opt)
if (repo_has_promisor_remote(the_repository))
warning("This repository uses promisor remotes. Some objects may not be loaded.");
read_replace_refs = 0;
disable_replace_refs();
cb.opt = opt;
cb.expand = &data;

View File

@ -324,7 +324,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
read_replace_refs = 0;
disable_replace_refs();
save_commit_buffer = 0;
argc = parse_options(argc, argv, prefix, options,

View File

@ -927,7 +927,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
fetch_if_missing = 0;
errors_found = 0;
read_replace_refs = 0;
disable_replace_refs();
save_commit_buffer = 0;
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);

View File

@ -1752,7 +1752,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(index_pack_usage);
read_replace_refs = 0;
disable_replace_refs();
fsck_options.walk = mark_link;
reset_pack_idx_option(&opts);

View File

@ -4284,7 +4284,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (DFS_NUM_STATES > (1 << OE_DFS_STATE_BITS))
BUG("too many dfs states, increase OE_DFS_STATE_BITS");
read_replace_refs = 0;
disable_replace_refs();
sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1);
if (the_repository->gitdir) {

View File

@ -164,7 +164,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
expire = TIME_MAX;
save_commit_buffer = 0;
read_replace_refs = 0;
disable_replace_refs();
repo_init_revisions(the_repository, &revs, prefix);
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);

View File

@ -566,7 +566,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
OPT_END()
};
read_replace_refs = 0;
disable_replace_refs();
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);

View File

@ -609,7 +609,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
int i;
struct object_id oid;
read_replace_refs = 0;
disable_replace_refs();
git_config(git_default_config, NULL);

View File

@ -36,7 +36,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
};
packet_trace_identity("upload-pack");
read_replace_refs = 0;
disable_replace_refs();
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);

View File

@ -185,7 +185,7 @@ void setup_git_env(const char *git_dir)
strvec_clear(&to_free);
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0;
disable_replace_refs();
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
: "refs/replace/");

2
git.c
View File

@ -185,7 +185,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--no-replace-objects")) {
read_replace_refs = 0;
disable_replace_refs();
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
if (envchanged)
*envchanged = 1;

View File

@ -84,3 +84,8 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
}
die(_("replace depth too high for object %s"), oid_to_hex(oid));
}
void disable_replace_refs(void)
{
read_replace_refs = 0;
}

View File

@ -48,4 +48,12 @@ static inline const struct object_id *lookup_replace_object(struct repository *r
return do_lookup_replace_object(r, oid);
}
/*
* Some commands override config and environment settings for using
* replace references. Use this method to disable the setting and ensure
* those other settings will not override this choice. This applies
* globally to all in-process repositories.
*/
void disable_replace_refs(void);
#endif /* REPLACE_OBJECT_H */