gvfs: allow "virtualizing" objects

The idea is to allow blob objects to be missing from the local repository,
and to load them lazily on demand.

After discussing this idea on the mailing list, we will rename the feature
to "lazy clone" and work more on this.

Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
This commit is contained in:
Ben Peart 2017-01-10 18:47:14 +00:00 коммит произвёл Johannes Schindelin
Родитель daf6bc41c9
Коммит 56ba8237e0
5 изменённых файлов: 32 добавлений и 0 удалений

Просмотреть файл

@ -1088,6 +1088,8 @@ int use_optional_locks(void);
extern char comment_line_char; extern char comment_line_char;
extern int auto_comment_line_char; extern int auto_comment_line_char;
extern int core_virtualize_objects;
enum log_refs_config { enum log_refs_config {
LOG_REFS_UNSET = -1, LOG_REFS_UNSET = -1,
LOG_REFS_NONE = 0, LOG_REFS_NONE = 0,

Просмотреть файл

@ -1753,6 +1753,11 @@ int git_default_core_config(const char *var, const char *value, void *cb)
return 0; return 0;
} }
if (!strcmp(var, "core.virtualizeobjects")) {
core_virtualize_objects = git_config_bool(var, value);
return 0;
}
/* Add other config variables here and to Documentation/config.txt. */ /* Add other config variables here and to Documentation/config.txt. */
return platform_core_config(var, value, cb); return platform_core_config(var, value, cb);
} }

Просмотреть файл

@ -48,6 +48,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
*/ */
if (gvfs_config_is_set(GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK)) if (gvfs_config_is_set(GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK))
return 0; return 0;
if (core_virtualize_objects)
return 0;
if (!opt) if (!opt)
opt = &defaults; opt = &defaults;

Просмотреть файл

@ -77,6 +77,7 @@ int core_gvfs;
int merge_log_config = -1; int merge_log_config = -1;
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
unsigned long pack_size_limit_cfg; unsigned long pack_size_limit_cfg;
int core_virtualize_objects;
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET; enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
#ifndef PROTECT_HFS_DEFAULT #ifndef PROTECT_HFS_DEFAULT

Просмотреть файл

@ -33,6 +33,7 @@
#include "object-store.h" #include "object-store.h"
#include "promisor-remote.h" #include "promisor-remote.h"
#include "submodule.h" #include "submodule.h"
#include "hook.h"
/* The maximum size for an object header. */ /* The maximum size for an object header. */
#define MAX_HEADER_LEN 32 #define MAX_HEADER_LEN 32
@ -1525,6 +1526,20 @@ void disable_obj_read_lock(void)
pthread_mutex_destroy(&obj_read_mutex); pthread_mutex_destroy(&obj_read_mutex);
} }
static int run_read_object_hook(const struct object_id *oid)
{
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
int ret;
uint64_t start;
start = getnanotime();
strvec_push(&opt.args, oid_to_hex(oid));
ret = run_hooks_opt("read-object", &opt);
trace_performance_since(start, "run_read_object_hook");
return ret;
}
int fetch_if_missing = 1; int fetch_if_missing = 1;
static int do_oid_object_info_extended(struct repository *r, static int do_oid_object_info_extended(struct repository *r,
@ -1537,6 +1552,7 @@ static int do_oid_object_info_extended(struct repository *r,
int rtype; int rtype;
const struct object_id *real = oid; const struct object_id *real = oid;
int already_retried = 0; int already_retried = 0;
int tried_hook = 0;
if (flags & OBJECT_INFO_LOOKUP_REPLACE) if (flags & OBJECT_INFO_LOOKUP_REPLACE)
@ -1548,6 +1564,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi) if (!oi)
oi = &blank_oi; oi = &blank_oi;
retry:
co = find_cached_object(real); co = find_cached_object(real);
if (co) { if (co) {
if (oi->typep) if (oi->typep)
@ -1582,6 +1599,11 @@ static int do_oid_object_info_extended(struct repository *r,
reprepare_packed_git(r); reprepare_packed_git(r);
if (find_pack_entry(r, real, &e)) if (find_pack_entry(r, real, &e))
break; break;
if (core_virtualize_objects && !tried_hook) {
tried_hook = 1;
if (!run_read_object_hook(oid))
goto retry;
}
} }
/* /*