Skip to content

Commit 0df7e63

Browse files
Ben Peartdscho
authored andcommitted
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> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent ca883f1 commit 0df7e63

6 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎connected.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#define USE_THE_REPOSITORY_VARIABLE
22

33
#include "git-compat-util.h"
4+
#include "environment.h"
45
#include "gettext.h"
56
#include "gvfs.h"
67
#include "hex.h"
@@ -52,6 +53,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
5253
*/
5354
if (gvfs_config_is_set(the_repository, GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK))
5455
return 0;
56+
if (gvfs_virtualize_objects(the_repository))
57+
return 0;
5558

5659
if (!opt)
5760
opt = &defaults;

‎environment.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ int core_sparse_checkout_cone;
8080
int sparse_expect_files_outside_of_patterns;
8181
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
8282
unsigned long pack_size_limit_cfg;
83+
int core_virtualize_objects;
8384
int max_allowed_tree_depth =
8485
#ifdef _MSC_VER
8586
/*

‎environment.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,6 @@ extern int auto_comment_line_char;
215215
extern bool warn_on_auto_comment_char;
216216
#endif /* !WITH_BREAKING_CHANGES */
217217

218+
extern int core_virtualize_objects;
218219
# endif /* USE_THE_REPOSITORY_VARIABLE */
219220
#endif /* ENVIRONMENT_H */

‎gvfs.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ static int early_core_gvfs_config(const char *var, const char *value,
1616
if (!strcmp(var, "core.gvfs"))
1717
core_gvfs = git_config_bool_or_int("core.gvfs", value, ctx->kvi,
1818
&core_gvfs_is_bool);
19+
if (!strcmp(var, "core.virtualizeobjects"))
20+
core_virtualize_objects = git_config_bool(var, value);
1921
return 0;
2022
}
2123

@@ -27,11 +29,16 @@ static void gvfs_load_config_value(struct repository *r)
2729
if (r) {
2830
repo_config_get_bool_or_int(r, "core.gvfs",
2931
&core_gvfs_is_bool, &core_gvfs);
30-
} else if (startup_info->have_repository == 0)
32+
repo_config_get_bool(r, "core.virtualizeobjects",
33+
&core_virtualize_objects);
34+
} else if (startup_info->have_repository == 0) {
3135
read_early_config(the_repository, early_core_gvfs_config, NULL);
32-
else
36+
} else {
3337
repo_config_get_bool_or_int(the_repository, "core.gvfs",
3438
&core_gvfs_is_bool, &core_gvfs);
39+
repo_config_get_bool(the_repository, "core.virtualizeobjects",
40+
&core_virtualize_objects);
41+
}
3542

3643
/* Turn on all bits if a bool was set in the settings */
3744
if (core_gvfs_is_bool && core_gvfs)
@@ -46,3 +53,9 @@ int gvfs_config_is_set(struct repository *r, int mask)
4653
gvfs_load_config_value(r);
4754
return (core_gvfs & mask) == mask;
4855
}
56+
57+
int gvfs_virtualize_objects(struct repository *r)
58+
{
59+
gvfs_load_config_value(r);
60+
return core_virtualize_objects;
61+
}

‎gvfs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ struct repository;
1818
#define GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS (1 << 6)
1919

2020
int gvfs_config_is_set(struct repository *r, int mask);
21+
int gvfs_virtualize_objects(struct repository *r);
2122

2223
#endif /* GVFS_H */

‎odb.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include "dir.h"
77
#include "environment.h"
88
#include "gettext.h"
9+
#include "gvfs.h"
910
#include "hex.h"
11+
#include "hook.h"
1012
#include "khash.h"
1113
#include "lockfile.h"
1214
#include "loose.h"
@@ -26,6 +28,7 @@
2628
#include "submodule.h"
2729
#include "tmp-objdir.h"
2830
#include "trace2.h"
31+
#include "trace.h"
2932
#include "write-or-die.h"
3033

3134
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -656,6 +659,20 @@ void disable_obj_read_lock(void)
656659
pthread_mutex_destroy(&obj_read_mutex);
657660
}
658661

662+
static int run_read_object_hook(struct repository *r, const struct object_id *oid)
663+
{
664+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
665+
int ret;
666+
uint64_t start;
667+
668+
start = getnanotime();
669+
strvec_push(&opt.args, oid_to_hex(oid));
670+
ret = run_hooks_opt(r, "read-object", &opt);
671+
trace_performance_since(start, "run_read_object_hook");
672+
673+
return ret;
674+
}
675+
659676
int fetch_if_missing = 1;
660677

661678
static int register_all_submodule_sources(struct object_database *odb)
@@ -682,13 +699,15 @@ static int do_oid_object_info_extended(struct object_database *odb,
682699
const struct cached_object *co;
683700
const struct object_id *real = oid;
684701
int already_retried = 0;
702+
int tried_hook = 0;
685703

686704
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
687705
real = lookup_replace_object(odb->repo, oid);
688706

689707
if (is_null_oid(real))
690708
return -1;
691709

710+
retry:
692711
co = find_cached_object(odb, real);
693712
if (co) {
694713
if (oi) {
@@ -725,6 +744,11 @@ static int do_oid_object_info_extended(struct object_database *odb,
725744
for (source = odb->sources; source; source = source->next)
726745
if (!packfile_store_read_object_info(source->packfiles, real, oi, flags))
727746
return 0;
747+
if (gvfs_virtualize_objects(odb->repo) && !tried_hook) {
748+
tried_hook = 1;
749+
if (!run_read_object_hook(odb->repo, oid))
750+
goto retry;
751+
}
728752
}
729753

730754
/*

0 commit comments

Comments
 (0)