stop verifying pack file checksum in the main process during clone/fetch Both got-fetch-pack and got-index-pack now verify the pack file checksum. This means we can avoid reading the entire pack file in the main process just to verify its checksum and avoid a noticable stall between fetching and indexing on slow machines.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/lib/fetch.c b/lib/fetch.c
index bc53875..4ad71dd 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -345,48 +345,6 @@ done:
return err;
}
-static const struct got_error *
-check_pack_hash(int fd, size_t sz, uint8_t *hcomp)
-{
- SHA1_CTX ctx;
- uint8_t hexpect[SHA1_DIGEST_LENGTH];
- uint8_t buf[32 * 1024];
- ssize_t n, r, nr;
-
- if (sz < sizeof(struct got_packfile_hdr) + SHA1_DIGEST_LENGTH)
- return got_error_msg(GOT_ERR_BAD_PACKFILE, "short packfile");
-
- n = 0;
- SHA1Init(&ctx);
- while (n < sz - 20) {
- nr = sizeof(buf);
- if (sz - n - 20 < sizeof(buf))
- nr = sz - n - 20;
- r = read(fd, buf, nr);
- if (r == -1)
- return got_error_from_errno("read");
- if (r != nr)
- return got_error_msg(GOT_ERR_BAD_PACKFILE,
- "short pack file");
- SHA1Update(&ctx, buf, nr);
- n += r;
- }
- SHA1Final(hcomp, &ctx);
-
- r = read(fd, hexpect, sizeof(hexpect));
- if (r == -1)
- return got_error_from_errno("read");
- if (r != sizeof(hexpect))
- return got_error_msg(GOT_ERR_BAD_PACKFILE,
- "short pack file");
-
- if (memcmp(hcomp, hexpect, SHA1_DIGEST_LENGTH) != 0)
- return got_error_msg(GOT_ERR_BAD_PACKFILE,
- "packfile checksum mismatch");
-
- return NULL;
-}
-
const struct got_error*
got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
struct got_pathlist_head *symrefs, const char *remote_name,
@@ -744,15 +702,6 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
err = got_error_from_errno("lseek");
goto done;
}
-
- err = check_pack_hash(packfd, packfile_size, (*pack_hash)->sha1);
- if (err)
- goto done;
-
- if (lseek(packfd, 0, SEEK_SET) == -1) {
- err = got_error_from_errno("lseek");
- goto done;
- }
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_idxfds) == -1) {
err = got_error_from_errno("socketpair");