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

[PATCH 04/14] fsck: drop `the_repository` in `fsck_set_msg_types()`

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 20, 2026, 11:47 UTC
Message-ID
<20260320-b4-pks-fsck-without-the-repository-v1-4-6594f997926b@pks.im>
In-Reply-To
<20260320-b4-pks-fsck-without-the-repository-v1-0-6594f997926b@pks.im>

We implicitly rely on `the_repository` in `fsck_set_msg_types()` because of our reliance on `the_hash_algo`. Fix this dependency on global state by requiring the callers to provide the hash function.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/index-pack.c     |  6 ++++--
 builtin/unpack-objects.c |  3 ++-
 fsck.c                   | 27 +++++++++++++++++++--------
 fsck.h                   |  3 ++-
 4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 3d1f7dbd5f..c4117e5970 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1932,13 +1932,15 @@ int cmd_index_pack(int argc,
 			} else if (skip_to_optional_arg(arg, "--strict", &arg)) {
 				strict = 1;
 				do_fsck_object = 1;
-				fsck_set_msg_types(&fsck_options, arg);
+				fsck_set_msg_types(&fsck_options, arg,
+						   the_hash_algo);
 			} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
 				strict = 1;
 				check_self_contained_and_connected = 1;
 			} else if (skip_to_optional_arg(arg, "--fsck-objects", &arg)) {
 				do_fsck_object = 1;
-				fsck_set_msg_types(&fsck_options, arg);
+				fsck_set_msg_types(&fsck_options, arg,
+						   the_hash_algo);
 			} else if (!strcmp(arg, "--verify")) {
 				verify = 1;
 			} else if (!strcmp(arg, "--verify-stat")) {
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 9596b3ea4f..3e748a55d9 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -649,7 +649,8 @@ int cmd_unpack_objects(int argc,
 			}
 			if (skip_prefix(arg, "--strict=", &arg)) {
 				strict = 1;
-				fsck_set_msg_types(&fsck_options, arg);
+				fsck_set_msg_types(&fsck_options, arg,
+						   the_hash_algo);
 				continue;
 			}
 			if (skip_prefix(arg, "--pack_header=", &arg)) {
diff --git a/fsck.c b/fsck.c
index a7ebab9581..efd987dd2b 100644
--- a/fsck.c
+++ b/fsck.c
@@ -182,7 +182,8 @@ void fsck_set_msg_type(struct fsck_options *options,
 	free(to_free);
 }
 
-void fsck_set_msg_types(struct fsck_options *options, const char *values)
+void fsck_set_msg_types(struct fsck_options *options, const char *values,
+			const struct git_hash_algo *algo)
 {
 	char *buf = xstrdup(values), *to_free = buf;
 	int done = 0;
@@ -207,7 +208,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
 			if (equal == len)
 				die("skiplist requires a path");
 			oidset_parse_file(&options->skip_oids, buf + equal + 1,
-					  the_repository->hash_algo);
+					  algo);
 			buf += len + 1;
 			continue;
 		}
@@ -1404,11 +1405,16 @@ void fsck_options_clear(struct fsck_options *options)
 	kh_clear_oid_map(options->object_names);
 }
 
