summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/odb.c b/src/odb.c
index ed600ffab..f98f9f92a 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -495,8 +495,10 @@ int git_odb_read_unique_short_oid(git_oid *out_oid, git_odb_object **out, git_od
git_rawobj raw;
int found = 0;
- assert(out && db && id && len > 0);
+ assert(out && db && id);
+ if (len < GIT_OID_MINPREFIXLEN)
+ return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to lookup object. Prefix length is lower than %d.", GIT_OID_MINPREFIXLEN);
if (len > GIT_OID_HEXSZ)
len = GIT_OID_HEXSZ;
@@ -514,17 +516,26 @@ int git_odb_read_unique_short_oid(git_oid *out_oid, git_odb_object **out, git_od
if (b->read != NULL) {
error = b->read_unique_short_oid(out_oid, &raw.data, &raw.len, &raw.type, b, short_id, len);
- if (error == GIT_SUCCESS)
+ switch (error) {
+ case GIT_SUCCESS:
found++;
+ break;
+ case GIT_ENOTFOUND:
+ break;
+ case GIT_EAMBIGUOUSOIDPREFIX:
+ return git__rethrow(error, "Failed to read object. Ambiguous sha1 prefix");
+ default:
+ return git__rethrow(error, "Failed to read object");
+ }
}
}
if (found == 1) {
*out = git_cache_try_store(&db->cache, new_odb_object(out_oid, &raw));
} else if (found > 1) {
- return git__rethrow(GIT_EAMBIGUOUSOIDPREFIX, "Ambiguous sha1");
+ return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to read object. Ambiguous sha1 prefix");
} else {
- return git__rethrow(GIT_ENOTFOUND, "Failed to read object");
+ return git__throw(GIT_ENOTFOUND, "Failed to read object. Object not found");
}
return GIT_SUCCESS;