From 19c76e8235747a61a703fe3bf7a5e40caf6fa3fa Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 17 May 2024 10:18:59 +0200 Subject: refs: move object peeling into "object.c" Peeling an object has nothing to do with refs, but we still have the code in "refs.c". Move it over into "object.c", which is a more natural place to put it. Ideally, we'd also move `peel_iterated_oid()` over into "object.c". But this function is tied to the refs interfaces because it uses a global ref iterator variable to optimize peeling when the iterator already has the peeled object ID readily available. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- object.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'object.c') diff --git a/object.c b/object.c index 51e384828e..995041926a 100644 --- a/object.c +++ b/object.c @@ -207,6 +207,27 @@ struct object *lookup_object_by_type(struct repository *r, } } +enum peel_status peel_object(const struct object_id *name, struct object_id *oid) +{ + struct object *o = lookup_unknown_object(the_repository, name); + + if (o->type == OBJ_NONE) { + int type = oid_object_info(the_repository, name, NULL); + if (type < 0 || !object_as_type(o, type, 0)) + return PEEL_INVALID; + } + + if (o->type != OBJ_TAG) + return PEEL_NON_TAG; + + o = deref_tag_noverify(o); + if (!o) + return PEEL_INVALID; + + oidcpy(oid, &o->oid); + return PEEL_PEELED; +} + struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) { struct object *obj; -- cgit v1.3