summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-03-04 01:18:30 -0500
committerEdward Thomson <ethomson@github.com>2016-03-07 10:20:01 -0500
commite10144ae57e50798e43515cb469722a4e825c23c (patch)
tree7c47bd1660b6323551c23c9e84bc360c6c33d68b /src/odb.c
parent785d8c48ea8725691da3c50e7dae8751523d4c30 (diff)
downloadlibgit2-e10144ae57e50798e43515cb469722a4e825c23c.tar.gz
odb: improved not found error messages
When looking up an abbreviated oid, show the actual (abbreviated) oid the caller passed instead of a full (but ambiguously truncated) oid.
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/odb.c b/src/odb.c
index 1c877c9fc..cb0f70623 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -725,7 +725,8 @@ int git_odb_exists_prefix(
git_oid_cpy(out, short_id);
return 0;
} else {
- return git_odb__error_notfound("no match for id prefix", short_id);
+ return git_odb__error_notfound(
+ "no match for id prefix", short_id, len);
}
}
@@ -740,7 +741,7 @@ int git_odb_exists_prefix(
error = odb_exists_prefix_1(out, db, &key, len, true);
if (error == GIT_ENOTFOUND)
- return git_odb__error_notfound("no match for id prefix", &key);
+ return git_odb__error_notfound("no match for id prefix", &key, len);
return error;
}
@@ -881,7 +882,7 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
error = odb_read_1(out, db, id, true);
if (error == GIT_ENOTFOUND)
- return git_odb__error_notfound("no match for id", id);
+ return git_odb__error_notfound("no match for id", id, GIT_OID_HEXSZ);
return error;
}
@@ -967,7 +968,7 @@ int git_odb_read_prefix(
error = read_prefix_1(out, db, &key, len, true);
if (error == GIT_ENOTFOUND)
- return git_odb__error_notfound("no match for prefix", &key);
+ return git_odb__error_notfound("no match for prefix", &key, len);
return error;
}
@@ -1223,12 +1224,14 @@ int git_odb_refresh(struct git_odb *db)
return 0;
}
-int git_odb__error_notfound(const char *message, const git_oid *oid)
+int git_odb__error_notfound(
+ const char *message, const git_oid *oid, size_t oid_len)
{
if (oid != NULL) {
char oid_str[GIT_OID_HEXSZ + 1];
- git_oid_tostr(oid_str, sizeof(oid_str), oid);
- giterr_set(GITERR_ODB, "Object not found - %s (%s)", message, oid_str);
+ git_oid_tostr(oid_str, oid_len, oid);
+ giterr_set(GITERR_ODB, "Object not found - %s (%.*s)",
+ message, oid_len, oid_str);
} else
giterr_set(GITERR_ODB, "Object not found - %s", message);