From: Shawn Pearce <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 5/5] Convert unpack_entry_gently and friends to use offsets.
Date: Sat, 26 Aug 2006 04:12:27 -0400 [thread overview]
Message-ID: <20060826081227.GG22343@spearce.org> (raw)
Change unpack_entry_gently and its helper functions to use offsets
rather than addresses and left counts to supply pack position
information. In most cases this makes the code easier to follow,
and it reduces the number of local variables in a few functions.
It also better prepares this code for mapping partial segments of
packs and altering what regions of a pack are mapped while unpacking
an entry.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
sha1_file.c | 33 +++++++++++++++------------------
1 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index e6d47c1..558ec4a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1041,9 +1041,9 @@ static int packed_object_info(struct pac
return 0;
}
-static void *unpack_compressed_entry(unsigned char *data,
- unsigned long size,
- unsigned long left)
+static void *unpack_compressed_entry(struct packed_git *p,
+ unsigned long offset,
+ unsigned long size)
{
int st;
z_stream stream;
@@ -1052,8 +1052,8 @@ static void *unpack_compressed_entry(uns
buffer = xmalloc(size + 1);
buffer[size] = 0;
memset(&stream, 0, sizeof(stream));
- stream.next_in = data;
- stream.avail_in = left;
+ stream.next_in = (unsigned char*)p->pack_base + offset;
+ stream.avail_in = p->pack_size - offset;
stream.next_out = buffer;
stream.avail_out = size;
@@ -1068,21 +1068,22 @@ static void *unpack_compressed_entry(uns
return buffer;
}
-static void *unpack_delta_entry(unsigned char *base_sha1,
+static void *unpack_delta_entry(struct packed_git *p,
+ unsigned long offset,
unsigned long delta_size,
- unsigned long left,
char *type,
- unsigned long *sizep,
- struct packed_git *p)
+ unsigned long *sizep)
{
struct pack_entry base_ent;
void *delta_data, *result, *base;
unsigned long result_size, base_size;
+ unsigned char* base_sha1;
- if (left < 20)
+ if ((offset + 20) >= p->pack_size)
die("truncated pack file");
/* The base entry _must_ be in the same pack */
+ base_sha1 = (unsigned char*)p->pack_base + offset;
if (!find_pack_entry_one(base_sha1, &base_ent, p))
die("failed to find delta-pack base object %s",
sha1_to_hex(base_sha1));
@@ -1091,8 +1092,7 @@ static void *unpack_delta_entry(unsigned
die("failed to read delta-pack base object %s",
sha1_to_hex(base_sha1));
- delta_data = unpack_compressed_entry(base_sha1 + 20,
- delta_size, left - 20);
+ delta_data = unpack_compressed_entry(p, offset + 20, delta_size);
result = patch_delta(base, base_size,
delta_data, delta_size,
&result_size);
@@ -1124,23 +1124,20 @@ void *unpack_entry_gently(struct pack_en
char *type, unsigned long *sizep)
{
struct packed_git *p = entry->p;
- unsigned long offset, size, left;
- unsigned char *pack;
+ unsigned long offset, size;
enum object_type kind;
offset = unpack_object_header(p, entry->offset, &kind, &size);
- pack = (unsigned char *) p->pack_base + offset;
- left = p->pack_size - offset;
switch (kind) {
case OBJ_DELTA:
- return unpack_delta_entry(pack, size, left, type, sizep, p);
+ return unpack_delta_entry(p, offset, size, type, sizep);
case OBJ_COMMIT:
case OBJ_TREE:
case OBJ_BLOB:
case OBJ_TAG:
strcpy(type, type_names[kind]);
*sizep = size;
- return unpack_compressed_entry(pack, size, left);
+ return unpack_compressed_entry(p, offset, size);
default:
return NULL;
}
--
1.4.2.g6580
reply other threads:[~2006-08-26 8:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060826081227.GG22343@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).