public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: git@vger.kernel.org
Subject: [PATCH 02/10] tree: add repo_parse_tree*()
Date: Fri,  9 Jan 2026 22:30:13 +0100	[thread overview]
Message-ID: <20260109213021.2546-3-l.s.r@web.de> (raw)
In-Reply-To: <20260109213021.2546-1-l.s.r@web.de>

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>
---
 tree.c | 16 +++++++++++++---
 tree.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/tree.c b/tree.c
index 2a677234d60..036f56ca29b 100644
--- 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 cc6ddf51b32..9037891d30f 100644
--- 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
-- 
2.52.0


  parent reply	other threads:[~2026-01-09 21:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-09 21:30 [PATCH 00/10] tree: stop using the_repository René Scharfe
2026-01-09 21:30 ` [PATCH 01/10] environment: move access to core.maxTreeDepth into repo settings René Scharfe
2026-01-12  9:21   ` Patrick Steinhardt
2026-01-12 19:37     ` René Scharfe
2026-01-09 21:30 ` René Scharfe [this message]
2026-01-09 21:30 ` [PATCH 03/10] add-interactive: use repo_parse_tree_indirect() René Scharfe
2026-01-09 21:30 ` [PATCH 04/10] bloom: use repo_parse_tree() René Scharfe
2026-01-09 21:30 ` [PATCH 05/10] delta-islands: " René Scharfe
2026-01-09 21:30 ` [PATCH 06/10] pack-bitmap-write: " René Scharfe
2026-01-09 21:30 ` [PATCH 07/10] path-walk: use repo_parse_tree_gently() René Scharfe
2026-01-09 21:30 ` [PATCH 08/10] tree: use repo_parse_tree() René Scharfe
2026-01-12  9:21   ` Patrick Steinhardt
2026-01-09 21:30 ` [PATCH 09/10] tree: stop using the_repository René Scharfe
2026-01-12  9:21   ` Patrick Steinhardt
2026-01-12 14:22     ` Junio C Hamano
2026-01-12 15:00       ` Patrick Steinhardt
2026-01-12 15:17         ` Junio C Hamano
2026-01-12 15:20         ` Junio C Hamano
2026-01-12 15:28           ` Patrick Steinhardt
2026-01-12 19:37             ` René Scharfe
2026-01-13  6:13               ` Patrick Steinhardt
2026-01-09 21:30 ` [PATCH 10/10] cocci: convert parse_tree functions to repo_ variants René Scharfe
2026-01-15 22:01 ` [PATCH 11/10] cocci: remove obsolete the_repository rules René Scharfe
2026-01-16 10:02   ` Patrick Steinhardt
2026-01-16 17:28     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260109213021.2546-3-l.s.r@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox