From: Patrick Steinhardt Date: Mon, 12 Jan 2026 09:02:49 GMT Subject: [PATCH v2 00/17] Fixes and improvements for ref consistency checks Message-ID: <20260112-pks-refs-verify-fixes-v2-0-2e9e453bd6c3@pks.im> In-Reply-To: <20260109-pks-refs-verify-fixes-v1-0-3587dba18294@pks.im> Hi, this patch series contains a bunch of fixes and improvements for ref consistency checks. It is structured as follows: - Patches 1 to 4 contain a couple of cleanups for the consistency checks done by the "files" backend. - Patches 5 to 7 introduce checks for root refs for the "files" backend. - Patches 9 to 14 introduce infrastructure for shared checks with the "files" and "reftable" backend. - Patches 15 to 17 move some ref consistency checks that were still driven by git-fsck(1) into `git refs verify`. Changes in v2: - Remove unused `errors_found` field. - Fix a commit message typo. - Fix a copy-paste error in a function comment. - Link to v1: https://lore.kernel.org/r/20260109-pks-refs-verify-fixes-v1-0-3587dba18294@pks.im Thanks! Patrick --- Patrick Steinhardt (17): refs/files: simplify iterating through root refs refs/files: move fsck functions into global scope refs/files: remove `refs_check_dir` parameter refs/files: remove useless indirection refs/files: extract function to check single ref refs/files: improve error handling when verifying symrefs refs/files: perform consistency checks for root refs fsck: drop unused fields from `struct fsck_ref_report` refs/files: extract generic symref target checks refs/files: introduce function to perform normal ref checks refs/reftable: adapt includes to become consistent refs/reftable: extract function to retrieve backend for worktree refs/reftable: fix consistency checks with worktrees refs/reftable: introduce generic checks for refs builtin/fsck: move generic object ID checks into `refs_fsck()` builtin/fsck: move generic HEAD check into `refs_fsck()` builtin/fsck: drop `fsck_head_link()` Documentation/fsck-msgids.adoc | 6 ++ builtin/fsck.c | 46 +-------- fsck.c | 5 - fsck.h | 4 +- refs.c | 43 ++++++++ refs.h | 18 ++++ refs/files-backend.c | 228 ++++++++++++++++++++++++----------------- refs/reftable-backend.c | 167 ++++++++++++++++++++++-------- t/t0602-reffiles-fsck.sh | 30 ++++++ t/t0614-reftable-fsck.sh | 44 ++++++++ t/t1450-fsck.sh | 10 +- 11 files changed, 414 insertions(+), 187 deletions(-) Range-diff versus v1: 1: 201451626d = 1: 21531efb05 refs/files: simplify iterating through root refs 2: 88252f2b99 = 2: 861bd57d6e refs/files: move fsck functions into global scope 3: 56d8ce2c85 = 3: e06b8bdd23 refs/files: remove `refs_check_dir` parameter 4: ddf450134c = 4: 92992a522e refs/files: remove useless indirection 5: 2d3ebf80fd = 5: 904fecf80e refs/files: extract function to check single ref 6: 316dafeff8 = 6: b5f5e86f1f refs/files: improve error handling when verifying symrefs 7: 94a9b3d58b ! 7: d1abff98f8 refs/files: perform consistency checks for root refs @@ refs/files-backend.c: static int files_fsck_refs_dir(struct ref_store *ref_store + struct worktree *wt; + struct strbuf refname; + struct strbuf path; -+ bool errors_found; +}; + +static int files_fsck_root_ref(const char *refname, void *cb_data) @@ refs/files-backend.c: static int files_fsck_refs_dir(struct ref_store *ref_store if (files_fsck_refs_dir(ref_store, o, wt) < 0) ret = -1; + -+ if (for_each_root_ref(refs, files_fsck_root_ref, &data) < 0 || -+ data.errors_found) ++ if (for_each_root_ref(refs, files_fsck_root_ref, &data) < 0) + ret = -1; + if (refs->packed_ref_store->be->fsck(refs->packed_ref_store, o, wt) < 0) 8: a773fd65e9 = 8: 0b0e0e0033 fsck: drop unused fields from `struct fsck_ref_report` 9: 12cf39ce8c ! 9: 4bf249e530 refs/files: extract generic symref target checks @@ Commit message Reimplementing these checks for every single backend doesn't really make sense. Extract it into a generic `refs_fsck_symref()` function that can - be used my other backends, as well. The "reftable" backend will be wired + be used by other backends, as well. The "reftable" backend will be wired up in a subsequent commit. While at it, improve the consistency checks so that we don't complain 10: 9ae96c0acb ! 10: 5bd34fb53c refs/files: introduce function to perform normal ref checks @@ refs.h: int check_refname_format(const char *refname, int flags); struct fsck_ref_report; +/* -+ * Perform generic checks for a specific symref target. This function is ++ * Perform generic checks for a specific direct ref. This function is + * expected to be called by the ref backends for every symbolic ref. + */ +int refs_fsck_ref(struct ref_store *refs, struct fsck_options *o, 11: c2b0a1f517 = 11: ca62b50abc refs/reftable: adapt includes to become consistent 12: 608b689d9e = 12: 66b5d6c981 refs/reftable: extract function to retrieve backend for worktree 13: d39733206f = 13: d31b7fb348 refs/reftable: fix consistency checks with worktrees 14: 37b8d22941 = 14: eb960e66f2 refs/reftable: introduce generic checks for refs 15: 72b81062d2 = 15: d0e2e3fe33 builtin/fsck: move generic object ID checks into `refs_fsck()` 16: 07a2403bc7 = 16: 029d02dd8a builtin/fsck: move generic HEAD check into `refs_fsck()` 17: e944a0e430 = 17: 99eb06f153 builtin/fsck: drop `fsck_head_link()` --- base-commit: d529f3a197364881746f558e5652f0236131eb86 change-id: 20260109-pks-refs-verify-fixes-1e47872317cf