summaryrefslogtreecommitdiff
path: root/pack-objects.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-06-29 00:49:27 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-29 03:37:42 (GMT)
commit9d5ab9625ddb53a68a99516225d0bcb39ec473d5 (patch)
tree50c53ecc9651c7f697aabac2cd48e3f7d04ce638 /pack-objects.c
parent67e5a5ece41eebc7fec497911690e5a8ca38aea6 (diff)
downloadgit-9d5ab9625ddb53a68a99516225d0bcb39ec473d5.zip
git-9d5ab9625ddb53a68a99516225d0bcb39ec473d5.tar.gz
git-9d5ab9625ddb53a68a99516225d0bcb39ec473d5.tar.bz2
[PATCH] Emit base objects of a delta chain when the delta is output.
Deltas are useless by themselves and when you use them you need to get to their base objects. A base object should inherit recency from the most recent deltified object that is based on it and that is what this patch teaches git-pack-objects. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'pack-objects.c')
-rw-r--r--pack-objects.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/pack-objects.c b/pack-objects.c
index 36f515b..feee560 100644
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -118,6 +118,23 @@ static unsigned long write_object(struct sha1file *f, struct object_entry *entry
return hdrlen + datalen;
}
+static unsigned long write_one(struct sha1file *f,
+ struct object_entry *e,
+ unsigned long offset)
+{
+ if (e->offset)
+ /* offset starts from header size and cannot be zero
+ * if it is written already.
+ */
+ return offset;
+ e->offset = offset;
+ offset += write_object(f, e);
+ /* if we are delitified, write out its base object. */
+ if (e->delta)
+ offset = write_one(f, e->delta, offset);
+ return offset;
+}
+
static void write_pack_file(void)
{
int i;
@@ -135,11 +152,9 @@ static void write_pack_file(void)
hdr.hdr_entries = htonl(nr_objects);
sha1write(f, &hdr, sizeof(hdr));
offset = sizeof(hdr);
- for (i = 0; i < nr_objects; i++) {
- struct object_entry *entry = objects + i;
- entry->offset = offset;
- offset += write_object(f, entry);
- }
+ for (i = 0; i < nr_objects; i++)
+ offset = write_one(f, objects + i, offset);
+
sha1close(f, pack_file_sha1, 1);
mb = offset >> 20;
offset &= 0xfffff;