git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 10/12] builtin/fsck: stop using `the_repository` when checking packed objects

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 23, 2026, 15:03 UTC
Message-ID
<20260323-b4-pks-fsck-without-the-repository-v2-10-e8dc79bca651@pks.im>
In-Reply-To
<20260323-b4-pks-fsck-without-the-repository-v2-0-e8dc79bca651@pks.im>

We implicitly rely on `the_repository` when checking objects part of a packfile. These objects are iterated over via `verify_pack()`, which is provided by the packfile subsystem, and a callback function is then invoked for each of the objects in that specific pack.

Unfortunately, it is not possible to provide a payload to the callback function. Refactor `verify_pack()` to accept a payload that is passed through to the callback so that we can inject the repository and get rid of the use of `the_repository`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/fsck.c | 11 ++++++-----
 pack-check.c   |  7 ++++---
 pack.h         |  9 +++++++--
 3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e8bdec7cd0..22ca1200a2 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -447,15 +447,16 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
 }
 
 static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
-			   unsigned long size, void *buffer, int *eaten)
+			   unsigned long size, void *buffer, int *eaten, void *cb_data)
 {
+	struct repository *repo = cb_data;
+	struct object *obj;
+
 	/*
 	 * Note, buffer may be NULL if type is OBJ_BLOB. See
 	 * verify_packfile(), data_valid variable for details.
 	 */
-	struct object *obj;
-	obj = parse_object_buffer(the_repository, oid, type, size, buffer,
-				  eaten);
+	obj = parse_object_buffer(repo, oid, type, size, buffer, eaten);
 	if (!obj) {
 		errors_found |= ERROR_OBJECT;
 		return error(_("%s: object corrupt or missing"),
@@ -1089,7 +1090,7 @@ int cmd_fsck(int argc,
 			repo_for_each_pack(repo, p) {
 				/* verify gives error messages itself */
 				if (verify_pack(repo,
-						p, fsck_obj_buffer,
+						p, fsck_obj_buffer, repo,
 						progress, count))
 					errors_found |= ERROR_PACK;
 				count += p->num_objects;
diff --git a/pack-check.c b/pack-check.c
index 7378c80730..79992bb509 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -53,6 +53,7 @@ static int verify_packfile(struct repository *r,
 			   struct packed_git *p,
 			   struct pack_window **w_curs,
 			   verify_fn fn,
+			   void *fn_data,
 			   struct progress *progress, uint32_t base_count)
 
 {
@@ -161,7 +162,7 @@ static int verify_packfile(struct repository *r,
 				    oid_to_hex(&oid), p->pack_name);
 		else if (fn) {
 			int eaten = 0;
-			err |= fn(&oid, type, size, data, &eaten);
+			err |= fn(&oid, type, size, data, &eaten, fn_data);
 			if (eaten)
 				data = NULL;
 		}
@@ -192,7 +193,7 @@ int verify_pack_index(struct packed_git *p)
 	return err;
 }
 
-int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn,
+int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn, void *fn_data,
 		struct progress *progress, uint32_t base_count)
 {
 	int err = 0;
@@ -202,7 +203,7 @@ int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn,
 	if (!p->index_data)
 		return -1;
 
-	err |= verify_packfile(r, p, &w_curs, fn, progress, base_count);
+	err |= verify_packfile(r, p, &w_curs, fn, fn_data, progress, base_count);
 	unuse_pack(&w_curs);
 
 	return err;
diff --git a/pack.h b/pack.h
index ec76472e49..1cde92082b 100644
--- a/pack.h
+++ b/pack.h
@@ -85,7 +85,11 @@ struct pack_idx_entry {
 
 struct progress;
 /* Note, the data argument could be NULL if object type is blob */
-typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*);
+typedef int (*verify_fn)(const struct object_id *oid,
+			 enum object_type type,
+			 unsigned long size,
+			 void *buffer, int *eaten,
+			 void *fn_data);
 
 const char *write_idx_file(struct repository *repo,
 			   const char *index_name,
@@ -95,7 +99,8 @@ const char *write_idx_file(struct repository *repo,
 			   const unsigned char *sha1);
 int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
 int verify_pack_index(struct packed_git *);
-int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t);
+int verify_pack(struct repository *, struct packed_git *, verify_fn fn, void *fn_data,
+		struct progress *, uint32_t);
 off_t write_pack_header(struct hashfile *f, uint32_t);
 void fixup_pack_header_footer(const struct git_hash_algo *, int,
 			      unsigned char *, const char *, uint32_t,
-- 
2.53.0.1118.gaef5881109.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 13 of 17 in “fsck: drop use of `the_repository`”
  1. 00/12 fsck: drop use of `the_repository`Patrick Steinhardt, Mar 23, 2026
  2. 01/12 fetch-pack: move fsck options into function scopePatrick Steinhardt, Mar 23, 2026
  3. Junio C HamanoMar 23, 2026
  4. 02/12 fsck: initialize fsck options via a functionPatrick Steinhardt, Mar 23, 2026
  5. Junio C HamanoMar 23, 2026
  6. 03/12 fsck: store repository in fsck optionsPatrick Steinhardt, Mar 23, 2026
  7. 04/12 fsck: drop USE_THE_REPOSITORYPatrick Steinhardt, Mar 23, 2026
  8. 05/12 builtin/fsck: fix trivial dependence on `the_repository`Patrick Steinhardt, Mar 23, 2026
  9. 06/12 builtin/fsck: stop using `the_repository` when snapshotting refsPatrick Steinhardt, Mar 23, 2026
  10. 07/12 builtin/fsck: stop using `the_repository` when checking refsPatrick Steinhardt, Mar 23, 2026
  11. 08/12 builtin/fsck: stop using `the_repository` when checking reflogsPatrick Steinhardt, Mar 23, 2026
  12. 09/12 builtin/fsck: stop using `the_repository` with loose objectsPatrick Steinhardt, Mar 23, 2026
  13. 10/12 builtin/fsck: stop using `the_repository` when checking packed objectsPatrick Steinhardt, Mar 23, 2026
  14. 11/12 builtin/fsck: stop using `the_repository` when marking objectsPatrick Steinhardt, Mar 23, 2026
  15. 12/12 builtin/fsck: stop using `the_repository` in error reportingPatrick Steinhardt, Mar 23, 2026
  16. Junio C HamanoMar 31, 2026
  17. Patrick SteinhardtMar 31, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.