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

remove delta-against-self bit

After experimenting with code to add the ability to encode a delta against part of the deltified file, it turns out that resulting packs are _bigger_ than when this ability is not used. The raw delta output might be smaller, but it doesn't compress as well using gzip with a negative net saving on average. Said bit would in fact be more useful to allow for encoding the copying of chunks larger than 64KB providing more savings with large files. This will correspond to packs version 3. While the current code still produces packs version 2, it is made future proof so pack versions 2 and 3 are accepted. Any pack version 2 are compatible with version 3 since the redefined bit was never used before. When enough time has passed, code to use that bit to produce version 3 packs could be added. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Feb 9, 2006 at 17:50 UTC d60fc1c8649f80c006b9f493c542461e81608d4b
5 files changed +11 -12
index-pack.c
+3 -3
@@ -68,9 +68,9 @@ static void parse_pack_header(void)
68 hdr = (void *)pack_base;
69 if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
70 die("packfile '%s' signature mismatch", pack_name);
71 - if (hdr->hdr_version != htonl(PACK_VERSION))
72 - die("packfile '%s' version %d different from ours %d",
73 - pack_name, ntohl(hdr->hdr_version), PACK_VERSION);
71 + if (!pack_version_ok(hdr->hdr_version))
72 + die("packfile '%s' version %d unsupported",
73 + pack_name, ntohl(hdr->hdr_version));
74
75 nr_objects = ntohl(hdr->hdr_entries);
76
pack-check.c
+3 -3
@@ -16,9 +16,9 @@ static int verify_packfile(struct packed_git *p)
16 hdr = p->pack_base;
17 if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
18 return error("Packfile %s signature mismatch", p->pack_name);
19 - if (hdr->hdr_version != htonl(PACK_VERSION))
20 - return error("Packfile version %d different from ours %d",
21 - ntohl(hdr->hdr_version), PACK_VERSION);
19 + if (!pack_version_ok(hdr->hdr_version))
20 + return error("Packfile version %d unsupported",
21 + ntohl(hdr->hdr_version));
22 nr_objects = ntohl(hdr->hdr_entries);
23 if (num_packed_objects(p) != nr_objects)
24 return error("Packfile claims to have %d objects, "
pack.h
+1
@@ -21,6 +21,7 @@ enum object_type {
21 */
22 #define PACK_SIGNATURE 0x5041434b /* "PACK" */
23 #define PACK_VERSION 2
24 +#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
25 struct pack_header {
26 unsigned int hdr_signature;
27 unsigned int hdr_version;
patch-delta.c
+2 -3
@@ -44,16 +44,15 @@ void *patch_delta(void *src_buf, unsigned long src_size,
44 cmd = *data++;
45 if (cmd & 0x80) {
46 unsigned long cp_off = 0, cp_size = 0;
47 - const unsigned char *buf;
47 if (cmd & 0x01) cp_off = *data++;
48 if (cmd & 0x02) cp_off |= (*data++ << 8);
49 if (cmd & 0x04) cp_off |= (*data++ << 16);
50 if (cmd & 0x08) cp_off |= (*data++ << 24);
51 if (cmd & 0x10) cp_size = *data++;
52 if (cmd & 0x20) cp_size |= (*data++ << 8);
53 + if (cmd & 0x40) cp_size |= (*data++ << 16);
54 if (cp_size == 0) cp_size = 0x10000;
55 - buf = (cmd & 0x40) ? dst_buf : src_buf;
56 - memcpy(out, buf + cp_off, cp_size);
55 + memcpy(out, src_buf + cp_off, cp_size);
56 out += cp_size;
57 } else {
58 memcpy(out, data, cmd);
unpack-objects.c
+2 -3
@@ -246,13 +246,12 @@ static void unpack_all(void)
246 {
247 int i;
248 struct pack_header *hdr = fill(sizeof(struct pack_header));
249 - unsigned version = ntohl(hdr->hdr_version);
249 unsigned nr_objects = ntohl(hdr->hdr_entries);
250
251 if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE)
252 die("bad pack file");
254 - if (version != PACK_VERSION)
255 - die("unable to handle pack file version %d", version);
253 + if (!pack_version_ok(hdr->hdr_version))
254 + die("unknown pack file version %d", ntohl(hdr->hdr_version));
255 fprintf(stderr, "Unpacking %d objects\n", nr_objects);
256
257 use(sizeof(struct pack_header));