@matheusbsbs / matheus-bagliano / commits / ee5743ce19
Fork 0

compute object CRC32 with index-pack

Same as previous patch but for index-pack. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Apr 9, 2007 at 01:06 UTC ee5743ce191d4f39f976e76fe4c12bf8fc67a590
1 file changed +13 -3
index-pack.c
+13 -3
@@ -15,6 +15,7 @@ struct object_entry
15 off_t offset;
16 unsigned long size;
17 unsigned int hdr_size;
18 + uint32_t crc32;
19 enum object_type type;
20 enum object_type real_type;
21 unsigned char sha1[20];
@@ -86,6 +87,7 @@ static unsigned char input_buffer[4096];
87 static unsigned int input_offset, input_len;
88 static off_t consumed_bytes;
89 static SHA_CTX input_ctx;
90 +static uint32_t input_crc32;
91 static int input_fd, output_fd, pack_fd;
92
93 /* Discard current buffer used content. */
@@ -128,6 +130,7 @@ static void use(int bytes)
130 {
131 if (bytes > input_len)
132 die("used more bytes than were available");
133 + input_crc32 = crc32(input_crc32, input_buffer + input_offset, bytes);
134 input_len -= bytes;
135 input_offset += bytes;
136
@@ -224,8 +227,10 @@ static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_
227 unsigned long size;
228 off_t base_offset;
229 unsigned shift;
230 + void *data;
231
232 obj->offset = consumed_bytes;
233 + input_crc32 = crc32(0, Z_NULL, 0);
234
235 p = fill(1);
236 c = *p;
@@ -276,7 +281,9 @@ static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_
281 }
282 obj->hdr_size = consumed_bytes - obj->offset;
283
279 - return unpack_entry_data(obj->offset, obj->size);
284 + data = unpack_entry_data(obj->offset, obj->size);
285 + obj->crc32 = input_crc32;
286 + return data;
287 }
288
289 static void *get_data_from_pack(struct object_entry *obj)
@@ -521,7 +528,7 @@ static void parse_pack_objects(unsigned char *sha1)
528 fputc('\n', stderr);
529 }
530
524 -static int write_compressed(int fd, void *in, unsigned int size)
531 +static int write_compressed(int fd, void *in, unsigned int size, uint32_t *obj_crc)
532 {
533 z_stream stream;
534 unsigned long maxsize;
@@ -542,6 +549,7 @@ static int write_compressed(int fd, void *in, unsigned int size)
549
550 size = stream.total_out;
551 write_or_die(fd, out, size);
552 + *obj_crc = crc32(*obj_crc, out, size);
553 free(out);
554 return size;
555 }
@@ -562,8 +570,10 @@ static void append_obj_to_pack(const unsigned char *sha1, void *buf,
570 }
571 header[n++] = c;
572 write_or_die(output_fd, header, n);
573 + obj[0].crc32 = crc32(0, Z_NULL, 0);
574 + obj[0].crc32 = crc32(obj[0].crc32, header, n);
575 obj[1].offset = obj[0].offset + n;
566 - obj[1].offset += write_compressed(output_fd, buf, size);
576 + obj[1].offset += write_compressed(output_fd, buf, size, &obj[0].crc32);
577 hashcpy(obj->sha1, sha1);
578 }
579