summaryrefslogtreecommitdiff
path: root/src/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/object.c')
-rw-r--r--src/object.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/object.c b/src/object.c
index c84e94b05..12947f035 100644
--- a/src/object.c
+++ b/src/object.c
@@ -77,9 +77,15 @@ static int create_object(git_object **object_out, git_otype type)
return GIT_SUCCESS;
}
-int git_object_lookup_prefix(git_object **object_out, git_repository *repo, const git_oid *id, unsigned int len, git_otype type)
+int git_object_lookup_prefix(
+ git_object **object_out,
+ git_repository *repo,
+ const git_oid *id,
+ unsigned int len,
+ git_otype type)
{
git_object *object = NULL;
+ git_odb *odb = NULL;
git_odb_object *odb_obj;
int error = GIT_SUCCESS;
@@ -89,6 +95,10 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
return git__throw(GIT_EAMBIGUOUSOIDPREFIX,
"Failed to lookup object. Prefix length is lower than %d.", GIT_OID_MINPREFIXLEN);
+ error = git_repository_odb__weakptr(&odb, repo);
+ if (error < GIT_SUCCESS)
+ return error;
+
if (len > GIT_OID_HEXSZ)
len = GIT_OID_HEXSZ;
@@ -98,10 +108,11 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
*/
object = git_cache_get(&repo->objects, id);
if (object != NULL) {
- if (type != GIT_OBJ_ANY && type != object->type)
- {
+ if (type != GIT_OBJ_ANY && type != object->type) {
git_object_close(object);
- return git__throw(GIT_EINVALIDTYPE, "Failed to lookup object. The given type does not match the type on the ODB");
+ return git__throw(GIT_EINVALIDTYPE,
+ "Failed to lookup object. "
+ "The given type does not match the type on the ODB");
}
*object_out = object;
@@ -113,7 +124,7 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
* it is the same cost for packed and loose object backends,
* but it may be much more costly for sqlite and hiredis.
*/
- error = git_odb_read(&odb_obj, repo->db, id);
+ error = git_odb_read(&odb_obj, odb, id);
} else {
git_oid short_oid;
@@ -133,7 +144,7 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
* - We never explore the cache, go right to exploring the backends
* We chose the latter : we explore directly the backends.
*/
- error = git_odb_read_prefix(&odb_obj, repo->db, &short_oid, len);
+ error = git_odb_read_prefix(&odb_obj, odb, &short_oid, len);
}
if (error < GIT_SUCCESS)