]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tree: add repo_parse_tree*()
authorRené Scharfe <l.s.r@web.de>
Fri, 9 Jan 2026 21:30:13 +0000 (22:30 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 10 Jan 2026 02:36:16 +0000 (18:36 -0800)
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>
tree.c
tree.h

diff --git a/tree.c b/tree.c
index 2a677234d60aa10e4c993ee43602681d1a7f6b10..036f56ca29bb149644bd7a8e64db0d78218ec426 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -186,6 +186,12 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
 }
 
 int parse_tree_gently(struct tree *item, int quiet_on_missing)
+{
+       return repo_parse_tree_gently(the_repository, item, quiet_on_missing);
+}
+
+int repo_parse_tree_gently(struct repository *r, struct tree *item,
+                          int quiet_on_missing)
 {
         enum object_type type;
         void *buffer;
@@ -193,8 +199,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
 
        if (item->object.parsed)
                return 0;
-       buffer = odb_read_object(the_repository->objects, &item->object.oid,
-                                &type, &size);
+       buffer = odb_read_object(r->objects, &item->object.oid, &type, &size);
        if (!buffer)
                return quiet_on_missing ? -1 :
                        error("Could not read %s",
@@ -216,7 +221,12 @@ void free_tree_buffer(struct tree *tree)
 
 struct tree *parse_tree_indirect(const struct object_id *oid)
 {
-       struct repository *r = the_repository;
+       return repo_parse_tree_indirect(the_repository, oid);
+}
+
+struct tree *repo_parse_tree_indirect(struct repository *r,
+                                     const struct object_id *oid)
+{
        struct object *obj = parse_object(r, oid);
        return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
 }
diff --git a/tree.h b/tree.h
index cc6ddf51b3273c2dbeb798b2cb945de29dd28a36..9037891d30fbb433b7db8f0ce208305d1c8de7f0 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -20,14 +20,22 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
 int parse_tree_gently(struct tree *tree, int quiet_on_missing);
+int repo_parse_tree_gently(struct repository *r, struct tree *item,
+                          int quiet_on_missing);
 static inline int parse_tree(struct tree *tree)
 {
        return parse_tree_gently(tree, 0);
 }
+static inline int repo_parse_tree(struct repository *r, struct tree *item)
+{
+       return repo_parse_tree_gently(r, item, 0);
+}
 void free_tree_buffer(struct tree *tree);
 
 /* Parses and returns the tree in the given ent, chasing tags and commits. */
 struct tree *parse_tree_indirect(const struct object_id *oid);
+struct tree *repo_parse_tree_indirect(struct repository *r,
+                                     const struct object_id *oid);
 
 /*
  * Functions for comparing pathnames