+struct fsck_options_parse_config_key_data {
+	struct repository *repo;
+	struct fsck_options *options;
+};
+
 static int fsck_options_parse_config_key(const char *var, const char *value,
 					 const struct config_context *ctx,
-					 void *cb)
+					 void *cb_data)
 {
-	struct fsck_options *options = cb;
+	struct fsck_options_parse_config_key_data *data = cb_data;
 	const char *msg_id;
 
 	if (strcmp(var, "fsck.skiplist") == 0) {
@@ -1420,7 +1426,8 @@ static int fsck_options_parse_config_key(const char *var, const char *value,
 			struct strbuf sb = STRBUF_INIT;
 			strbuf_addf(&sb, "skiplist=%s", path);
 			free(path);
-			fsck_set_msg_types(options, sb.buf);
+			fsck_set_msg_types(data->options, sb.buf,
+					   data->repo->hash_algo);
 			strbuf_release(&sb);
 		}
 		return 0;
@@ -1429,17 +1436,21 @@ static int fsck_options_parse_config_key(const char *var, const char *value,
 	if (skip_prefix(var, "fsck.", &msg_id)) {
 		if (!value)
 			return config_error_nonbool(var);
-		fsck_set_msg_type(options, msg_id, value);
+		fsck_set_msg_type(data->options, msg_id, value);
 		return 0;
 	}
 
-	return git_default_config(var, value, ctx, cb);
+	return git_default_config(var, value, ctx, cb_data);
 }
 
 void fsck_options_parse_config(struct fsck_options *options,
 			       struct repository *repo)
 {
-	repo_config(repo, fsck_options_parse_config_key, options);
+	struct fsck_options_parse_config_key_data data = {
+		.repo = repo,
+		.options = options,
+	};
+	repo_config(repo, fsck_options_parse_config_key, &data);
 }
 
 /*
diff --git a/fsck.h b/fsck.h
index 7d0d876103..3ca1683f74 100644
--- a/fsck.h
+++ b/fsck.h
@@ -118,7 +118,8 @@ void fsck_set_msg_type_from_ids(struct fsck_options *options,
 				enum fsck_msg_type msg_type);
 void fsck_set_msg_type(struct fsck_options *options,
 		       const char *msg_id, const char *msg_type);
-void fsck_set_msg_types(struct fsck_options *options, const char *values);
+void fsck_set_msg_types(struct fsck_options *options, const char *values,
+			const struct git_hash_algo *algo);
 int is_valid_msg_type(const char *msg_id, const char *msg_type);
 
 /*
-- 
2.53.0.1055.ga2ffed1127.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 7 of 18 in “fsck: drop use of `the_repository`”
  1. 00/14 fsck: drop use of `the_repository`Patrick Steinhardt, Mar 20, 2026
  2. 01/14 fsck: drop `the_repository` in `fsck_walk()`Patrick Steinhardt, Mar 20, 2026
  3. Junio C HamanoMar 20, 2026
  4. Patrick SteinhardtMar 23, 2026
  5. 02/14 fsck: drop `the_repository` in `fsck_finish()`Patrick Steinhardt, Mar 20, 2026
  6. 03/14 fsck: refactor interface to parse fsck optionsPatrick Steinhardt, Mar 20, 2026
  7. 04/14 fsck: drop `the_repository` in `fsck_set_msg_types()`Patrick Steinhardt, Mar 20, 2026
  8. 05/14 fsck: stop relying on global state via `parse_oid_hex()`Patrick Steinhardt, Mar 20, 2026
  9. 06/14 builtin/fsck: fix trivial dependence on `the_repository`Patrick Steinhardt, Mar 20, 2026
  10. 07/14 builtin/fsck: stop using `the_repository` when snapshotting refsPatrick Steinhardt, Mar 20, 2026
  11. 08/14 builtin/fsck: stop using `the_repository` when checking refsPatrick Steinhardt, Mar 20, 2026
  12. 09/14 builtin/fsck: stop using `the_repository` when checking reflogsPatrick Steinhardt, Mar 20, 2026
  13. 10/14 builtin/fsck: stop using `the_repository` with loose objectsPatrick Steinhardt, Mar 20, 2026
  14. 11/14 builtin/fsck: stop using `the_repository` when checking packed objectsPatrick Steinhardt, Mar 20, 2026
  15. 12/14 builtin/fsck: stop using `the_repository` when marking objectsPatrick Steinhardt, Mar 20, 2026
  16. 13/14 fsck: provide repository in `struct fsck_report_object`Patrick Steinhardt, Mar 20, 2026
  17. Junio C HamanoMar 20, 2026
  18. 14/14 builtin/fsck: stop using `the_repository` in error reportingPatrick Steinhardt, Mar 20, 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.