diff options
author | Edward Thomson <ethomson@github.com> | 2016-03-04 01:18:30 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-03-07 10:20:01 -0500 |
commit | e10144ae57e50798e43515cb469722a4e825c23c (patch) | |
tree | 7c47bd1660b6323551c23c9e84bc360c6c33d68b /src/odb.c | |
parent | 785d8c48ea8725691da3c50e7dae8751523d4c30 (diff) | |
download | libgit2-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.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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); |