From: Junio C Hamano Date: Sun, 19 Mar 2006 21:43:42 +0000 (-0800) Subject: unpack_delta_entry(): reduce memory footprint. X-Git-Tag: v1.3.0-rc1~17^2~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=67686d95044e56475669ff1306448e41a794a865;p=git.git unpack_delta_entry(): reduce memory footprint. Currently we unpack the delta data from the pack and then unpack the base object to apply that delta data to it. When getting an object that is deeply deltified, we can reduce memory footprint by unpacking the base object first and then unpacking the delta data, because we will need to keep at most one delta data in memory that way. Signed-off-by: Junio C Hamano --- diff --git a/sha1_file.c b/sha1_file.c index a80d849f1..58edec0bb 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -973,6 +973,16 @@ static void *unpack_delta_entry(unsigned char *base_sha1, if (left < 20) die("truncated pack file"); + + /* The base entry _must_ be in the same pack */ + if (!find_pack_entry_one(base_sha1, &base_ent, p)) + die("failed to find delta-pack base object %s", + sha1_to_hex(base_sha1)); + base = unpack_entry_gently(&base_ent, type, &base_size); + if (!base) + die("failed to read delta-pack base object %s", + sha1_to_hex(base_sha1)); + data = base_sha1 + 20; data_size = left - 20; delta_data = xmalloc(delta_size); @@ -990,14 +1000,6 @@ static void *unpack_delta_entry(unsigned char *base_sha1, if ((st != Z_STREAM_END) || stream.total_out != delta_size) die("delta data unpack failed"); - /* The base entry _must_ be in the same pack */ - if (!find_pack_entry_one(base_sha1, &base_ent, p)) - die("failed to find delta-pack base object %s", - sha1_to_hex(base_sha1)); - base = unpack_entry_gently(&base_ent, type, &base_size); - if (!base) - die("failed to read delta-pack base object %s", - sha1_to_hex(base_sha1)); result = patch_delta(base, base_size, delta_data, delta_size, &result_size);