summaryrefslogtreecommitdiff
path: root/builtin-pack-objects.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2006-09-21 00:06:49 -0400
committerJunio C Hamano <junkio@cox.net>2006-09-27 00:11:59 -0700
commiteb32d236df0c16b936b04f0c5402addb61cdb311 (patch)
tree005ee01d7e4813930c25854277d704d2f11bccb3 /builtin-pack-objects.c
parent4a0641b7cf833644b286b56bb57d66b5538e4418 (diff)
downloadgit-eb32d236df0c16b936b04f0c5402addb61cdb311.tar.gz
introduce delta objects with offset to base
This adds a new object, namely OBJ_OFS_DELTA, renames OBJ_DELTA to OBJ_REF_DELTA to better make the distinction between those two delta objects, and adds support for the handling of those new delta objects in sha1_file.c only. The OBJ_OFS_DELTA contains a relative offset from the delta object's position in a pack instead of the 20-byte SHA1 reference to identify the base object. Since the base is likely to be not so far away, the relative offset is more likely to have a smaller encoding on average than an absolute offset. And for those delta objects the base must always be stored first because there is no way to know the distance of later objects when streaming a pack. Hence this relative offset is always meant to be negative. The offset encoding is slightly denser than the one used for object size -- credits to <linux@horizon.com> (whoever this is) for bringing it to my attention. This allows for pack size reduction between 3.2% (Linux-2.6) to over 5% (linux-historic). Runtime pack access should be faster too since delta replay does skip a search in the pack index for each delta in a chain. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-pack-objects.c')
-rw-r--r--builtin-pack-objects.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 96c069a81d..c62734a2a6 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -232,7 +232,7 @@ static int encode_header(enum object_type type, unsigned long size, unsigned cha
int n = 1;
unsigned char c;
- if (type < OBJ_COMMIT || type > OBJ_DELTA)
+ if (type < OBJ_COMMIT || type > OBJ_REF_DELTA)
die("bad type %d", type);
c = (type << 4) | (size & 15);
@@ -297,7 +297,7 @@ static int revalidate_pack_entry(struct object_entry *entry, unsigned char *data
used = unpack_object_header_gently(data, len, &type, &size);
if (!used)
return -1;
- if (type == OBJ_DELTA)
+ if (type == OBJ_REF_DELTA)
used += 20; /* skip base object name */
data += used;
len -= used;
@@ -340,7 +340,7 @@ static unsigned long write_object(struct sha1file *f,
obj_type = entry->type;
if (! entry->in_pack)
to_reuse = 0; /* can't reuse what we don't have */
- else if (obj_type == OBJ_DELTA)
+ else if (obj_type == OBJ_REF_DELTA)
to_reuse = 1; /* check_object() decided it for us */
else if (obj_type != entry->in_pack_type)
to_reuse = 0; /* pack has delta which is unusable */
@@ -380,7 +380,7 @@ static unsigned long write_object(struct sha1file *f,
if (entry->delta) {
buf = delta_against(buf, size, entry);
size = entry->delta_size;
- obj_type = OBJ_DELTA;
+ obj_type = OBJ_REF_DELTA;
}
/*
* The object header is a byte of 'type' followed by zero or
@@ -409,11 +409,11 @@ static unsigned long write_object(struct sha1file *f,
sha1write(f, buf, datalen);
unuse_packed_git(p);
hdrlen = 0; /* not really */
- if (obj_type == OBJ_DELTA)
+ if (obj_type == OBJ_REF_DELTA)
reused_delta++;
reused++;
}
- if (obj_type == OBJ_DELTA)
+ if (obj_type == OBJ_REF_DELTA)
written_delta++;
written++;
return hdrlen + datalen;
@@ -916,7 +916,7 @@ static void check_object(struct object_entry *entry)
* delta.
*/
if (!no_reuse_delta &&
- entry->in_pack_type == OBJ_DELTA &&
+ entry->in_pack_type == OBJ_REF_DELTA &&
(base_entry = locate_object_entry(base)) &&
(!base_entry->preferred_base)) {
@@ -929,7 +929,7 @@ static void check_object(struct object_entry *entry)
/* uncompressed size of the delta data */
entry->size = entry->delta_size = size;
entry->delta = base_entry;
- entry->type = OBJ_DELTA;
+ entry->type = OBJ_REF_DELTA;
entry->delta_sibling = base_entry->delta_child;
base_entry->delta_child = entry;