8
void *index_base = p->index_base;
9
SHA_CTX ctx;
10
unsigned char sha1[20];
11
- unsigned long pack_size = p->pack_size;
12
- void *pack_base;
13
- struct pack_header *hdr;
11
+ unsigned long offset = 0, pack_sig = p->pack_size - 20;
12
int nr_objects, err, i;
13
16
- /* Header consistency check */
17
- pack_base = use_pack(p, w_curs, 0, NULL);
18
- hdr = (struct pack_header*)pack_base;
19
- if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
20
- return error("Packfile %s signature mismatch", p->pack_name);
21
- if (!pack_version_ok(hdr->hdr_version))
22
- return error("Packfile version %d unsupported",
23
- ntohl(hdr->hdr_version));
24
- nr_objects = ntohl(hdr->hdr_entries);
25
- if (num_packed_objects(p) != nr_objects)
26
- return error("Packfile claims to have %d objects, "
27
- "while idx size expects %d", nr_objects,
28
- num_packed_objects(p));
14
+ /* Note that the pack header checks are actually performed by
15
+ * use_pack when it first opens the pack file. If anything
16
+ * goes wrong during those checks then the call will die out
17
+ * immediately.
18
+ */
19
20
SHA1_Init(&ctx);
31
- SHA1_Update(&ctx, pack_base, pack_size - 20);
21
+ while (offset < pack_sig) {
22
+ unsigned int remaining;
23
+ unsigned char *in = use_pack(p, w_curs, offset, &remaining);
24
+ offset += remaining;
25
+ if (offset > pack_sig)
26
+ remaining -= offset - pack_sig;
27
+ SHA1_Update(&ctx, in, remaining);
28
+ }
29
SHA1_Final(sha1, &ctx);
33
- if (hashcmp(sha1, (unsigned char *)pack_base + pack_size - 20))
30
+ if (hashcmp(sha1, use_pack(p, w_curs, pack_sig, NULL)))
31
return error("Packfile %s SHA1 mismatch with itself",
32
p->pack_name);
33
if (hashcmp(sha1, (unsigned char *)index_base + index_size - 40))
34
return error("Packfile %s SHA1 mismatch with idx",
35
p->pack_name);
36
+ unuse_pack(w_curs);
37
38
/* Make sure everything reachable from idx is valid. Since we
39
* have verified that nr_objects matches between idx and pack,
40
* we do not do scan-streaming check on the pack file.
41
*/
42
+ nr_objects = num_packed_objects(p);
43
for (i = err = 0; i < nr_objects; i++) {
44
unsigned char sha1[20];
45
void *data;
72
73
#define MAX_CHAIN 40
74
76
-static void show_pack_info(struct packed_git *p,
77
- struct pack_window **w_curs)
75
+static void show_pack_info(struct packed_git *p)
76
{
79
- struct pack_header *hdr;
77
int nr_objects, i;
78
unsigned int chain_histogram[MAX_CHAIN];
79
83
- hdr = (struct pack_header*)use_pack(p, w_curs, 0, NULL);
84
- nr_objects = ntohl(hdr->hdr_entries);
80
+ nr_objects = num_packed_objects(p);
81
memset(chain_histogram, 0, sizeof(chain_histogram));
82
83
for (i = 0; i < nr_objects; i++) {
149
if (ret)
150
printf("%s: bad\n", p->pack_name);
151
else {
156
- struct pack_window *w_curs = NULL;
157
- show_pack_info(p, &w_curs);
158
- unuse_pack(&w_curs);
152
+ show_pack_info(p);
153
printf("%s: ok\n", p->pack_name);
154
}
155
}