mirror of
https://github.com/git/git.git
synced 2026-01-09 17:46:37 +00:00
ref: support multiple worktrees check for refs
We have already set up the infrastructure to check the consistency for refs, but we do not support multiple worktrees. However, "git-fsck(1)" will check the refs of worktrees. As we decide to get feature parity with "git-fsck(1)", we need to set up support for multiple worktrees. Because each worktree has its own specific refs, instead of just showing the users "refs/worktree/foo", we need to display the full name such as "worktrees/<id>/refs/worktree/foo". So we should know the id of the worktree to get the full name. Add a new parameter "struct worktree *" for "refs-internal.h::fsck_fn". Then change the related functions to follow this new interface. The "packed-refs" only exists in the main worktree, so we should only check "packed-refs" in the main worktree. Use "is_main_worktree" method to skip checking "packed-refs" in "packed_fsck" function. Then, enhance the "files-backend.c::files_fsck_refs_dir" function to add "worktree/<id>/" prefix when we are not in the main worktree. Last, add a new test to check the refname when there are multiple worktrees to exercise the code. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: shejialuo <shejialuo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
56ca603957
commit
7c78d819e6
@@ -5,6 +5,7 @@
|
||||
#include "parse-options.h"
|
||||
#include "refs.h"
|
||||
#include "strbuf.h"
|
||||
#include "worktree.h"
|
||||
|
||||
#define REFS_MIGRATE_USAGE \
|
||||
N_("git refs migrate --ref-format=<format> [--dry-run]")
|
||||
@@ -66,6 +67,7 @@ out:
|
||||
static int cmd_refs_verify(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
struct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT;
|
||||
struct worktree **worktrees;
|
||||
const char * const verify_usage[] = {
|
||||
REFS_VERIFY_USAGE,
|
||||
NULL,
|
||||
@@ -75,7 +77,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix)
|
||||
OPT_BOOL(0, "strict", &fsck_refs_options.strict, N_("enable strict checking")),
|
||||
OPT_END(),
|
||||
};
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
argc = parse_options(argc, argv, prefix, options, verify_usage, 0);
|
||||
if (argc)
|
||||
@@ -84,9 +86,13 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix)
|
||||
git_config(git_fsck_config, &fsck_refs_options);
|
||||
prepare_repo_settings(the_repository);
|
||||
|
||||
ret = refs_fsck(get_main_ref_store(the_repository), &fsck_refs_options);
|
||||
worktrees = get_worktrees();
|
||||
for (size_t i = 0; worktrees[i]; i++)
|
||||
ret |= refs_fsck(get_worktree_ref_store(worktrees[i]),
|
||||
&fsck_refs_options, worktrees[i]);
|
||||
|
||||
fsck_options_clear(&fsck_refs_options);
|
||||
free_worktrees(worktrees);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user