packfile: allow has_packed_and_bad to handle arbitrary repositories

has_packed_and_bad is not widely used, so just migrate it all at once. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Oct 16, 2018 at 16:35 UTC 33b94066f27199071abaa4067d29a98bbbbdae11
3 files changed +5 -4
packfile.c
+3 -2
@@ -1131,12 +1131,13 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
1131 p->num_bad_objects++;
1132 }
1133
1134 -const struct packed_git *has_packed_and_bad(const unsigned char *sha1)
1134 +const struct packed_git *has_packed_and_bad(struct repository *r,
1135 + const unsigned char *sha1)
1136 {
1137 struct packed_git *p;
1138 unsigned i;
1139
1139 - for (p = the_repository->objects->packed_git; p; p = p->next)
1140 + for (p = r->objects->packed_git; p; p = p->next)
1141 for (i = 0; i < p->num_bad_objects; i++)
1142 if (hasheq(sha1,
1143 p->bad_object_sha1 + the_hash_algo->rawsz * i))
packfile.h
+1 -1
@@ -146,7 +146,7 @@ extern int packed_object_info(struct repository *r,
146 off_t offset, struct object_info *);
147
148 extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
149 -extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
149 +extern const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1);
150
151 /*
152 * Iff a pack file in the given repository contains the object named by sha1,
sha1-file.c
+1 -1
@@ -1432,7 +1432,7 @@ void *read_object_file_extended(const struct object_id *oid,
1432 die(_("loose object %s (stored in %s) is corrupt"),
1433 oid_to_hex(repl), path);
1434
1435 - if ((p = has_packed_and_bad(repl->hash)) != NULL)
1435 + if ((p = has_packed_and_bad(the_repository, repl->hash)) != NULL)
1436 die(_("packed object %s (stored in %s) is corrupt"),
1437 oid_to_hex(repl), p->pack_name);
1438