summaryrefslogtreecommitdiff
path: root/refs/files-backend.c
diff options
context:
space:
mode:
authorshejialuo <shejialuo@gmail.com>2024-11-20 19:51:16 +0800
committerJunio C Hamano <gitster@pobox.com>2024-11-21 08:21:31 +0900
commit32dc1c7ec3c4e92704f221abbfee5cc1d50bf473 (patch)
treeed4350666679626cb952a1da1d3538efe19979a9 /refs/files-backend.c
parent38cd6eead19f3d7359ebd34cae6f2a37de4ccc10 (diff)
ref: check the full refname instead of basename
In "files-backend.c::files_fsck_refs_name", we validate the refname format by using "check_refname_format" to check the basename of the iterator with "REFNAME_ALLOW_ONELEVEL" flag. However, this is a bad implementation. Although we doesn't allow a single "@" in ".git" directory, we do allow "refs/heads/@". So, we will report an error wrongly when there is a "refs/heads/@" ref by using one level refname "@". Because we just check one level refname, we either cannot check the other parts of the full refname. And we will ignore the following errors: "refs/heads/ new-feature/test" "refs/heads/~new-feature/test" In order to fix the above problem, enhance "files_fsck_refs_name" to use the full name for "check_refname_format". Then, replace the tests which are related to "@" and add tests to exercise the above situations using for loop to avoid repetition. 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>
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r--refs/files-backend.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 03d2503276..b055edc061 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3519,10 +3519,13 @@ static int files_fsck_refs_name(struct ref_store *ref_store UNUSED,
if (iter->basename[0] != '.' && ends_with(iter->basename, ".lock"))
goto cleanup;
- if (check_refname_format(iter->basename, REFNAME_ALLOW_ONELEVEL)) {
+ /*
+ * This works right now because we never check the root refs.
+ */
+ strbuf_addf(&sb, "%s/%s", refs_check_dir, iter->relative_path);
+ if (check_refname_format(sb.buf, 0)) {
struct fsck_ref_report report = { 0 };
- strbuf_addf(&sb, "%s/%s", refs_check_dir, iter->relative_path);
report.path = sb.buf;
ret = fsck_report_ref(o, &report,
FSCK_MSG_BAD_REF_NAME,