Skip to content

Commit 7ebf19c

Browse files
pks-tgitster
authored andcommitted
pack-check: stop depending on the_repository
There are multiple sites in "pack-check.c" where we use the global `the_repository` variable, either explicitly or implicitly by using `the_hash_algo`. In all of those cases we already have a repository available in the calling context though. Refactor the code to instead use the caller-provided repository and remove the `USE_THE_REPOSITORY_VARIABLE` define. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7835ee7 commit 7ebf19c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pack-check.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
@@ -44,7 +43,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
4443
} while (len);
4544

4645
index_crc = p->index_data;
47-
index_crc += 2 + 256 + (size_t)p->num_objects * (the_hash_algo->rawsz/4) + nr;
46+
index_crc += 2 + 256 + (size_t)p->num_objects * (p->repo->hash_algo->rawsz/4) + nr;
4847

4948
return data_crc != ntohl(*index_crc);
5049
}
@@ -81,11 +80,11 @@ static int verify_packfile(struct repository *r,
8180
} while (offset < pack_sig_ofs);
8281
git_hash_final(hash, &ctx);
8382
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
84-
if (!hasheq(hash, pack_sig, the_repository->hash_algo))
83+
if (!hasheq(hash, pack_sig, r->hash_algo))
8584
err = error("%s pack checksum mismatch",
8685
p->pack_name);
8786
if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig,
88-
the_repository->hash_algo))
87+
r->hash_algo))
8988
err = error("%s pack checksum does not match its index",
9089
p->pack_name);
9190
unuse_pack(w_curs);
@@ -132,7 +131,7 @@ static int verify_packfile(struct repository *r,
132131
unuse_pack(w_curs);
133132

134133
if (type == OBJ_BLOB &&
135-
repo_settings_get_big_file_threshold(the_repository) <= size) {
134+
repo_settings_get_big_file_threshold(r) <= size) {
136135
/*
137136
* Let stream_object_signature() check it with
138137
* the streaming interface; no point slurping
@@ -181,7 +180,7 @@ int verify_pack_index(struct packed_git *p)
181180
return error("packfile %s index not opened", p->pack_name);
182181

183182
/* Verify SHA1 sum of the index file */
184-
if (!hashfile_checksum_valid(the_repository->hash_algo, p->index_data, p->index_size))
183+
if (!hashfile_checksum_valid(p->repo->hash_algo, p->index_data, p->index_size))
185184
err = error("Packfile index for %s hash mismatch",
186185
p->pack_name);
187186
return err;

0 commit comments

Comments
 (0)