Skip to content

Commit

Permalink
unpack_delta_entry(): reduce memory footprint.
Browse files Browse the repository at this point in the history
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 <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Mar 19, 2006
1 parent 2b1c0ef commit 67686d9
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 67686d9

Please sign in to comment.