Skip to content

Commit 173d324

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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4767665 commit 173d324

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

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
@@ -81,6 +81,7 @@ int sparse_expect_files_outside_of_patterns;
8181
int merge_log_config = -1;
8282
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
8383
unsigned long pack_size_limit_cfg;
84+
int core_virtualize_objects;
8485
int max_allowed_tree_depth =
8586
#ifdef _MSC_VER
8687
/*

environment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,6 @@ extern const char *comment_line_str;
212212
extern char *comment_line_str_to_free;
213213
extern int auto_comment_line_char;
214214

215+
extern int core_virtualize_objects;
215216
# endif /* USE_THE_REPOSITORY_VARIABLE */
216217
#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
@@ -5,7 +5,9 @@
55
#include "dir.h"
66
#include "environment.h"
77
#include "gettext.h"
8+
#include "gvfs.h"
89
#include "hex.h"
10+
#include "hook.h"
911
#include "khash.h"
1012
#include "lockfile.h"
1113
#include "loose.h"
@@ -23,6 +25,7 @@
2325
#include "strvec.h"
2426
#include "submodule.h"
2527
#include "trace2.h"
28+
#include "trace.h"
2629
#include "write-or-die.h"
2730

2831
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -628,6 +631,20 @@ void disable_obj_read_lock(void)
628631
pthread_mutex_destroy(&obj_read_mutex);
629632
}
630633

634+
static int run_read_object_hook(struct repository *r, const struct object_id *oid)
635+
{
636+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
637+
int ret;
638+
uint64_t start;
639+
640+
start = getnanotime();
641+
strvec_push(&opt.args, oid_to_hex(oid));
642+
ret = run_hooks_opt(r, "read-object", &opt);
643+
trace_performance_since(start, "run_read_object_hook");
644+
645+
return ret;
646+
}
647+
631648
int fetch_if_missing = 1;
632649

633650
static int register_all_submodule_sources(struct object_database *odb)
@@ -657,6 +674,7 @@ static int do_oid_object_info_extended(struct object_database *odb,
657674
int rtype;
658675
const struct object_id *real = oid;
659676
int already_retried = 0;
677+
int tried_hook = 0;
660678

661679

662680
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
@@ -668,6 +686,7 @@ static int do_oid_object_info_extended(struct object_database *odb,
668686
if (!oi)
669687
oi = &blank_oi;
670688

689+
retry:
671690
co = find_cached_object(odb, real);
672691
if (co) {
673692
if (oi->typep)
@@ -697,6 +716,11 @@ static int do_oid_object_info_extended(struct object_database *odb,
697716
reprepare_packed_git(odb->repo);
698717
if (find_pack_entry(odb->repo, real, &e))
699718
break;
719+
if (gvfs_virtualize_objects(odb->repo) && !tried_hook) {
720+
tried_hook = 1;
721+
if (!run_read_object_hook(odb->repo, oid))
722+
goto retry;
723+
}
700724
}
701725

702726
/*

0 commit comments

Comments
 (0)