Because the path dictionary table is located right after the name dictionary table, we currently need to load the later to find the former. Signed-off-by: Nicolas Pitre <nico@xxxxxxxxxxx> --- cache.h | 2 ++ packv4-parse.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/cache.h b/cache.h index 6ce327e..5f2147a 100644 --- a/cache.h +++ b/cache.h @@ -1030,6 +1030,8 @@ extern struct packed_git { int version; int index_version; struct packv4_dict *name_dict; + off_t name_dict_end; + struct packv4_dict *path_dict; time_t mtime; int pack_fd; unsigned pack_local:1, diff --git a/packv4-parse.c b/packv4-parse.c index 431f47e..b80b73e 100644 --- a/packv4-parse.c +++ b/packv4-parse.c @@ -114,6 +114,7 @@ static void load_name_dict(struct packed_git *p) if (!names) die("bad pack name dictionary in %s", p->pack_name); p->name_dict = names; + p->name_dict_end = offset; } const unsigned char *get_nameref(struct packed_git *p, const unsigned char **srcp) @@ -131,6 +132,41 @@ const unsigned char *get_nameref(struct packed_git *p, const unsigned char **src return p->name_dict->data + p->name_dict->offsets[index]; } +static void load_path_dict(struct packed_git *p) +{ + off_t offset; + struct packv4_dict *paths; + + /* + * For now we need to load the name dictionary to know where + * it ends and therefore where the path dictionary starts. + */ + if (!p->name_dict) + load_name_dict(p); + + offset = p->name_dict_end; + paths = load_dict(p, &offset); + if (!paths) + die("bad pack path dictionary in %s", p->pack_name); + p->path_dict = paths; +} + +const unsigned char *get_pathref(struct packed_git *p, const unsigned char **srcp) +{ + unsigned int index; + + if (!p->path_dict) + load_path_dict(p); + + index = decode_varint(srcp); + if (index < 1 || index - 1 >= p->path_dict->nb_entries) { + error("%s: index overflow", __func__); + return NULL; + } + index -= 1; + return p->path_dict->data + p->path_dict->offsets[index]; +} + void *pv4_get_commit(struct packed_git *p, struct pack_window **w_curs, off_t offset, unsigned long size) { -- 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