@@ -899,21 +899,6 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress)
return res;
}
-static void fsck_refs(void)
-{
- struct child_process refs_verify = CHILD_PROCESS_INIT;
- child_process_init(&refs_verify);
- refs_verify.git_cmd = 1;
- strvec_pushl(&refs_verify.args, "refs", "verify", NULL);
- if (verbose)
- strvec_push(&refs_verify.args, "--verbose");
- if (check_strict)
- strvec_push(&refs_verify.args, "--strict");
-
- if (run_command(&refs_verify))
- errors_found |= ERROR_REFS;
-}
-
static char const * const fsck_usage[] = {
N_("git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n"
" [--[no-]full] [--strict] [--verbose] [--lost-found]\n"
@@ -1083,8 +1068,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
check_connectivity();
- fsck_refs();
-
if (the_repository->settings.core_commit_graph) {
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
@@ -235,7 +235,6 @@ static int fsck_vreport(struct fsck_options *options,
void *fsck_report,
enum fsck_msg_id msg_id, const char *fmt, va_list ap)
{
- va_list ap_copy;
struct strbuf sb = STRBUF_INIT;
enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
int result;
@@ -251,12 +250,10 @@ static int fsck_vreport(struct fsck_options *options,
prepare_msg_ids();
strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased);
- va_copy(ap_copy, ap);
- strbuf_vaddf(&sb, fmt, ap_copy);
+ strbuf_vaddf(&sb, fmt, ap);
result = options->error_func(options, fsck_report,
msg_type, msg_id, sb.buf);
strbuf_release(&sb);
- va_end(ap);
return result;
}
@@ -1391,5 +1388,6 @@ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o,
puts(oid_to_hex(report->oid));
return 0;
}
- return fsck_objects_error_function(o, fsck_report, msg_type,msg_id, message);
+ return fsck_objects_error_function(o, fsck_report,
+ msg_type, msg_id, message);
}
@@ -3414,26 +3414,25 @@ static int files_ref_store_remove_on_disk(struct ref_store *ref_store,
* the whole directory. This function is used as the callback for each
* regular file or symlink in the directory.
*/
-typedef int (*files_fsck_refs_fn)(struct fsck_options *o,
- const char *gitdir,
+typedef int (*files_fsck_refs_fn)(struct ref_store *ref_store,
+ struct fsck_options *o,
const char *refs_check_dir,
struct dir_iterator *iter);
-static int files_fsck_refs_name(struct fsck_options *o,
- const char *gitdir UNUSED,
+static int files_fsck_refs_name(struct ref_store *ref_store UNUSED,
+ struct fsck_options *o,
const char *refs_check_dir,
struct dir_iterator *iter)
{
struct strbuf sb = STRBUF_INIT;
- size_t len = 0;
int ret = 0;
/*
* Ignore the files ending with ".lock" as they may be lock files
* However, do not allow bare ".lock" files.
*/
- if (strip_suffix(iter->basename, ".lock", &len) && (len != 0))
- goto clean;
+ if (iter->basename[0] != '.' && ends_with(iter->basename, ".lock"))
+ goto cleanup;
if (check_refname_format(iter->basename, REFNAME_ALLOW_ONELEVEL)) {
struct fsck_ref_report report = { .path = NULL };
@@ -3445,7 +3444,7 @@ static int files_fsck_refs_name(struct fsck_options *o,
"invalid refname format");
}
-clean:
+cleanup:
strbuf_release(&sb);
return ret;
}
@@ -3455,13 +3454,12 @@ static int files_fsck_refs_dir(struct ref_store *ref_store,
const char *refs_check_dir,
files_fsck_refs_fn *fsck_refs_fn)
{
- const char *gitdir = ref_store->gitdir;
struct strbuf sb = STRBUF_INIT;
struct dir_iterator *iter;
int iter_status;
int ret = 0;
- strbuf_addf(&sb, "%s/%s", gitdir, refs_check_dir);
+ strbuf_addf(&sb, "%s/%s", ref_store->gitdir, refs_check_dir);
iter = dir_iterator_begin(sb.buf, 0);
if (!iter) {
@@ -3478,7 +3476,7 @@ static int files_fsck_refs_dir(struct ref_store *ref_store,
fprintf_ln(stderr, "Checking %s/%s",
refs_check_dir, iter->relative_path);
for (size_t i = 0; fsck_refs_fn[i]; i++) {
- if (fsck_refs_fn[i](o, gitdir, refs_check_dir, iter))
+ if (fsck_refs_fn[i](ref_store, o, refs_check_dir, iter))
ret = -1;
}
} else {
@@ -3507,7 +3505,7 @@ static int files_fsck_refs(struct ref_store *ref_store,
};
if (o->verbose)
- fprintf_ln(stderr, "Checking references consistency");
+ fprintf_ln(stderr, _("Checking references consistency"));
return files_fsck_refs_dir(ref_store, o, "refs", fsck_refs_fn);
}
@@ -26,7 +26,7 @@ test_expect_success 'ref name should be checked' '
git tag multi_hierarchy/tag-2 &&
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
- test_must_fail git fsck 2>err &&
+ test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
error: refs/heads/.branch-1: badRefName: invalid refname format
EOF
@@ -34,7 +34,7 @@ test_expect_success 'ref name should be checked' '
test_cmp expect err &&
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ &&
- test_must_fail git fsck 2>err &&
+ test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
error: refs/heads/@: badRefName: invalid refname format
EOF
@@ -42,7 +42,7 @@ test_expect_success 'ref name should be checked' '
test_cmp expect err &&
cp $tag_dir_prefix/multi_hierarchy/tag-2 $tag_dir_prefix/multi_hierarchy/@ &&
- test_must_fail git fsck 2>err &&
+ test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
error: refs/tags/multi_hierarchy/@: badRefName: invalid refname format
EOF
@@ -50,12 +50,12 @@ test_expect_success 'ref name should be checked' '
test_cmp expect err &&
cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock &&
- git fsck 2>err &&
+ git refs verify 2>err &&
rm $tag_dir_prefix/tag-1.lock &&
test_must_be_empty err &&
cp $tag_dir_prefix/tag-1 $tag_dir_prefix/.lock &&
- test_must_fail git fsck 2>err &&
+ test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
error: refs/tags/.lock: badRefName: invalid refname format
EOF
@@ -76,18 +76,16 @@ test_expect_success 'ref name check should be adapted into fsck messages' '
git checkout -b branch-2 &&
git tag tag-2 &&
-
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
- git -c fsck.badRefName=warn fsck 2>err &&
+ git -c fsck.badRefName=warn refs verify 2>err &&
cat >expect <<-EOF &&
warning: refs/heads/.branch-1: badRefName: invalid refname format
EOF
rm $branch_dir_prefix/.branch-1 &&
test_cmp expect err &&
-
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ &&
- git -c fsck.badRefName=ignore fsck 2>err &&
+ git -c fsck.badRefName=ignore refs verify 2>err &&
test_must_be_empty err
'