mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-07 22:59:45 +00:00
reflog: Error handling on empty reflog
This commit is contained in:
parent
0972443c47
commit
1e71354e34
@ -205,7 +205,6 @@ cleanup:
|
|||||||
static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t identifier)
|
static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t identifier)
|
||||||
{
|
{
|
||||||
git_reflog *reflog;
|
git_reflog *reflog;
|
||||||
int error = -1;
|
|
||||||
size_t numentries;
|
size_t numentries;
|
||||||
const git_reflog_entry *entry;
|
const git_reflog_entry *entry;
|
||||||
bool search_by_pos = (identifier <= 100000000);
|
bool search_by_pos = (identifier <= 100000000);
|
||||||
@ -216,21 +215,11 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide
|
|||||||
numentries = git_reflog_entrycount(reflog);
|
numentries = git_reflog_entrycount(reflog);
|
||||||
|
|
||||||
if (search_by_pos) {
|
if (search_by_pos) {
|
||||||
if (numentries < identifier + 1) {
|
if (numentries < identifier + 1)
|
||||||
giterr_set(
|
goto notfound;
|
||||||
GITERR_REFERENCE,
|
|
||||||
"Reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ,
|
|
||||||
git_reference_name(ref), numentries, identifier);
|
|
||||||
|
|
||||||
error = GIT_ENOTFOUND;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry = git_reflog_entry_byindex(reflog, identifier);
|
entry = git_reflog_entry_byindex(reflog, identifier);
|
||||||
git_oid_cpy(oid, git_reflog_entry_id_new(entry));
|
git_oid_cpy(oid, git_reflog_entry_id_new(entry));
|
||||||
error = 0;
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
size_t i;
|
size_t i;
|
||||||
git_time commit_time;
|
git_time commit_time;
|
||||||
@ -243,16 +232,24 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
git_oid_cpy(oid, git_reflog_entry_id_new(entry));
|
git_oid_cpy(oid, git_reflog_entry_id_new(entry));
|
||||||
error = 0;
|
break;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error = GIT_ENOTFOUND;
|
if (i == numentries)
|
||||||
|
goto notfound;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
git_reflog_free(reflog);
|
git_reflog_free(reflog);
|
||||||
return error;
|
return 0;
|
||||||
|
|
||||||
|
notfound:
|
||||||
|
giterr_set(
|
||||||
|
GITERR_REFERENCE,
|
||||||
|
"Reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ,
|
||||||
|
git_reference_name(ref), numentries, identifier);
|
||||||
|
|
||||||
|
git_reflog_free(reflog);
|
||||||
|
return GIT_ENOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position)
|
static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position)
|
||||||
|
Loading…
Reference in New Issue
Block a user