mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-11 23:37:38 +00:00
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.
This commit is contained in:
parent
cdded6309a
commit
eb09ead246
17
src/odb.c
17
src/odb.c
@ -725,7 +725,8 @@ int git_odb_exists_prefix(
|
|||||||
git_oid_cpy(out, short_id);
|
git_oid_cpy(out, short_id);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} 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);
|
error = odb_exists_prefix_1(out, db, &key, len, true);
|
||||||
|
|
||||||
if (error == GIT_ENOTFOUND)
|
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;
|
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);
|
error = odb_read_1(out, db, id, true);
|
||||||
|
|
||||||
if (error == GIT_ENOTFOUND)
|
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;
|
return error;
|
||||||
}
|
}
|
||||||
@ -967,7 +968,7 @@ int git_odb_read_prefix(
|
|||||||
error = read_prefix_1(out, db, &key, len, true);
|
error = read_prefix_1(out, db, &key, len, true);
|
||||||
|
|
||||||
if (error == GIT_ENOTFOUND)
|
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;
|
return error;
|
||||||
}
|
}
|
||||||
@ -1223,12 +1224,14 @@ int git_odb_refresh(struct git_odb *db)
|
|||||||
return 0;
|
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) {
|
if (oid != NULL) {
|
||||||
char oid_str[GIT_OID_HEXSZ + 1];
|
char oid_str[GIT_OID_HEXSZ + 1];
|
||||||
git_oid_tostr(oid_str, sizeof(oid_str), oid);
|
git_oid_tostr(oid_str, oid_len, oid);
|
||||||
giterr_set(GITERR_ODB, "Object not found - %s (%s)", message, oid_str);
|
giterr_set(GITERR_ODB, "Object not found - %s (%.*s)",
|
||||||
|
message, oid_len, oid_str);
|
||||||
} else
|
} else
|
||||||
giterr_set(GITERR_ODB, "Object not found - %s", message);
|
giterr_set(GITERR_ODB, "Object not found - %s", message);
|
||||||
|
|
||||||
|
@ -82,7 +82,8 @@ int git_odb__hashlink(git_oid *out, const char *path);
|
|||||||
/*
|
/*
|
||||||
* Generate a GIT_ENOTFOUND error for the ODB.
|
* Generate a GIT_ENOTFOUND error for the ODB.
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate a GIT_EAMBIGUOUS error for the ODB.
|
* Generate a GIT_EAMBIGUOUS error for the ODB.
|
||||||
|
@ -547,7 +547,8 @@ static int locate_object_short_oid(
|
|||||||
|
|
||||||
/* Check that directory exists */
|
/* Check that directory exists */
|
||||||
if (git_path_isdir(object_location->ptr) == false)
|
if (git_path_isdir(object_location->ptr) == false)
|
||||||
return git_odb__error_notfound("no matching loose object for prefix", short_oid);
|
return git_odb__error_notfound("no matching loose object for prefix",
|
||||||
|
short_oid, len);
|
||||||
|
|
||||||
state.dir_len = git_buf_len(object_location);
|
state.dir_len = git_buf_len(object_location);
|
||||||
state.short_oid_len = len;
|
state.short_oid_len = len;
|
||||||
@ -560,7 +561,8 @@ static int locate_object_short_oid(
|
|||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (!state.found)
|
if (!state.found)
|
||||||
return git_odb__error_notfound("no matching loose object for prefix", short_oid);
|
return git_odb__error_notfound("no matching loose object for prefix",
|
||||||
|
short_oid, len);
|
||||||
|
|
||||||
if (state.found > 1)
|
if (state.found > 1)
|
||||||
return git_odb__error_ambiguous("multiple matches in loose objects");
|
return git_odb__error_ambiguous("multiple matches in loose objects");
|
||||||
@ -613,9 +615,10 @@ static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_
|
|||||||
raw.len = 0;
|
raw.len = 0;
|
||||||
raw.type = GIT_OBJ_BAD;
|
raw.type = GIT_OBJ_BAD;
|
||||||
|
|
||||||
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
|
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
|
||||||
error = git_odb__error_notfound("no matching loose object", oid);
|
error = git_odb__error_notfound("no matching loose object",
|
||||||
else if ((error = read_header_loose(&raw, &object_path)) == 0) {
|
oid, GIT_OID_HEXSZ);
|
||||||
|
} else if ((error = read_header_loose(&raw, &object_path)) == 0) {
|
||||||
*len_p = raw.len;
|
*len_p = raw.len;
|
||||||
*type_p = raw.type;
|
*type_p = raw.type;
|
||||||
}
|
}
|
||||||
@ -633,9 +636,10 @@ static int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p
|
|||||||
|
|
||||||
assert(backend && oid);
|
assert(backend && oid);
|
||||||
|
|
||||||
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
|
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
|
||||||
error = git_odb__error_notfound("no matching loose object", oid);
|
error = git_odb__error_notfound("no matching loose object",
|
||||||
else if ((error = read_loose(&raw, &object_path)) == 0) {
|
oid, GIT_OID_HEXSZ);
|
||||||
|
} else if ((error = read_loose(&raw, &object_path)) == 0) {
|
||||||
*buffer_p = raw.data;
|
*buffer_p = raw.data;
|
||||||
*len_p = raw.len;
|
*len_p = raw.len;
|
||||||
*type_p = raw.type;
|
*type_p = raw.type;
|
||||||
|
@ -264,7 +264,8 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen
|
|||||||
if (!pack_entry_find_inner(e, backend, oid, last_found))
|
if (!pack_entry_find_inner(e, backend, oid, last_found))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return git_odb__error_notfound("failed to find pack entry", oid);
|
return git_odb__error_notfound(
|
||||||
|
"failed to find pack entry", oid, GIT_OID_HEXSZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pack_entry_find_prefix(
|
static int pack_entry_find_prefix(
|
||||||
@ -309,7 +310,8 @@ static int pack_entry_find_prefix(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
return git_odb__error_notfound("no matching pack entry for prefix", short_oid);
|
return git_odb__error_notfound("no matching pack entry for prefix",
|
||||||
|
short_oid, len);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -333,7 +335,7 @@ static int pack_backend__refresh(git_odb_backend *backend_)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
|
if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
|
||||||
return git_odb__error_notfound("failed to refresh packfiles", NULL);
|
return git_odb__error_notfound("failed to refresh packfiles", NULL, 0);
|
||||||
|
|
||||||
git_buf_sets(&path, backend->pack_folder);
|
git_buf_sets(&path, backend->pack_folder);
|
||||||
|
|
||||||
|
10
src/pack.c
10
src/pack.c
@ -1015,7 +1015,7 @@ static int packfile_open(struct git_pack_file *p)
|
|||||||
unsigned char *idx_sha1;
|
unsigned char *idx_sha1;
|
||||||
|
|
||||||
if (p->index_version == -1 && pack_index_open(p) < 0)
|
if (p->index_version == -1 && pack_index_open(p) < 0)
|
||||||
return git_odb__error_notfound("failed to open packfile", NULL);
|
return git_odb__error_notfound("failed to open packfile", NULL, 0);
|
||||||
|
|
||||||
/* if mwf opened by another thread, return now */
|
/* if mwf opened by another thread, return now */
|
||||||
if (git_mutex_lock(&p->lock) < 0)
|
if (git_mutex_lock(&p->lock) < 0)
|
||||||
@ -1096,7 +1096,7 @@ int git_packfile__name(char **out, const char *path)
|
|||||||
path_len = strlen(path);
|
path_len = strlen(path);
|
||||||
|
|
||||||
if (path_len < strlen(".idx"))
|
if (path_len < strlen(".idx"))
|
||||||
return git_odb__error_notfound("invalid packfile path", NULL);
|
return git_odb__error_notfound("invalid packfile path", NULL, 0);
|
||||||
|
|
||||||
if (git_buf_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
|
if (git_buf_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1114,7 +1114,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
|
|||||||
*pack_out = NULL;
|
*pack_out = NULL;
|
||||||
|
|
||||||
if (path_len < strlen(".idx"))
|
if (path_len < strlen(".idx"))
|
||||||
return git_odb__error_notfound("invalid packfile path", NULL);
|
return git_odb__error_notfound("invalid packfile path", NULL, 0);
|
||||||
|
|
||||||
GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*p), path_len);
|
GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*p), path_len);
|
||||||
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
|
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
|
||||||
@ -1140,7 +1140,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
|
|||||||
|
|
||||||
if (p_stat(p->pack_name, &st) < 0 || !S_ISREG(st.st_mode)) {
|
if (p_stat(p->pack_name, &st) < 0 || !S_ISREG(st.st_mode)) {
|
||||||
git__free(p);
|
git__free(p);
|
||||||
return git_odb__error_notfound("packfile not found", NULL);
|
return git_odb__error_notfound("packfile not found", NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ok, it looks sane as far as we can check without
|
/* ok, it looks sane as far as we can check without
|
||||||
@ -1341,7 +1341,7 @@ static int pack_entry_find_offset(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
return git_odb__error_notfound("failed to find offset for pack entry", short_oid);
|
return git_odb__error_notfound("failed to find offset for pack entry", short_oid, len);
|
||||||
if (found > 1)
|
if (found > 1)
|
||||||
return git_odb__error_ambiguous("found multiple offsets for pack entry");
|
return git_odb__error_ambiguous("found multiple offsets for pack entry");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user