Skip to content

Commit 2b74f68

Browse files
rscharfegitster
authored andcommitted
tree: add repo_parse_tree*()
Add variants of parse_tree(), parse_tree_gently() and parse_tree_indirect() that allow using an arbitrary repository. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e691395 commit 2b74f68

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

tree.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,20 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
186186
}
187187

188188
int parse_tree_gently(struct tree *item, int quiet_on_missing)
189+
{
190+
return repo_parse_tree_gently(the_repository, item, quiet_on_missing);
191+
}
192+
193+
int repo_parse_tree_gently(struct repository *r, struct tree *item,
194+
int quiet_on_missing)
189195
{
190196
enum object_type type;
191197
void *buffer;
192198
unsigned long size;
193199

194200
if (item->object.parsed)
195201
return 0;
196-
buffer = odb_read_object(the_repository->objects, &item->object.oid,
197-
&type, &size);
202+
buffer = odb_read_object(r->objects, &item->object.oid, &type, &size);
198203
if (!buffer)
199204
return quiet_on_missing ? -1 :
200205
error("Could not read %s",
@@ -216,7 +221,12 @@ void free_tree_buffer(struct tree *tree)
216221

217222
struct tree *parse_tree_indirect(const struct object_id *oid)
218223
{
219-
struct repository *r = the_repository;
224+
return repo_parse_tree_indirect(the_repository, oid);
225+
}
226+
227+
struct tree *repo_parse_tree_indirect(struct repository *r,
228+
const struct object_id *oid)
229+
{
220230
struct object *obj = parse_object(r, oid);
221231
return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
222232
}

tree.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
2020
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
2121

2222
int parse_tree_gently(struct tree *tree, int quiet_on_missing);
23+
int repo_parse_tree_gently(struct repository *r, struct tree *item,
24+
int quiet_on_missing);
2325
static inline int parse_tree(struct tree *tree)
2426
{
2527
return parse_tree_gently(tree, 0);
2628
}
29+
static inline int repo_parse_tree(struct repository *r, struct tree *item)
30+
{
31+
return repo_parse_tree_gently(r, item, 0);
32+
}
2733
void free_tree_buffer(struct tree *tree);
2834

2935
/* Parses and returns the tree in the given ent, chasing tags and commits. */
3036
struct tree *parse_tree_indirect(const struct object_id *oid);
37+
struct tree *repo_parse_tree_indirect(struct repository *r,
38+
const struct object_id *oid);
3139

3240
/*
3341
* Functions for comparing pathnames

0 commit comments

Comments
 (0)