Skip to content

Commit 1c5f77b

Browse files
pks-tgitster
authored andcommitted
builtin/fsck: stop using the_repository when checking packed objects
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2b2287c commit 1c5f77b

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

builtin/fsck.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,16 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
447447
}
448448

449449
static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
450-
unsigned long size, void *buffer, int *eaten)
450+
unsigned long size, void *buffer, int *eaten, void *cb_data)
451451
{
452+
struct repository *repo = cb_data;
453+
struct object *obj;
454+
452455
/*
453456
* Note, buffer may be NULL if type is OBJ_BLOB. See
454457
* verify_packfile(), data_valid variable for details.
455458
*/
456-
struct object *obj;
457-
obj = parse_object_buffer(the_repository, oid, type, size, buffer,
458-
eaten);
459+
obj = parse_object_buffer(repo, oid, type, size, buffer, eaten);
459460
if (!obj) {
460461
errors_found |= ERROR_OBJECT;
461462
return error(_("%s: object corrupt or missing"),
@@ -1089,7 +1090,7 @@ int cmd_fsck(int argc,
10891090
repo_for_each_pack(repo, p) {
10901091
/* verify gives error messages itself */
10911092
if (verify_pack(repo,
1092-
p, fsck_obj_buffer,
1093+
p, fsck_obj_buffer, repo,
10931094
progress, count))
10941095
errors_found |= ERROR_PACK;
10951096
count += p->num_objects;

pack-check.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static int verify_packfile(struct repository *r,
5353
struct packed_git *p,
5454
struct pack_window **w_curs,
5555
verify_fn fn,
56+
void *fn_data,
5657
struct progress *progress, uint32_t base_count)
5758

5859
{
@@ -161,7 +162,7 @@ static int verify_packfile(struct repository *r,
161162
oid_to_hex(&oid), p->pack_name);
162163
else if (fn) {
163164
int eaten = 0;
164-
err |= fn(&oid, type, size, data, &eaten);
165+
err |= fn(&oid, type, size, data, &eaten, fn_data);
165166
if (eaten)
166167
data = NULL;
167168
}
@@ -192,7 +193,7 @@ int verify_pack_index(struct packed_git *p)
192193
return err;
193194
}
194195

195-
int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn,
196+
int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn, void *fn_data,
196197
struct progress *progress, uint32_t base_count)
197198
{
198199
int err = 0;
@@ -202,7 +203,7 @@ int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn,
202203
if (!p->index_data)
203204
return -1;
204205

205-
err |= verify_packfile(r, p, &w_curs, fn, progress, base_count);
206+
err |= verify_packfile(r, p, &w_curs, fn, fn_data, progress, base_count);
206207
unuse_pack(&w_curs);
207208

208209
return err;

pack.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ struct pack_idx_entry {
8585

8686
struct progress;
8787
/* Note, the data argument could be NULL if object type is blob */
88-
typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*);
88+
typedef int (*verify_fn)(const struct object_id *oid,
89+
enum object_type type,
90+
unsigned long size,
91+
void *buffer, int *eaten,
92+
void *fn_data);
8993

9094
const char *write_idx_file(struct repository *repo,
9195
const char *index_name,
@@ -95,7 +99,8 @@ const char *write_idx_file(struct repository *repo,
9599
const unsigned char *sha1);
96100
int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
97101
int verify_pack_index(struct packed_git *);
98-
int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t);
102+
int verify_pack(struct repository *, struct packed_git *, verify_fn fn, void *fn_data,
103+
struct progress *, uint32_t);
99104
off_t write_pack_header(struct hashfile *f, uint32_t);
100105
void fixup_pack_header_footer(const struct git_hash_algo *, int,
101106
unsigned char *, const char *, uint32_t,

0 commit comments

Comments
 (0)