aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2006-12-23 02:34:13 -0500
committerJunio C Hamano <junkio@cox.net>2006-12-29 11:36:44 -0800
commit079afb18fed078af01bd9ab02e2ebbe5d31893b1 (patch)
tree79fcc6e294e90e3a49f8bad533ee40dcdf2e627d /sha1_file.c
parent03e79c88aa34ce188eb4fb7509e6d127c79c507d (diff)
downloadgit-079afb18fed078af01bd9ab02e2ebbe5d31893b1.tar.gz
git-079afb18fed078af01bd9ab02e2ebbe5d31893b1.tar.xz
Loop over pack_windows when inflating/accessing data.
When multiple mmaps start getting used for all pack file access it is not possible to get all data associated with a specific object in one contiguous memory region. This limitation prevents simply passing a single address and length to SHA1_Update or to inflate. Instead we need to loop until we have processed all data of interest. As we loop over the data we are always interested in reusing the same window 'cursor', as the prior window will no longer be of any use to us. This allows the use_pack() call to automatically decrement the use count of the prior window before setting up access for us to the next window. Within each loop we need to make use of the available length output parameter of use_pack() to tell us how many bytes are available in the current memory region, as we cannot tell otherwise. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 4d80527ba..c30452251 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -962,19 +962,23 @@ static int packed_delta_info(struct packed_git *p,
if (sizep) {
const unsigned char *data;
- unsigned char delta_head[20];
+ unsigned char delta_head[20], *in;
unsigned long result_size;
z_stream stream;
int st;
memset(&stream, 0, sizeof(stream));
-
- stream.next_in = use_pack(p, w_curs, offset, &stream.avail_in);
stream.next_out = delta_head;
stream.avail_out = sizeof(delta_head);
inflateInit(&stream);
- st = inflate(&stream, Z_FINISH);
+ do {
+ in = use_pack(p, w_curs, offset, &stream.avail_in);
+ stream.next_in = in;
+ st = inflate(&stream, Z_FINISH);
+ offset += stream.next_in - in;
+ } while ((st == Z_OK || st == Z_BUF_ERROR)
+ && stream.total_out < sizeof(delta_head));
inflateEnd(&stream);
if ((st != Z_STREAM_END) &&
stream.total_out != sizeof(delta_head))
@@ -1103,17 +1107,21 @@ static void *unpack_compressed_entry(struct packed_git *p,
{
int st;
z_stream stream;
- unsigned char *buffer;
+ unsigned char *buffer, *in;
buffer = xmalloc(size + 1);
buffer[size] = 0;
memset(&stream, 0, sizeof(stream));
- stream.next_in = use_pack(p, w_curs, offset, &stream.avail_in);
stream.next_out = buffer;
stream.avail_out = size;
inflateInit(&stream);
- st = inflate(&stream, Z_FINISH);
+ do {
+ in = use_pack(p, w_curs, offset, &stream.avail_in);
+ stream.next_in = in;
+ st = inflate(&stream, Z_FINISH);
+ offset += stream.next_in - in;
+ } while (st == Z_OK || st == Z_BUF_ERROR);
inflateEnd(&stream);
if ((st != Z_STREAM_END) || stream.total_out != size) {
free(buffer);