From: Nicolas Pitre <nico@cam.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org, Nicolas Pitre <nico@cam.org>
Subject: [PATCH 05/10] compute object CRC32 with index-pack
Date: Mon, 09 Apr 2007 01:06:32 -0400 [thread overview]
Message-ID: <11760952002687-git-send-email-nico@cam.org> (raw)
In-Reply-To: <11760951993409-git-send-email-nico@cam.org>
Same as previous patch but for index-pack.
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
index-pack.c | 16 +++++++++++++---
1 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/index-pack.c b/index-pack.c
index 66fb0bc..d33f723 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -15,6 +15,7 @@ struct object_entry
off_t offset;
unsigned long size;
unsigned int hdr_size;
+ uint32_t crc32;
enum object_type type;
enum object_type real_type;
unsigned char sha1[20];
@@ -86,6 +87,7 @@ static unsigned char input_buffer[4096];
static unsigned int input_offset, input_len;
static off_t consumed_bytes;
static SHA_CTX input_ctx;
+static uint32_t input_crc32;
static int input_fd, output_fd, pack_fd;
/* Discard current buffer used content. */
@@ -128,6 +130,7 @@ static void use(int bytes)
{
if (bytes > input_len)
die("used more bytes than were available");
+ input_crc32 = crc32(input_crc32, input_buffer + input_offset, bytes);
input_len -= bytes;
input_offset += bytes;
@@ -224,8 +227,10 @@ static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_
unsigned long size;
off_t base_offset;
unsigned shift;
+ void *data;
obj->offset = consumed_bytes;
+ input_crc32 = crc32(0, Z_NULL, 0);
p = fill(1);
c = *p;
@@ -276,7 +281,9 @@ static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_
}
obj->hdr_size = consumed_bytes - obj->offset;
- return unpack_entry_data(obj->offset, obj->size);
+ data = unpack_entry_data(obj->offset, obj->size);
+ obj->crc32 = input_crc32;
+ return data;
}
static void *get_data_from_pack(struct object_entry *obj)
@@ -521,7 +528,7 @@ static void parse_pack_objects(unsigned char *sha1)
fputc('\n', stderr);
}
-static int write_compressed(int fd, void *in, unsigned int size)
+static int write_compressed(int fd, void *in, unsigned int size, uint32_t *obj_crc)
{
z_stream stream;
unsigned long maxsize;
@@ -542,6 +549,7 @@ static int write_compressed(int fd, void *in, unsigned int size)
size = stream.total_out;
write_or_die(fd, out, size);
+ *obj_crc = crc32(*obj_crc, out, size);
free(out);
return size;
}
@@ -562,8 +570,10 @@ static void append_obj_to_pack(const unsigned char *sha1, void *buf,
}
header[n++] = c;
write_or_die(output_fd, header, n);
+ obj[0].crc32 = crc32(0, Z_NULL, 0);
+ obj[0].crc32 = crc32(obj[0].crc32, header, n);
obj[1].offset = obj[0].offset + n;
- obj[1].offset += write_compressed(output_fd, buf, size);
+ obj[1].offset += write_compressed(output_fd, buf, size, &obj[0].crc32);
hashcpy(obj->sha1, sha1);
}
--
1.5.1.696.g6d352-dirty
next prev parent reply other threads:[~2007-04-09 5:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-09 5:06 support for large packs and 64-bit offsets Nicolas Pitre
2007-04-09 5:06 ` [PATCH 01/10] get rid of num_packed_objects() Nicolas Pitre
2007-04-09 5:06 ` [PATCH 02/10] make overflow test on delta base offset work regardless of variable size Nicolas Pitre
2007-04-09 5:06 ` [PATCH 03/10] add overflow tests on pack offset variables Nicolas Pitre
2007-04-09 5:06 ` [PATCH 04/10] compute a CRC32 for each object as stored in a pack Nicolas Pitre
2007-04-09 5:06 ` Nicolas Pitre [this message]
2007-04-09 5:06 ` [PATCH 06/10] pack-objects: learn about pack index version 2 Nicolas Pitre
2007-04-09 5:06 ` [PATCH 07/10] index-pack: " Nicolas Pitre
2007-04-09 5:06 ` [PATCH 08/10] sha1_file.c: learn about " Nicolas Pitre
2007-04-09 5:06 ` [PATCH 09/10] show-index.c: learn about index v2 Nicolas Pitre
2007-04-09 5:06 ` [PATCH 10/10] pack-redundant.c: " Nicolas Pitre
2007-04-09 5:32 ` [PATCH 06/10] pack-objects: learn about pack index version 2 Junio C Hamano
2007-04-09 14:54 ` Nicolas Pitre
2007-04-09 17:19 ` support for large packs and 64-bit offsets Shawn O. Pearce
2007-04-09 17:32 ` Nicolas Pitre
2007-04-09 17:43 ` Shawn O. Pearce
2007-04-09 19:49 ` Junio C Hamano
2007-04-09 19:53 ` Shawn O. Pearce
2007-04-09 20:02 ` Nicolas Pitre
2007-04-09 20:18 ` Junio C Hamano
2007-04-09 18:02 ` Linus Torvalds
2007-04-09 18:26 ` Nicolas Pitre
2007-04-09 18:34 ` Shawn O. Pearce
2007-04-09 19:46 ` Nicolas Pitre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11760952002687-git-send-email-nico@cam.org \
--to=nico@cam.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.