summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-09-11 13:06:15 +0700
committerNicolas Pitre <nico@fluxnic.net>2013-09-13 21:00:30 -0400
commit7f23009976047a2c603dd7d4c90ec8afb8c052c4 (patch)
tree12d586e8fcbc2cec791ae11e5a039d4cb19c5c4d
parent18c295348761341d23b340a9f42ad7af4cea7598 (diff)
downloadgit-7f23009976047a2c603dd7d4c90ec8afb8c052c4.tar.gz
unpack-objects: decode v4 object header
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
-rw-r--r--builtin/unpack-objects.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 1a3c30e710..a906a984f2 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -448,32 +448,38 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
free(base);
}
-static int unpack_one(unsigned nr)
+static void read_typesize_v2(enum object_type *type, unsigned long *size)
{
+ unsigned char c = *(char*)fill_and_use(1);
unsigned shift;
- unsigned char *pack;
- unsigned long size, c;
+
+ *type = (c >> 4) & 7;
+ *size = (c & 15);
+ shift = 4;
+ while (c & 128) {
+ c = *(char*)fill_and_use(1);
+ *size += (c & 0x7f) << shift;
+ shift += 7;
+ }
+}
+
+static int unpack_one(unsigned nr)
+{
+ unsigned long size;
enum object_type type;
obj_list[nr].offset = consumed_bytes;
- pack = fill(1);
if (packv4 && *(char*)fill(1) == 0) {
use(1);
return -1;
}
- c = *pack;
- use(1);
- type = (c >> 4) & 7;
- size = (c & 15);
- shift = 4;
- while (c & 0x80) {
- pack = fill(1);
- c = *pack;
- use(1);
- size += (c & 0x7f) << shift;
- shift += 7;
- }
+ if (packv4) {
+ uintmax_t val = read_varint();
+ type = val & 15;
+ size = val >> 4;
+ } else
+ read_typesize_v2(&type, &size);
switch (type) {
case OBJ_COMMIT: