git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 01/14] fsck: drop `the_repository` in `fsck_walk()`
Date: Fri, 20 Mar 2026 12:47:06 +0100	[thread overview]
Message-ID: <20260320-b4-pks-fsck-without-the-repository-v1-1-6594f997926b@pks.im> (raw)
In-Reply-To: <20260320-b4-pks-fsck-without-the-repository-v1-0-6594f997926b@pks.im>

The function `fsck_walk()` and its object type specific functions
`fsck_walk_tree()` et al implicitly rely on `the_repository`. Remove
this dependency by injecting the repository as a parameter instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/fsck.c           |  6 +++---
 builtin/index-pack.c     |  2 +-
 builtin/unpack-objects.c |  2 +-
 fsck.c                   | 40 ++++++++++++++++++++++++++--------------
 fsck.h                   | 15 ++++++++++++---
 5 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9bab32effe..15477767c7 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -186,7 +186,7 @@ static void mark_object_reachable(struct object *obj)
 
 static int traverse_one_object(struct object *obj)
 {
-	int result = fsck_walk(obj, obj, &fsck_walk_options);
+	int result = fsck_walk(the_repository, obj, obj, &fsck_walk_options);
 
 	if (obj->type == OBJ_TREE) {
 		struct tree *tree = (struct tree *)obj;
@@ -244,7 +244,7 @@ static int mark_unreachable_referents(const struct object_id *oid,
 	}
 
 	options.walk = mark_used;
-	fsck_walk(obj, NULL, &options);
+	fsck_walk(the_repository, obj, NULL, &options);
 	if (obj->type == OBJ_TREE)
 		free_tree_buffer((struct tree *)obj);
 
@@ -413,7 +413,7 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
 			   printable_type(&obj->oid, obj->type),
 			   describe_object(&obj->oid));
 
-	if (fsck_walk(obj, NULL, &fsck_obj_options))
+	if (fsck_walk(the_repository, obj, NULL, &fsck_obj_options))
 		objerror(obj, _("broken links"));
 	err = fsck_object(obj, buffer, size, &fsck_obj_options);
 	if (err)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d1e47279a8..a3d37d34cc 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -954,7 +954,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			if (do_fsck_object &&
 			    fsck_object(obj, buf, size, &fsck_options))
 				die(_("fsck error in packed object"));
-			if (strict && fsck_walk(obj, NULL, &fsck_options))
+			if (strict && fsck_walk(the_repository, obj, NULL, &fsck_options))
 				die(_("Not all child objects of %s are reachable"), oid_to_hex(&obj->oid));
 			if (record_outgoing_links)
 				do_record_outgoing_links(obj);
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 6fc64e9e4b..52b62ff6d4 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -244,7 +244,7 @@ static int check_object(struct object *obj, enum object_type type,
 	if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options))
 		die("fsck error in packed object");
 	fsck_options.walk = check_object;
-	if (fsck_walk(obj, NULL, &fsck_options))
+	if (fsck_walk(the_repository, obj, NULL, &fsck_options))
 		die("Error on reachable objects of %s", oid_to_hex(&obj->oid));
 	write_cached_object(obj, obj_buf);
 	return 0;
diff --git a/fsck.c b/fsck.c
index 0f02cf8f77..c6b6f533be 100644
--- a/fsck.c
+++ b/fsck.c
@@ -353,14 +353,17 @@ const char *fsck_describe_object(struct fsck_options *options,
 	return buf->buf;
 }
 
-static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options)
+static int fsck_walk_tree(struct repository *repo,
+			  struct tree *tree,
+			  void *data,
+			  struct fsck_options *options)
 {
 	struct tree_desc desc;
 	struct name_entry entry;
 	int res = 0;
 	const char *name;
 
-	if (repo_parse_tree(the_repository, tree))
+	if (repo_parse_tree(repo, tree))
 		return -1;
 
 	name = fsck_get_object_name(options, &tree->object.oid);
@@ -375,14 +378,14 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
 			continue;
 
 		if (S_ISDIR(entry.mode)) {
-			obj = (struct object *)lookup_tree(the_repository, &entry.oid);
+			obj = (struct object *)lookup_tree(repo, &entry.oid);
 			if (name && obj)
 				fsck_put_object_name(options, &entry.oid, "%s%s/",
 						     name, entry.path);
 			result = options->walk(obj, OBJ_TREE, data, options);
 		}
 		else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
-			obj = (struct object *)lookup_blob(the_repository, &entry.oid);
+			obj = (struct object *)lookup_blob(repo, &entry.oid);
 			if (name && obj)
 				fsck_put_object_name(options, &entry.oid, "%s%s",
 						     name, entry.path);
@@ -401,7 +404,10 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
 	return res;
 }
 
-static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_options *options)
+static int fsck_walk_commit(struct repository *repo,
+			    struct commit *commit,
+			    void *data,
+			    struct fsck_options *options)
 {
 	int counter = 0, generation = 0, name_prefix_len = 0;
 	struct commit_list *parents;
@@ -409,7 +415,7 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
 	int result;
 	const char *name;
 
-	if (repo_parse_commit(the_repository, commit))
+	if (repo_parse_commit(repo, commit))
 		return -1;
 
 	name = fsck_get_object_name(options, &commit->object.oid);
@@ -417,7 +423,7 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
 		fsck_put_object_name(options, get_commit_tree_oid(commit),
 				     "%s:", name);
 
-	result = options->walk((struct object *) repo_get_commit_tree(the_repository, commit),
+	result = options->walk((struct object *) repo_get_commit_tree(repo, commit),
 			       OBJ_TREE, data, options);
 	if (result < 0)
 		return result;
@@ -470,34 +476,40 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
 	return res;
 }
 
-static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options)
+static int fsck_walk_tag(struct repository *repo,
+			 struct tag *tag,
+			 void *data,
+			 struct fsck_options *options)
 {
 	const char *name = fsck_get_object_name(options, &tag->object.oid);
 
-	if (parse_tag(the_repository, tag))
+	if (parse_tag(repo, tag))
 		return -1;
 	if (name)
 		fsck_put_object_name(options, &tag->tagged->oid, "%s", name);
 	return options->walk(tag->tagged, OBJ_ANY, data, options);
 }
 
