summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 69a2d42)
raw | patch | inline | side by side (parent: 69a2d42)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Wed, 29 Jun 2005 05:15:57 +0000 (22:15 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Wed, 29 Jun 2005 05:15:57 +0000 (22:15 -0700) |
This makes it match the new delta encoding, and admittedly makes the
code easier to follow.
This also updates the PACK file version to 2, since this (and the delta
encoding change in the previous commit) are incompatible with the old
format.
code easier to follow.
This also updates the PACK file version to 2, since this (and the delta
encoding change in the previous commit) are incompatible with the old
format.
Makefile | patch | blob | history | |
pack-objects.c | patch | blob | history | |
pack.h | patch | blob | history | |
sha1_file.c | patch | blob | history | |
unpack-objects.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index 1736980d09a46e079eec4435d16d5b891865543e..9384c538cb2400e56b329f50a7380cd559672e91 100644 (file)
--- a/Makefile
+++ b/Makefile
tag.o date.o index.o diff-delta.o patch-delta.o entry.o \
epoch.o refs.o csum-file.o
LIB_FILE=libgit.a
-LIB_H=cache.h object.h blob.h tree.h commit.h tag.h delta.h epoch.h csum-file.h
+LIB_H=cache.h object.h blob.h tree.h commit.h tag.h delta.h epoch.h csum-file.h pack.h
LIB_H += strbuf.h
LIB_OBJS += strbuf.o
diff --git a/pack-objects.c b/pack-objects.c
index feee5600b9c362ad1436db64e3624f646f064fc3..fc969e342a80c99a7455daf32696c828123ad1b9 100644 (file)
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -51,32 +51,19 @@ static void *delta_against(void *buf, unsigned long size, struct object_entry *e
*/
static int encode_header(enum object_type type, unsigned long size, unsigned char *hdr)
{
- int n = 1, i;
+ int n = 1;
unsigned char c;
if (type < OBJ_COMMIT || type > OBJ_DELTA)
die("bad type %d", type);
- /*
- * Shift the size up by 7 bits at a time,
- * until you get bits in the "high four".
- * That will be our beginning. We'll have
- * four size bits in 28..31, then groups
- * of seven in 21..27, 14..20, 7..13 and
- * finally 0..6.
- */
- if (size) {
- n = 5;
- while (!(size & 0xfe000000)) {
- size <<= 7;
- n--;
- }
- }
- c = (type << 4) | (size >> 28);
- for (i = 1; i < n; i++) {
+ c = (type << 4) | (size & 15);
+ size >>= 4;
+ while (size) {
*hdr++ = c | 0x80;
- c = (size >> 21) & 0x7f;
- size <<= 7;
+ c = size & 0x7f;
+ size >>= 7;
+ n++;
}
*hdr = c;
return n;
else
f = sha1create("%s.%s", base_name, "pack");
hdr.hdr_signature = htonl(PACK_SIGNATURE);
- hdr.hdr_version = htonl(1);
+ hdr.hdr_version = htonl(PACK_VERSION);
hdr.hdr_entries = htonl(nr_objects);
sha1write(f, &hdr, sizeof(hdr));
offset = sizeof(hdr);
index 08e120dca664f43f8c12a2ce59cb28a67315500a..83ac3218bd2c3fb0a18770338efa3aee79be082e 100644 (file)
--- a/pack.h
+++ b/pack.h
#ifndef PACK_H
#define PACK_H
+/*
+ * The packed object type is stored in 3 bits.
+ * The type value 0 is a reserved prefix if ever there is more than 7
+ * object types, or any future format extensions.
+ */
enum object_type {
- OBJ_NONE,
- OBJ_COMMIT,
- OBJ_TREE,
- OBJ_BLOB,
- OBJ_TAG,
- OBJ_DELTA,
+ OBJ_EXT = 0,
+ OBJ_COMMIT = 1,
+ OBJ_TREE = 2,
+ OBJ_BLOB = 3,
+ OBJ_TAG = 4,
+ /* 5/6 for future expansion */
+ OBJ_DELTA = 7,
};
/*
* Packed object header
*/
#define PACK_SIGNATURE 0x5041434b /* "PACK" */
+#define PACK_VERSION 2
struct pack_header {
unsigned int hdr_signature;
unsigned int hdr_version;
diff --git a/sha1_file.c b/sha1_file.c
index 25208d2da365a0a670d2ef2adf4dcbcf60ee910a..0bdaa16e7f9d2062e118e8ec64b503aa66977e1f 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
static unsigned long unpack_object_header(struct packed_git *p, unsigned long offset,
enum object_type *type, unsigned long *sizep)
{
+ unsigned shift;
unsigned char *pack, c;
unsigned long size;
@@ -670,12 +671,14 @@ static unsigned long unpack_object_header(struct packed_git *p, unsigned long of
offset++;
*type = (c >> 4) & 7;
size = c & 15;
+ shift = 4;
while (c & 0x80) {
if (offset >= p->pack_size)
die("object offset outside of pack file");
c = *pack++;
offset++;
- size = (size << 7) | (c & 0x7f);
+ size += (c & 0x7f) << shift;
+ shift += 7;
}
*sizep = size;
return offset;
diff --git a/unpack-objects.c b/unpack-objects.c
index 0892d2b920cbf5b3456867aaaabe45f7599edcc0..b9ddcb70e0b653865716e5b78e4035028d651c9e 100644 (file)
--- a/unpack-objects.c
+++ b/unpack-objects.c
static void unpack_one(void)
{
+ unsigned shift;
unsigned char *pack, c;
unsigned long size;
enum object_type type;
use(1);
type = (c >> 4) & 7;
size = (c & 15);
+ shift = 4;
while (c & 0x80) {
pack = fill(1);
c = *pack++;
use(1);
- size = (size << 7) + (c & 0x7f);
+ size += (c & 0x7f) << shift;
+ shift += 7;
}
switch (type) {
case OBJ_COMMIT:
if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE)
die("bad pack file");
- if (version != 1)
+ if (version != PACK_VERSION)
die("unable to handle pack file version %d", version);
fprintf(stderr, "Unpacking %d objects\n", nr_objects);