Skip to content

Commit

Permalink
gvfs: allow "virtualizing" objects
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ben Peart authored and dscho committed Jun 8, 2019
1 parent 033080a commit 8e05a37
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cache.h
Expand Up @@ -916,6 +916,8 @@ int use_optional_locks(void);
extern char comment_line_char;
extern int auto_comment_line_char;

extern int core_virtualize_objects;

enum log_refs_config {
LOG_REFS_UNSET = -1,
LOG_REFS_NONE = 0,
Expand Down
5 changes: 5 additions & 0 deletions config.c
Expand Up @@ -1360,6 +1360,11 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
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. */
return platform_core_config(var, value, cb);
}
Expand Down
2 changes: 2 additions & 0 deletions connected.c
Expand Up @@ -47,6 +47,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
*/
if (gvfs_config_is_set(GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK))
return 0;
if (core_virtualize_objects)
return 0;

if (!opt)
opt = &defaults;
Expand Down
1 change: 1 addition & 0 deletions environment.c
Expand Up @@ -73,6 +73,7 @@ int core_gvfs;
int merge_log_config = -1;
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
unsigned long pack_size_limit_cfg;
int core_virtualize_objects;
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;

#ifndef PROTECT_HFS_DEFAULT
Expand Down
22 changes: 22 additions & 0 deletions sha1-file.c
Expand Up @@ -1318,6 +1318,21 @@ static int loose_object_info(struct repository *r,
return (status < 0) ? status : 0;
}

static int run_read_object_hook(const struct object_id *oid)
{
struct argv_array args = ARGV_ARRAY_INIT;
int ret;
uint64_t start;

start = getnanotime();
argv_array_push(&args, oid_to_hex(oid));
ret = run_hook_argv(NULL, "read-object", args.argv);
argv_array_clear(&args);
trace_performance_since(start, "run_read_object_hook");

return ret;
}

int fetch_if_missing = 1;

int oid_object_info_extended(struct repository *r, const struct object_id *oid,
Expand All @@ -1328,6 +1343,7 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
int rtype;
const struct object_id *real = oid;
int already_retried = 0;
int tried_hook = 0;

if (flags & OBJECT_INFO_LOOKUP_REPLACE)
real = lookup_replace_object(r, oid);
Expand All @@ -1338,6 +1354,7 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
if (!oi)
oi = &blank_oi;

retry:
if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
struct cached_object *co = find_cached_object(real);
if (co) {
Expand Down Expand Up @@ -1374,6 +1391,11 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
reprepare_packed_git(r);
if (find_pack_entry(r, real, &e))
break;
if (core_virtualize_objects && !tried_hook) {
tried_hook = 1;
if (!run_read_object_hook(oid))
goto retry;
}
}

/* Check if it is a missing object */
Expand Down

0 comments on commit 8e05a37

Please sign in to comment.