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>
Signed-off-by: Johannes Schindelin <johasc@microsoft.com>
  • Loading branch information
Ben Peart authored and dscho committed Oct 8, 2024
1 parent 162137d commit 2516df2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,11 @@ int git_default_core_config(const char *var, const char *value,
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, ctx, cb);
}
Expand Down
3 changes: 3 additions & 0 deletions connected.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "gvfs.h"
Expand Down Expand Up @@ -52,6 +53,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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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;
int max_allowed_tree_depth =
#ifdef _MSC_VER
/*
Expand Down
1 change: 1 addition & 0 deletions environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,6 @@ extern const char *comment_line_str;
extern char *comment_line_str_to_free;
extern int auto_comment_line_char;

extern int core_virtualize_objects;
# endif /* USE_THE_REPOSITORY_VARIABLE */
#endif /* ENVIRONMENT_H */
23 changes: 23 additions & 0 deletions object-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "fsck.h"
#include "loose.h"
#include "object-file-convert.h"
#include "trace.h"
#include "hook.h"

/* The maximum size for an object header. */
#define MAX_HEADER_LEN 32
Expand Down Expand Up @@ -1620,6 +1622,20 @@ void disable_obj_read_lock(void)
pthread_mutex_destroy(&obj_read_mutex);
}

static int run_read_object_hook(struct repository *r, 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(r, "read-object", &opt);
trace_performance_since(start, "run_read_object_hook");

return ret;
}

int fetch_if_missing = 1;

static int do_oid_object_info_extended(struct repository *r,
Expand All @@ -1632,6 +1648,7 @@ static int do_oid_object_info_extended(struct repository *r,
int rtype;
const struct object_id *real = oid;
int already_retried = 0;
int tried_hook = 0;


if (flags & OBJECT_INFO_LOOKUP_REPLACE)
Expand All @@ -1643,6 +1660,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi)
oi = &blank_oi;

retry:
co = find_cached_object(real);
if (co) {
if (oi->typep)
Expand Down Expand Up @@ -1674,6 +1692,11 @@ static int do_oid_object_info_extended(struct repository *r,
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(r, oid))
goto retry;
}
}

/*
Expand Down

0 comments on commit 2516df2

Please sign in to comment.