Let's start actually parsing pack v4 data. Here's the first item. Signed-off-by: Nicolas Pitre <nico@xxxxxxxxxxx> --- Makefile | 1 + packv4-parse.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 packv4-parse.c diff --git a/Makefile b/Makefile index 4716113..ba6cafc 100644 --- a/Makefile +++ b/Makefile @@ -838,6 +838,7 @@ LIB_OBJS += object.o LIB_OBJS += pack-check.o LIB_OBJS += pack-revindex.o LIB_OBJS += pack-write.o +LIB_OBJS += packv4-parse.o LIB_OBJS += pager.o LIB_OBJS += parse-options.o LIB_OBJS += parse-options-cb.o diff --git a/packv4-parse.c b/packv4-parse.c new file mode 100644 index 0000000..299fc48 --- /dev/null +++ b/packv4-parse.c @@ -0,0 +1,30 @@ +/* + * Code to parse pack v4 object encoding + * + * (C) Nicolas Pitre <nico@xxxxxxxxxxx> + * + * This code is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include "cache.h" +#include "varint.h" + +const unsigned char *get_sha1ref(struct packed_git *p, + const unsigned char **bufp) +{ + const unsigned char *sha1; + + if (!**bufp) { + sha1 = *bufp + 1; + *bufp += 21; + } else { + unsigned int index = decode_varint(bufp); + if (index < 1 || index - 1 > p->num_objects) + die("bad index in %s", __func__); + sha1 = p->sha1_table + (index - 1) * 20; + } + + return sha1; +} -- 1.8.4.38.g317e65b -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html