From: "Hervé Cauwelier" <herve@itaapy.com>
To: git@vger.kernel.org
Subject: [PATCH 2/6] Read the base offset or name of delta objects
Date: Wed, 14 Oct 2009 12:37:45 +0200 [thread overview]
Message-ID: <1255516669-26745-2-git-send-email-herve@itaapy.com> (raw)
In-Reply-To: <1255516669-26745-1-git-send-email-herve@itaapy.com>
Signed-off-by: Hervé Cauwelier <herve@itaapy.com>
---
src/cc-compat.h | 3 +++
src/odb.c | 28 ++++++++++++++++++++++++++--
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/src/cc-compat.h b/src/cc-compat.h
index 8997caa..8dd6774 100644
--- a/src/cc-compat.h
+++ b/src/cc-compat.h
@@ -30,6 +30,9 @@
# define GIT_TYPEOF(x)
#endif
+#define bitsizeof(x) (CHAR_BIT * sizeof(x))
+#define MSB(x, bits) ((x) & GIT_TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))
+
/*
* Does our compiler/platform support the C99 <inttypes.h> and
* <stdint.h> header files. (C99 requires that <inttypes.h>
diff --git a/src/odb.c b/src/odb.c
index 2319998..2b4b016 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -97,8 +97,10 @@ struct git_odb {
};
typedef struct { /* object header data */
- git_otype type; /* object type */
- size_t size; /* object size */
+ git_otype type; /* object type */
+ size_t size; /* object size */
+ off_t base_offset; /* delta base offset (GIT_OBJ_OFS_DELTA) */
+ git_oid base_name; /* delta base name (GIT_OBJ_REF_DELTA) */
} obj_hdr;
static struct {
@@ -238,6 +240,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, gitfo_buf *obj)
unsigned char c;
unsigned char *data = obj->data;
size_t shift, size, used = 0;
+ off_t base_offset;
if (obj->len == 0)
return 0;
@@ -258,6 +261,27 @@ static size_t get_binary_object_header(obj_hdr *hdr, gitfo_buf *obj)
}
hdr->size = size;
+ hdr->base_offset = 0;
+ hdr->base_name.id[0] = '\0';
+
+ if (hdr->type == GIT_OBJ_OFS_DELTA) {
+ c = data[used++];
+ base_offset = c & 127;
+ while (c & 128) {
+ base_offset++;
+ if (!base_offset || MSB(base_offset, 7))
+ return 0; /* overflow */
+ c = data[used++];
+ base_offset = (base_offset << 7) + (c & 127);
+ }
+ assert(base_offset > 0);
+ hdr->base_offset = base_offset;
+ }
+ else if (hdr->type == GIT_OBJ_REF_DELTA) {
+ git_oid_mkraw(&hdr->base_name, data + used);
+ used += 20;
+ }
+
return used;
}
--
1.6.5
next prev parent reply other threads:[~2009-10-14 10:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-14 10:37 [PATCH 1/6] Open the pack file and keep a map on it Hervé Cauwelier
2009-10-14 10:37 ` Hervé Cauwelier [this message]
2009-10-14 10:37 ` [PATCH 3/6] Allow zlib to read a pack buffer longer than the actual data Hervé Cauwelier
2009-10-14 10:37 ` [PATCH 4/6] Inflate an object from a pack file Hervé Cauwelier
2009-10-14 10:37 ` [PATCH 5/6] This assertion is valid for both loose and packed objects Hervé Cauwelier
2009-10-14 10:37 ` [PATCH 6/6] Read an object from a pack file Hervé Cauwelier
2009-10-14 12:48 ` [PATCH 1/6] Open the pack file and keep a map on it Sverre Rabbelier
2009-10-14 15:29 ` Hervé Cauwelier
2009-10-14 15:30 ` Sverre Rabbelier
-- strict thread matches above, loose matches on Subject: below --
2009-10-03 18:09 Patches for libgit2 Hervé Cauwelier
2009-10-03 18:09 ` [PATCH 1/6] Open the pack file and keep a map on it Hervé Cauwelier
2009-10-03 18:09 ` [PATCH 2/6] Read the base offset or name of delta objects Hervé Cauwelier
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=1255516669-26745-2-git-send-email-herve@itaapy.com \
--to=herve@itaapy.com \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.