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:

committed by
Junio C Hamano

parent
b0afdce5da
commit
d24eda4e03
@ -805,7 +805,7 @@ static int batch_objects(struct batch_options *opt)
|
|||||||
if (repo_has_promisor_remote(the_repository))
|
if (repo_has_promisor_remote(the_repository))
|
||||||
warning("This repository uses promisor remotes. Some objects may not be loaded.");
|
warning("This repository uses promisor remotes. Some objects may not be loaded.");
|
||||||
|
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
|
|
||||||
cb.opt = opt;
|
cb.opt = opt;
|
||||||
cb.expand = &data;
|
cb.expand = &data;
|
||||||
|
@ -324,7 +324,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
save_commit_buffer = 0;
|
save_commit_buffer = 0;
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options,
|
argc = parse_options(argc, argv, prefix, options,
|
||||||
|
@ -927,7 +927,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
|||||||
fetch_if_missing = 0;
|
fetch_if_missing = 0;
|
||||||
|
|
||||||
errors_found = 0;
|
errors_found = 0;
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
save_commit_buffer = 0;
|
save_commit_buffer = 0;
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
|
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
|
||||||
|
@ -1752,7 +1752,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
|
|||||||
if (argc == 2 && !strcmp(argv[1], "-h"))
|
if (argc == 2 && !strcmp(argv[1], "-h"))
|
||||||
usage(index_pack_usage);
|
usage(index_pack_usage);
|
||||||
|
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
fsck_options.walk = mark_link;
|
fsck_options.walk = mark_link;
|
||||||
|
|
||||||
reset_pack_idx_option(&opts);
|
reset_pack_idx_option(&opts);
|
||||||
|
@ -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))
|
if (DFS_NUM_STATES > (1 << OE_DFS_STATE_BITS))
|
||||||
BUG("too many dfs states, increase 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);
|
sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1);
|
||||||
if (the_repository->gitdir) {
|
if (the_repository->gitdir) {
|
||||||
|
@ -164,7 +164,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
expire = TIME_MAX;
|
expire = TIME_MAX;
|
||||||
save_commit_buffer = 0;
|
save_commit_buffer = 0;
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
repo_init_revisions(the_repository, &revs, prefix);
|
repo_init_revisions(the_repository, &revs, prefix);
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
|
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
|
||||||
|
@ -566,7 +566,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
|
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
|
||||||
|
@ -609,7 +609,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
|
|||||||
int i;
|
int i;
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
|
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
|
|||||||
};
|
};
|
||||||
|
|
||||||
packet_trace_identity("upload-pack");
|
packet_trace_identity("upload-pack");
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
|
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ void setup_git_env(const char *git_dir)
|
|||||||
strvec_clear(&to_free);
|
strvec_clear(&to_free);
|
||||||
|
|
||||||
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
|
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
|
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
|
||||||
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
|
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
|
||||||
: "refs/replace/");
|
: "refs/replace/");
|
||||||
|
2
git.c
2
git.c
@ -185,7 +185,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
|
|||||||
if (envchanged)
|
if (envchanged)
|
||||||
*envchanged = 1;
|
*envchanged = 1;
|
||||||
} else if (!strcmp(cmd, "--no-replace-objects")) {
|
} else if (!strcmp(cmd, "--no-replace-objects")) {
|
||||||
read_replace_refs = 0;
|
disable_replace_refs();
|
||||||
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
|
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
|
||||||
if (envchanged)
|
if (envchanged)
|
||||||
*envchanged = 1;
|
*envchanged = 1;
|
||||||
|
@ -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));
|
die(_("replace depth too high for object %s"), oid_to_hex(oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void disable_replace_refs(void)
|
||||||
|
{
|
||||||
|
read_replace_refs = 0;
|
||||||
|
}
|
||||||
|
@ -48,4 +48,12 @@ static inline const struct object_id *lookup_replace_object(struct repository *r
|
|||||||
return do_lookup_replace_object(r, oid);
|
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 */
|
#endif /* REPLACE_OBJECT_H */
|
||||||
|
Reference in New Issue
Block a user