vendor/libgit2/src/odb_pack.c in rugged-0.25.0b5 vs vendor/libgit2/src/odb_pack.c in rugged-0.25.0b6

- old
+ new

@@ -11,17 +11,20 @@ #include "git2/indexer.h" #include "git2/sys/odb_backend.h" #include "fileops.h" #include "hash.h" #include "odb.h" -#include "delta-apply.h" +#include "delta.h" #include "sha1_lookup.h" #include "mwindow.h" #include "pack.h" #include "git2/odb_backend.h" +/* re-freshen pack files no more than every 2 seconds */ +#define FRESHEN_FREQUENCY 2 + struct pack_backend { git_odb_backend parent; git_vector packs; struct git_pack_file *last_found; char *pack_folder; @@ -361,10 +364,32 @@ return error; return git_packfile_resolve_header(len_p, type_p, e.p, e.offset); } +static int pack_backend__freshen( + git_odb_backend *backend, const git_oid *oid) +{ + struct git_pack_entry e; + time_t now; + int error; + + if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0) + return error; + + now = time(NULL); + + if (e.p->last_freshen > now - FRESHEN_FREQUENCY) + return 0; + + if ((error = git_futils_touch(e.p->pack_name, &now)) < 0) + return error; + + e.p->last_freshen = now; + return 0; +} + static int pack_backend__read( void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) { struct git_pack_entry e; @@ -558,10 +583,11 @@ backend->parent.exists = &pack_backend__exists; backend->parent.exists_prefix = &pack_backend__exists_prefix; backend->parent.refresh = &pack_backend__refresh; backend->parent.foreach = &pack_backend__foreach; backend->parent.writepack = &pack_backend__writepack; + backend->parent.freshen = &pack_backend__freshen; backend->parent.free = &pack_backend__free; *out = backend; return 0; } @@ -588,12 +614,9 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir) { int error = 0; struct pack_backend *backend = NULL; git_buf path = GIT_BUF_INIT; - - if (git_mwindow_files_init() < 0) - return -1; if (pack_backend__alloc(&backend, 8) < 0) return -1; if (!(error = git_buf_joinpath(&path, objects_dir, "pack")) &&