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>
René Scharfe committed
Jan 9, 2026 at 22:30 UTC
2b74f68ca0553afcab3bed4b6971cf3bfd1fa7b2
2 files changed
+21
-3
tree.c
+13
-3
@@ -186,6 +186,12 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
186
}
187
188
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)
195
{
196
enum object_type type;
197
void *buffer;
@@ -193,8 +199,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
199
200
if (item->object.parsed)
201
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);
203
if (!buffer)
204
return quiet_on_missing ? -1 :
205
error("Could not read %s",
@@ -216,7 +221,12 @@ void free_tree_buffer(struct tree *tree)
221
222
struct tree *parse_tree_indirect(const struct object_id *oid)
223
{
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
+{
230
struct object *obj = parse_object(r, oid);
231
return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
232
}
tree.h
+8
@@ -20,14 +20,22 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
20
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
21
22
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);
25
static inline int parse_tree(struct tree *tree)
26
{
27
return parse_tree_gently(tree, 0);
28
}
29
+static inline int repo_parse_tree(struct repository *r, struct tree *item)
30
+{
31
+ return repo_parse_tree_gently(r, item, 0);
32
+}
33
void free_tree_buffer(struct tree *tree);
34
35
/* Parses and returns the tree in the given ent, chasing tags and commits. */
36
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);
39
40
/*
41
* Functions for comparing pathnames