mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 20:42:32 +00:00
Remove mtime checks from ODB packfile backend
Now forcing refresh on a foreach, and on missed full-oid or short-oid lookups.
This commit is contained in:
parent
5bb0dc9390
commit
78216495b0
@ -24,7 +24,6 @@ struct pack_backend {
|
|||||||
git_vector packs;
|
git_vector packs;
|
||||||
struct git_pack_file *last_found;
|
struct git_pack_file *last_found;
|
||||||
char *pack_folder;
|
char *pack_folder;
|
||||||
time_t pack_folder_mtime;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,7 +232,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
|
|||||||
return git_vector_insert(&backend->packs, pack);
|
return git_vector_insert(&backend->packs, pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int packfile_refresh_all_maybe(struct pack_backend *backend, bool force)
|
static int packfile_refresh_all(struct pack_backend *backend)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -245,28 +244,21 @@ static int packfile_refresh_all_maybe(struct pack_backend *backend, bool force)
|
|||||||
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);
|
||||||
|
|
||||||
if (force || st.st_mtime != backend->pack_folder_mtime) {
|
git_buf_sets(&path, backend->pack_folder);
|
||||||
git_buf_sets(&path, backend->pack_folder);
|
|
||||||
|
|
||||||
/* reload all packs */
|
/* reload all packs */
|
||||||
error = git_path_direach(&path, packfile_load__cb, (void *)backend);
|
error = git_path_direach(&path, packfile_load__cb, (void *)backend);
|
||||||
|
|
||||||
git_buf_free(&path);
|
git_buf_free(&path);
|
||||||
|
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
git_vector_sort(&backend->packs);
|
git_vector_sort(&backend->packs);
|
||||||
backend->pack_folder_mtime = st.st_mtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int packfile_refresh_all(struct pack_backend *backend) {
|
|
||||||
return packfile_refresh_all_maybe(backend, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int pack_entry_find_inner(struct git_pack_entry *e,
|
static int pack_entry_find_inner(struct git_pack_entry *e,
|
||||||
struct pack_backend *backend,
|
struct pack_backend *backend,
|
||||||
const git_oid *oid)
|
const git_oid *oid)
|
||||||
@ -304,7 +296,7 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen
|
|||||||
|
|
||||||
if (!pack_entry_find_inner(e, backend, oid))
|
if (!pack_entry_find_inner(e, backend, oid))
|
||||||
return 0;
|
return 0;
|
||||||
if ((error = packfile_refresh_all_maybe(backend, true)) < 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))
|
||||||
return 0;
|
return 0;
|
||||||
@ -312,11 +304,10 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen
|
|||||||
return git_odb__error_notfound("failed to find pack entry", oid);
|
return git_odb__error_notfound("failed to find pack entry", oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pack_entry_find_prefix(
|
static unsigned pack_entry_find_prefix_inner(struct git_pack_entry *e,
|
||||||
struct git_pack_entry *e,
|
struct pack_backend *backend,
|
||||||
struct pack_backend *backend,
|
const git_oid *short_oid,
|
||||||
const git_oid *short_oid,
|
size_t len)
|
||||||
size_t len)
|
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -351,6 +342,25 @@ static int pack_entry_find_prefix(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pack_entry_find_prefix(
|
||||||
|
struct git_pack_entry *e,
|
||||||
|
struct pack_backend *backend,
|
||||||
|
const git_oid *short_oid,
|
||||||
|
size_t len)
|
||||||
|
{
|
||||||
|
unsigned found = 0;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
if ((found = pack_entry_find_prefix_inner(e, backend, short_oid, len)) > 0)
|
||||||
|
goto cleanup;
|
||||||
|
if ((error = packfile_refresh_all(backend)) < 0)
|
||||||
|
return error;
|
||||||
|
found = pack_entry_find_prefix_inner(e, backend, short_oid, len);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
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);
|
||||||
else if (found > 1)
|
else if (found > 1)
|
||||||
@ -535,7 +545,6 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
|
|||||||
|
|
||||||
if (git_path_isdir(git_buf_cstr(&path)) == true) {
|
if (git_path_isdir(git_buf_cstr(&path)) == true) {
|
||||||
backend->pack_folder = git_buf_detach(&path);
|
backend->pack_folder = git_buf_detach(&path);
|
||||||
backend->pack_folder_mtime = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backend->parent.read = &pack_backend__read;
|
backend->parent.read = &pack_backend__read;
|
||||||
|
Loading…
Reference in New Issue
Block a user