diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2007-01-18 11:26:06 -0500 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2007-01-18 11:26:06 -0500 |
commit | 566f44252b00003d1f4e7baaaf709d74bf73770f (patch) | |
tree | a3502cb54ded9a27954cb3d895a86770ab56994d | |
parent | Correct packfile edge output in fast-import. (diff) | |
download | tgif-566f44252b00003d1f4e7baaaf709d74bf73770f.tar.xz |
Always use struct pack_header for pack header in fast-import.
Previously we were using 'unsigned int' to update the hdr_entries
field of the pack header after the file had been completed and
was being hashed. This may not be 32 bits on all platforms.
Instead we want to always uint32_t.
I'm actually cheating here by just using the pack_header like the
rest of Git and letting the struct definition declare the correct
type. Right now that field is still 'unsigned int' (wrong) but a
pending change submitted by Simon 'corecode' Schubert changes it
to uint32_t. After that change is merged in fast-import will do
the right thing all of the time.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r-- | fast-import.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/fast-import.c b/fast-import.c index a3073c5f03..fb7d912eff 100644 --- a/fast-import.c +++ b/fast-import.c @@ -624,29 +624,31 @@ static void start_packfile(void) static void fixup_header_footer(void) { + static const int buf_sz = 128 * 1024; int pack_fd = pack_data->pack_fd; SHA_CTX c; - char hdr[8]; - unsigned long cnt; + struct pack_header hdr; char *buf; if (lseek(pack_fd, 0, SEEK_SET) != 0) die("Failed seeking to start: %s", strerror(errno)); - - SHA1_Init(&c); - if (read_in_full(pack_fd, hdr, 8) != 8) + if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr)) die("Unable to reread header of %s", pack_data->pack_name); - SHA1_Update(&c, hdr, 8); + if (lseek(pack_fd, 0, SEEK_SET) != 0) + die("Failed seeking to start: %s", strerror(errno)); + hdr.hdr_entries = htonl(object_count); + write_or_die(pack_fd, &hdr, sizeof(hdr)); - cnt = htonl(object_count); - SHA1_Update(&c, &cnt, 4); - write_or_die(pack_fd, &cnt, 4); + SHA1_Init(&c); + SHA1_Update(&c, &hdr, sizeof(hdr)); - buf = xmalloc(128 * 1024); + buf = xmalloc(buf_sz); for (;;) { - size_t n = xread(pack_fd, buf, 128 * 1024); - if (n <= 0) + size_t n = xread(pack_fd, buf, buf_sz); + if (!n) break; + if (n < 0) + die("Failed to checksum %s", pack_data->pack_name); SHA1_Update(&c, buf, n); } free(buf); |