diff options
-rw-r--r-- | index-pack.c | 6 | ||||
-rw-r--r-- | pack-check.c | 6 | ||||
-rw-r--r-- | pack.h | 1 | ||||
-rw-r--r-- | patch-delta.c | 5 | ||||
-rw-r--r-- | unpack-objects.c | 5 |
5 files changed, 11 insertions, 12 deletions
diff --git a/index-pack.c b/index-pack.c index 541d7bc1c..babe34b2d 100644 --- a/index-pack.c +++ b/index-pack.c @@ -68,9 +68,9 @@ static void parse_pack_header(void) hdr = (void *)pack_base; if (hdr->hdr_signature != htonl(PACK_SIGNATURE)) die("packfile '%s' signature mismatch", pack_name); - if (hdr->hdr_version != htonl(PACK_VERSION)) - die("packfile '%s' version %d different from ours %d", - pack_name, ntohl(hdr->hdr_version), PACK_VERSION); + if (!pack_version_ok(hdr->hdr_version)) + die("packfile '%s' version %d unsupported", + pack_name, ntohl(hdr->hdr_version)); nr_objects = ntohl(hdr->hdr_entries); diff --git a/pack-check.c b/pack-check.c index 511f29424..67a7ecdf1 100644 --- a/pack-check.c +++ b/pack-check.c @@ -16,9 +16,9 @@ static int verify_packfile(struct packed_git *p) hdr = p->pack_base; if (hdr->hdr_signature != htonl(PACK_SIGNATURE)) return error("Packfile %s signature mismatch", p->pack_name); - if (hdr->hdr_version != htonl(PACK_VERSION)) - return error("Packfile version %d different from ours %d", - ntohl(hdr->hdr_version), PACK_VERSION); + if (!pack_version_ok(hdr->hdr_version)) + return error("Packfile version %d unsupported", + ntohl(hdr->hdr_version)); nr_objects = ntohl(hdr->hdr_entries); if (num_packed_objects(p) != nr_objects) return error("Packfile claims to have %d objects, " @@ -21,6 +21,7 @@ enum object_type { */ #define PACK_SIGNATURE 0x5041434b /* "PACK" */ #define PACK_VERSION 2 +#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3)) struct pack_header { unsigned int hdr_signature; unsigned int hdr_version; diff --git a/patch-delta.c b/patch-delta.c index 98c27beb2..c0e131143 100644 --- a/patch-delta.c +++ b/patch-delta.c @@ -44,16 +44,15 @@ void *patch_delta(void *src_buf, unsigned long src_size, cmd = *data++; if (cmd & 0x80) { unsigned long cp_off = 0, cp_size = 0; - const unsigned char *buf; if (cmd & 0x01) cp_off = *data++; if (cmd & 0x02) cp_off |= (*data++ << 8); if (cmd & 0x04) cp_off |= (*data++ << 16); if (cmd & 0x08) cp_off |= (*data++ << 24); if (cmd & 0x10) cp_size = *data++; if (cmd & 0x20) cp_size |= (*data++ << 8); + if (cmd & 0x40) cp_size |= (*data++ << 16); if (cp_size == 0) cp_size = 0x10000; - buf = (cmd & 0x40) ? dst_buf : src_buf; - memcpy(out, buf + cp_off, cp_size); + memcpy(out, src_buf + cp_off, cp_size); out += cp_size; } else { memcpy(out, data, cmd); diff --git a/unpack-objects.c b/unpack-objects.c index 4b5b5cb3e..815a1b382 100644 --- a/unpack-objects.c +++ b/unpack-objects.c @@ -246,13 +246,12 @@ static void unpack_all(void) { int i; struct pack_header *hdr = fill(sizeof(struct pack_header)); - unsigned version = ntohl(hdr->hdr_version); unsigned nr_objects = ntohl(hdr->hdr_entries); if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE) die("bad pack file"); - if (version != PACK_VERSION) - die("unable to handle pack file version %d", version); + if (!pack_version_ok(hdr->hdr_version)) + die("unknown pack file version %d", ntohl(hdr->hdr_version)); fprintf(stderr, "Unpacking %d objects\n", nr_objects); use(sizeof(struct pack_header)); |