builtin/fsck: stop using `the_repository` in error reporting

In the preceding commit we have introduced the repository into `struct fsck_object_report`. This allows us to drop remaining uses of the global `the_repository` variable. Drop them and remove `USE_THE_REPOSITORY_VARIABLE`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 23, 2026 at 16:03 UTC 6fea405bb92100a229c0ee83c98e062e271577cd
1 file changed +23 -23
builtin/fsck.c
+23 -23
@@ -1,4 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
1 #include "builtin.h"
2 #include "gettext.h"
3 #include "hex.h"
@@ -66,14 +65,14 @@ static const char *describe_object(const struct object_id *oid)
65 return fsck_describe_object(&fsck_walk_options, oid);
66 }
67
69 -static const char *printable_type(const struct object_id *oid,
68 +static const char *printable_type(struct repository *repo,
69 + const struct object_id *oid,
70 enum object_type type)
71 {
72 const char *ret;
73
74 if (type == OBJ_NONE)
75 - type = odb_read_object_info(the_repository->objects,
76 - oid, NULL);
75 + type = odb_read_object_info(repo->objects, oid, NULL);
76
77 ret = type_name(type);
78 if (!ret)
@@ -82,17 +81,17 @@ static const char *printable_type(const struct object_id *oid,
81 return ret;
82 }
83
85 -static int objerror(struct object *obj, const char *err)
84 +static int objerror(struct repository *repo, struct object *obj, const char *err)
85 {
86 errors_found |= ERROR_OBJECT;
87 /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
88 fprintf_ln(stderr, _("error in %s %s: %s"),
90 - printable_type(&obj->oid, obj->type),
89 + printable_type(repo, &obj->oid, obj->type),
90 describe_object(&obj->oid), err);
91 return -1;
92 }
93
95 -static int fsck_objects_error_func(struct fsck_options *o UNUSED,
94 +static int fsck_objects_error_func(struct fsck_options *o,
95 void *fsck_report,
96 enum fsck_msg_type msg_type,
97 enum fsck_msg_id msg_id UNUSED,
@@ -106,13 +105,13 @@ static int fsck_objects_error_func(struct fsck_options *o UNUSED,
105 case FSCK_WARN:
106 /* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
107 fprintf_ln(stderr, _("warning in %s %s: %s"),
109 - printable_type(oid, object_type),
108 + printable_type(o->repo, oid, object_type),
109 describe_object(oid), message);
110 return 0;
111 case FSCK_ERROR:
112 /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
113 fprintf_ln(stderr, _("error in %s %s: %s"),
115 - printable_type(oid, object_type),
114 + printable_type(o->repo, oid, object_type),
115 describe_object(oid), message);
116 return 1;
117 default:
@@ -136,7 +135,7 @@ static int mark_object(struct object *obj, enum object_type type,
135 if (!obj) {
136 /* ... these references to parent->fld are safe here */
137 printf_ln(_("broken link from %7s %s"),
139 - printable_type(&parent->oid, parent->type),
138 + printable_type(options->repo, &parent->oid, parent->type),
139 describe_object(&parent->oid));
140 printf_ln(_("broken link from %7s %s"),
141 (type == OBJ_ANY ? _("unknown") : type_name(type)),
@@ -147,7 +146,7 @@ static int mark_object(struct object *obj, enum object_type type,
146
147 if (type != OBJ_ANY && obj->type != type)
148 /* ... and the reference to parent is safe here */
150 - objerror(parent, _("wrong object type in link"));
149 + objerror(options->repo, parent, _("wrong object type in link"));
150
151 if (obj->flags & REACHABLE)
152 return 0;
@@ -166,9 +165,9 @@ static int mark_object(struct object *obj, enum object_type type,
165 HAS_OBJECT_RECHECK_PACKED)) {
166 printf_ln(_("broken link from %7s %s\n"
167 " to %7s %s"),
169 - printable_type(&parent->oid, parent->type),
168 + printable_type(options->repo, &parent->oid, parent->type),
169 describe_object(&parent->oid),
171 - printable_type(&obj->oid, obj->type),
170 + printable_type(options->repo, &obj->oid, obj->type),
171 describe_object(&obj->oid));
172 errors_found |= ERROR_REACHABLE;
173 }
@@ -269,7 +268,7 @@ static void check_reachable_object(struct repository *repo, struct object *obj)
268 if (has_object_pack(repo, &obj->oid))
269 return; /* it is in pack - forget about it */
270 printf_ln(_("missing %s %s"),
272 - printable_type(&obj->oid, obj->type),
271 + printable_type(repo, &obj->oid, obj->type),
272 describe_object(&obj->oid));
273 errors_found |= ERROR_REACHABLE;
274 return;
@@ -296,7 +295,7 @@ static void check_unreachable_object(struct repository *repo, struct object *obj
295 */
296 if (show_unreachable) {
297 printf_ln(_("unreachable %s %s"),
299 - printable_type(&obj->oid, obj->type),
298 + printable_type(repo, &obj->oid, obj->type),
299 describe_object(&obj->oid));
300 return;
301 }
@@ -316,7 +315,7 @@ static void check_unreachable_object(struct repository *repo, struct object *obj
315 if (!(obj->flags & USED)) {
316 if (show_dangling)
317 printf_ln(_("dangling %s %s"),
319 - printable_type(&obj->oid, obj->type),
318 + printable_type(repo, &obj->oid, obj->type),
319 describe_object(&obj->oid));
320 if (write_lost_and_found) {
321 char *filename = repo_git_path(repo, "lost-found/%s/%s",
@@ -402,7 +401,8 @@ static void check_connectivity(struct repository *repo)
401 }
402 }
403
405 -static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
404 +static int fsck_obj(struct repository *repo,
405 + struct object *obj, void *buffer, unsigned long size)
406 {
407 int err;
408
@@ -412,11 +412,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
412
413 if (verbose)
414 fprintf_ln(stderr, _("Checking %s %s"),
415 - printable_type(&obj->oid, obj->type),
415 + printable_type(repo, &obj->oid, obj->type),
416 describe_object(&obj->oid));
417
418 if (fsck_walk(obj, NULL, &fsck_obj_options))
419 - objerror(obj, _("broken links"));
419 + objerror(repo, obj, _("broken links"));
420 err = fsck_object(obj, buffer, size, &fsck_obj_options);
421 if (err)
422 goto out;
@@ -434,7 +434,7 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
434
435 if (show_tags && tag->tagged) {
436 printf_ln(_("tagged %s %s (%s) in %s"),
437 - printable_type(&tag->tagged->oid, tag->tagged->type),
437 + printable_type(repo, &tag->tagged->oid, tag->tagged->type),
438 describe_object(&tag->tagged->oid),
439 tag->tag,
440 describe_object(&tag->object.oid));
@@ -465,7 +465,7 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
465 }
466 obj->flags &= ~(REACHABLE | SEEN);
467 obj->flags |= HAS_OBJ;
468 - return fsck_obj(obj, buffer, size);
468 + return fsck_obj(repo, obj, buffer, size);
469 }
470
471 static int default_refs;
@@ -765,7 +765,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
765
766 obj->flags &= ~(REACHABLE | SEEN);
767 obj->flags |= HAS_OBJ;
768 - if (fsck_obj(obj, contents, size))
768 + if (fsck_obj(data->repo, obj, contents, size))
769 errors_found |= ERROR_OBJECT;
770
771 if (!eaten)
@@ -830,7 +830,7 @@ static int fsck_cache_tree(struct repository *repo, struct cache_tree *it, const
830 fsck_put_object_name(&fsck_walk_options, &it->oid, ":");
831 mark_object_reachable(obj);
832 if (obj->type != OBJ_TREE)
833 - err |= objerror(obj, _("non-tree in cache-tree"));
833 + err |= objerror(repo, obj, _("non-tree in cache-tree"));
834 }
835 for (i = 0; i < it->subtree_nr; i++)
836 err |= fsck_cache_tree(repo, it->down[i]->cache_tree, index_path);