From 9d98354f48997faf8251c566d909957f6ae427d5 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Wed, 25 Apr 2018 11:21:06 -0700 Subject: cache.h: allow oid_object_info to handle arbitrary repositories This involves also adapting oid_object_info_extended and a some internal functions that are used to implement these. It all has to happen in one patch, because of a single recursive chain of calls visits all these functions. oid_object_info_extended is also used in partial clones, which allow fetching missing objects. As this series will not add the repository struct to the transport code and fetch_object(), add a TODO note and omit fetching if a user tries to use a partial clone in a repository other than the_repository. Among the functions modified to handle arbitrary repositories, unpack_entry() is one of them. Note that it still references the globals "delta_base_cache" and "delta_base_cached", but those are safe to be referenced (the former is indexed partly by "struct packed_git *", which is repo-specific, and the latter is only used to limit the size of the former as an optimization). Helped-by: Brandon Williams Helped-by: Jonathan Tan Signed-off-by: Jonathan Nieder Signed-off-by: Stefan Beller Reviewed-by: Jonathan Tan Signed-off-by: Junio C Hamano --- sha1_file.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'sha1_file.c') diff --git a/sha1_file.c b/sha1_file.c index 746ff8297a..dcd6b879ac 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1231,7 +1231,8 @@ static int sha1_loose_object_info(struct repository *r, int fetch_if_missing = 1; -int oid_object_info_extended_the_repository(const struct object_id *oid, struct object_info *oi, unsigned flags) +int oid_object_info_extended(struct repository *r, const struct object_id *oid, + struct object_info *oi, unsigned flags) { static struct object_info blank_oi = OBJECT_INFO_INIT; struct pack_entry e; @@ -1240,7 +1241,7 @@ int oid_object_info_extended_the_repository(const struct object_id *oid, struct int already_retried = 0; if (flags & OBJECT_INFO_LOOKUP_REPLACE) - real = lookup_replace_object(the_repository, oid); + real = lookup_replace_object(r, oid); if (is_null_oid(real)) return -1; @@ -1269,29 +1270,31 @@ int oid_object_info_extended_the_repository(const struct object_id *oid, struct } while (1) { - if (find_pack_entry(the_repository, real->hash, &e)) + if (find_pack_entry(r, real->hash, &e)) break; if (flags & OBJECT_INFO_IGNORE_LOOSE) return -1; /* Most likely it's a loose object. */ - if (!sha1_loose_object_info(the_repository, real->hash, oi, flags)) + if (!sha1_loose_object_info(r, real->hash, oi, flags)) return 0; /* Not a loose object; someone else may have just packed it. */ if (!(flags & OBJECT_INFO_QUICK)) { - reprepare_packed_git(the_repository); - if (find_pack_entry(the_repository, real->hash, &e)) + reprepare_packed_git(r); + if (find_pack_entry(r, real->hash, &e)) break; } /* Check if it is a missing object */ if (fetch_if_missing && repository_format_partial_clone && - !already_retried) { + !already_retried && r == the_repository) { /* - * TODO Investigate haveing fetch_object() return + * TODO Investigate having fetch_object() return * TODO error/success and stopping the music here. + * TODO Pass a repository struct through fetch_object, + * such that arbitrary repositories work. */ fetch_object(repository_format_partial_clone, real->hash); already_retried = 1; @@ -1307,10 +1310,10 @@ int oid_object_info_extended_the_repository(const struct object_id *oid, struct * information below, so return early. */ return 0; - rtype = packed_object_info(the_repository, e.p, e.offset, oi); + rtype = packed_object_info(r, e.p, e.offset, oi); if (rtype < 0) { mark_bad_packed_object(e.p, real->hash); - return oid_object_info_extended(the_repository, real, oi, 0); + return oid_object_info_extended(r, real, oi, 0); } else if (oi->whence == OI_PACKED) { oi->u.packed.offset = e.offset; oi->u.packed.pack = e.p; @@ -1322,15 +1325,17 @@ int oid_object_info_extended_the_repository(const struct object_id *oid, struct } /* returns enum object_type or negative */ -int oid_object_info_the_repository(const struct object_id *oid, unsigned long *sizep) +int oid_object_info(struct repository *r, + const struct object_id *oid, + unsigned long *sizep) { enum object_type type; struct object_info oi = OBJECT_INFO_INIT; oi.typep = &type; oi.sizep = sizep; - if (oid_object_info_extended(the_repository, oid, &oi, - OBJECT_INFO_LOOKUP_REPLACE) < 0) + if (oid_object_info_extended(r, oid, &oi, + OBJECT_INFO_LOOKUP_REPLACE) < 0) return -1; return type; } -- cgit v1.2.3