-int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
+int fsck_walk(struct repository *repo,
+	      struct object *obj,
+	      void *data,
+	      struct fsck_options *options)
 {
 	if (!obj)
 		return -1;
 
 	if (obj->type == OBJ_NONE)
-		parse_object(the_repository, &obj->oid);
+		parse_object(repo, &obj->oid);
 
 	switch (obj->type) {
 	case OBJ_BLOB:
 		return 0;
 	case OBJ_TREE:
-		return fsck_walk_tree((struct tree *)obj, data, options);
+		return fsck_walk_tree(repo, (struct tree *)obj, data, options);
 	case OBJ_COMMIT:
-		return fsck_walk_commit((struct commit *)obj, data, options);
+		return fsck_walk_commit(repo, (struct commit *)obj, data, options);
 	case OBJ_TAG:
-		return fsck_walk_tag((struct tag *)obj, data, options);
+		return fsck_walk_tag(repo, (struct tag *)obj, data, options);
 	default:
 		error("Unknown object type for %s",
 		      fsck_describe_object(options, &obj->oid));
diff --git a/fsck.h b/fsck.h
index 65ecbb7fe1..4bd54865fe 100644
--- a/fsck.h
+++ b/fsck.h
@@ -208,14 +208,23 @@ struct fsck_options {
 	.error_func = fsck_refs_error_function, \
 }
 
-/* descend in all linked child objects
- * the return value is:
+/*
+ * Perform consistency checks for the given object and all of its decendents.
+ *
+ * If set, the `walk` callback function in the options structure will be called
+ * for every commit. The data parameter will be passed as callback data.
+ *
+ * Returns:
+ *
  *    -1	error in processing the object
  *    <0	return value of the callback, which lead to an abort
  *    >0	return value of the first signaled error >0 (in the case of no other errors)
  *    0		everything OK
  */
-int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
+int fsck_walk(struct repository *repo,
+	      struct object *obj,
+	      void *data,
+	      struct fsck_options *options);
 
 /*
  * Blob objects my pass a NULL data pointer, which indicates they are too large

-- 
2.53.0.1055.ga2ffed1127.dirty



  reply	other threads:[~2026-03-20 11:47 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 11:47 [PATCH 00/14] fsck: drop use of `the_repository` Patrick Steinhardt
2026-03-20 11:47 ` Patrick Steinhardt [this message]
2026-03-20 23:09   ` [PATCH 01/14] fsck: drop `the_repository` in `fsck_walk()` Junio C Hamano
2026-03-23 12:22     ` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 02/14] fsck: drop `the_repository` in `fsck_finish()` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 03/14] fsck: refactor interface to parse fsck options Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 04/14] fsck: drop `the_repository` in `fsck_set_msg_types()` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 05/14] fsck: stop relying on global state via `parse_oid_hex()` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 06/14] builtin/fsck: fix trivial dependence on `the_repository` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 07/14] builtin/fsck: stop using `the_repository` when snapshotting refs Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 08/14] builtin/fsck: stop using `the_repository` when checking refs Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 09/14] builtin/fsck: stop using `the_repository` when checking reflogs Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 10/14] builtin/fsck: stop using `the_repository` with loose objects Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 11/14] builtin/fsck: stop using `the_repository` when checking packed objects Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 12/14] builtin/fsck: stop using `the_repository` when marking objects Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 13/14] fsck: provide repository in `struct fsck_report_object` Patrick Steinhardt
2026-03-20 23:13   ` Junio C Hamano
2026-03-20 11:47 ` [PATCH 14/14] builtin/fsck: stop using `the_repository` in error reporting Patrick Steinhardt
2026-03-23 15:02 ` [PATCH v2 00/12] fsck: drop use of `the_repository` Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 01/12] fetch-pack: move fsck options into function scope Patrick Steinhardt
2026-03-23 15:43     ` Junio C Hamano
2026-03-23 15:02   ` [PATCH v2 02/12] fsck: initialize fsck options via a function Patrick Steinhardt
2026-03-23 15:48     ` Junio C Hamano
2026-03-23 15:02   ` [PATCH v2 03/12] fsck: store repository in fsck options Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 04/12] fsck: drop USE_THE_REPOSITORY Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 05/12] builtin/fsck: fix trivial dependence on `the_repository` Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 06/12] builtin/fsck: stop using `the_repository` when snapshotting refs Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 07/12] builtin/fsck: stop using `the_repository` when checking refs Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 08/12] builtin/fsck: stop using `the_repository` when checking reflogs Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 09/12] builtin/fsck: stop using `the_repository` with loose objects Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 10/12] builtin/fsck: stop using `the_repository` when checking packed objects Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 11/12] builtin/fsck: stop using `the_repository` when marking objects Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 12/12] builtin/fsck: stop using `the_repository` in error reporting Patrick Steinhardt
2026-03-31 22:05   ` [PATCH v2 00/12] fsck: drop use of `the_repository` Junio C Hamano
2026-03-31 22:50     ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260320-b4-pks-fsck-without-the-repository-v1-1-6594f997926b@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).