Browse Source

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>
maint
Nicolas Pitre 19 years ago committed by Junio C Hamano
parent
commit
d60fc1c864
  1. 6
      index-pack.c
  2. 6
      pack-check.c
  3. 1
      pack.h
  4. 5
      patch-delta.c
  5. 5
      unpack-objects.c

6
index-pack.c

@ -68,9 +68,9 @@ static void parse_pack_header(void)
hdr = (void *)pack_base; hdr = (void *)pack_base;
if (hdr->hdr_signature != htonl(PACK_SIGNATURE)) if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
die("packfile '%s' signature mismatch", pack_name); die("packfile '%s' signature mismatch", pack_name);
if (hdr->hdr_version != htonl(PACK_VERSION)) if (!pack_version_ok(hdr->hdr_version))
die("packfile '%s' version %d different from ours %d", die("packfile '%s' version %d unsupported",
pack_name, ntohl(hdr->hdr_version), PACK_VERSION); pack_name, ntohl(hdr->hdr_version));


nr_objects = ntohl(hdr->hdr_entries); nr_objects = ntohl(hdr->hdr_entries);



6
pack-check.c

@ -16,9 +16,9 @@ static int verify_packfile(struct packed_git *p)
hdr = p->pack_base; hdr = p->pack_base;
if (hdr->hdr_signature != htonl(PACK_SIGNATURE)) if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
return error("Packfile %s signature mismatch", p->pack_name); return error("Packfile %s signature mismatch", p->pack_name);
if (hdr->hdr_version != htonl(PACK_VERSION)) if (!pack_version_ok(hdr->hdr_version))
return error("Packfile version %d different from ours %d", return error("Packfile version %d unsupported",
ntohl(hdr->hdr_version), PACK_VERSION); ntohl(hdr->hdr_version));
nr_objects = ntohl(hdr->hdr_entries); nr_objects = ntohl(hdr->hdr_entries);
if (num_packed_objects(p) != nr_objects) if (num_packed_objects(p) != nr_objects)
return error("Packfile claims to have %d objects, " return error("Packfile claims to have %d objects, "

1
pack.h

@ -21,6 +21,7 @@ enum object_type {
*/ */
#define PACK_SIGNATURE 0x5041434b /* "PACK" */ #define PACK_SIGNATURE 0x5041434b /* "PACK" */
#define PACK_VERSION 2 #define PACK_VERSION 2
#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
struct pack_header { struct pack_header {
unsigned int hdr_signature; unsigned int hdr_signature;
unsigned int hdr_version; unsigned int hdr_version;

5
patch-delta.c

@ -44,16 +44,15 @@ void *patch_delta(void *src_buf, unsigned long src_size,
cmd = *data++; cmd = *data++;
if (cmd & 0x80) { if (cmd & 0x80) {
unsigned long cp_off = 0, cp_size = 0; unsigned long cp_off = 0, cp_size = 0;
const unsigned char *buf;
if (cmd & 0x01) cp_off = *data++; if (cmd & 0x01) cp_off = *data++;
if (cmd & 0x02) cp_off |= (*data++ << 8); if (cmd & 0x02) cp_off |= (*data++ << 8);
if (cmd & 0x04) cp_off |= (*data++ << 16); if (cmd & 0x04) cp_off |= (*data++ << 16);
if (cmd & 0x08) cp_off |= (*data++ << 24); if (cmd & 0x08) cp_off |= (*data++ << 24);
if (cmd & 0x10) cp_size = *data++; if (cmd & 0x10) cp_size = *data++;
if (cmd & 0x20) cp_size |= (*data++ << 8); if (cmd & 0x20) cp_size |= (*data++ << 8);
if (cmd & 0x40) cp_size |= (*data++ << 16);
if (cp_size == 0) cp_size = 0x10000; if (cp_size == 0) cp_size = 0x10000;
buf = (cmd & 0x40) ? dst_buf : src_buf; memcpy(out, src_buf + cp_off, cp_size);
memcpy(out, buf + cp_off, cp_size);
out += cp_size; out += cp_size;
} else { } else {
memcpy(out, data, cmd); memcpy(out, data, cmd);

5
unpack-objects.c

@ -246,13 +246,12 @@ static void unpack_all(void)
{ {
int i; int i;
struct pack_header *hdr = fill(sizeof(struct pack_header)); struct pack_header *hdr = fill(sizeof(struct pack_header));
unsigned version = ntohl(hdr->hdr_version);
unsigned nr_objects = ntohl(hdr->hdr_entries); unsigned nr_objects = ntohl(hdr->hdr_entries);


if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE) if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE)
die("bad pack file"); die("bad pack file");
if (version != PACK_VERSION) if (!pack_version_ok(hdr->hdr_version))
die("unable to handle pack file version %d", version); die("unknown pack file version %d", ntohl(hdr->hdr_version));
fprintf(stderr, "Unpacking %d objects\n", nr_objects); fprintf(stderr, "Unpacking %d objects\n", nr_objects);


use(sizeof(struct pack_header)); use(sizeof(struct pack_header));

Loading…
Cancel
Save