mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-30 22:24:56 +00:00
ODB pack: snapshot last_found to avoid race
Also removed unnecessary refresh call and fixed some indentation.
This commit is contained in:
parent
78216495b0
commit
6340945186
@ -259,12 +259,13 @@ static int packfile_refresh_all(struct pack_backend *backend)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pack_entry_find_inner(struct git_pack_entry *e,
|
static int pack_entry_find_inner(
|
||||||
struct pack_backend *backend,
|
struct git_pack_entry *e,
|
||||||
const git_oid *oid)
|
struct pack_backend *backend,
|
||||||
|
const git_oid *oid,
|
||||||
|
struct git_pack_file *last_found)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct git_pack_file *last_found = backend->last_found;
|
|
||||||
|
|
||||||
if (last_found &&
|
if (last_found &&
|
||||||
git_pack_entry_find(e, last_found, oid, GIT_OID_HEXSZ) == 0)
|
git_pack_entry_find(e, last_found, oid, GIT_OID_HEXSZ) == 0)
|
||||||
@ -289,33 +290,32 @@ static int pack_entry_find_inner(struct git_pack_entry *e,
|
|||||||
static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid)
|
static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
struct git_pack_file *last_found = backend->last_found;
|
||||||
|
|
||||||
if (backend->last_found &&
|
if (backend->last_found &&
|
||||||
git_pack_entry_find(e, backend->last_found, oid, GIT_OID_HEXSZ) == 0)
|
git_pack_entry_find(e, backend->last_found, oid, GIT_OID_HEXSZ) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!pack_entry_find_inner(e, backend, oid))
|
if (!pack_entry_find_inner(e, backend, oid, last_found))
|
||||||
return 0;
|
return 0;
|
||||||
if ((error = packfile_refresh_all(backend)) < 0)
|
if ((error = packfile_refresh_all(backend)) < 0)
|
||||||
return error;
|
return error;
|
||||||
if (!pack_entry_find_inner(e, backend, oid))
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned pack_entry_find_prefix_inner(struct git_pack_entry *e,
|
static unsigned pack_entry_find_prefix_inner(
|
||||||
struct pack_backend *backend,
|
struct git_pack_entry *e,
|
||||||
const git_oid *short_oid,
|
struct pack_backend *backend,
|
||||||
size_t len)
|
const git_oid *short_oid,
|
||||||
|
size_t len,
|
||||||
|
struct git_pack_file *last_found)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned found = 0;
|
unsigned found = 0;
|
||||||
struct git_pack_file *last_found = backend->last_found;
|
|
||||||
|
|
||||||
if ((error = packfile_refresh_all(backend)) < 0)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
if (last_found) {
|
if (last_found) {
|
||||||
error = git_pack_entry_find(e, last_found, short_oid, len);
|
error = git_pack_entry_find(e, last_found, short_oid, len);
|
||||||
@ -353,12 +353,13 @@ static int pack_entry_find_prefix(
|
|||||||
{
|
{
|
||||||
unsigned found = 0;
|
unsigned found = 0;
|
||||||
int error;
|
int error;
|
||||||
|
struct git_pack_file *last_found = backend->last_found;
|
||||||
|
|
||||||
if ((found = pack_entry_find_prefix_inner(e, backend, short_oid, len)) > 0)
|
if ((found = pack_entry_find_prefix_inner(e, backend, short_oid, len, last_found)) > 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if ((error = packfile_refresh_all(backend)) < 0)
|
if ((error = packfile_refresh_all(backend)) < 0)
|
||||||
return error;
|
return error;
|
||||||
found = pack_entry_find_prefix_inner(e, backend, short_oid, len);
|
found = pack_entry_find_prefix_inner(e, backend, short_oid, len, last_found);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (!found)
|
if (!found)
|
||||||
|
Loading…
Reference in New Issue
Block a user