Skip to content

Commit 6e17496

Browse files
Ben Peartdscho
Ben Peart
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 e44a53b commit 6e17496

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,11 @@ int git_default_core_config(const char *var, const char *value,
16571657
return 0;
16581658
}
16591659

1660+
if (!strcmp(var, "core.virtualizeobjects")) {
1661+
core_virtualize_objects = git_config_bool(var, value);
1662+
return 0;
1663+
}
1664+
16601665
/* Add other config variables here and to Documentation/config.txt. */
16611666
return platform_core_config(var, value, ctx, cb);
16621667
}

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 "hex.h"
67
#include "gvfs.h"
@@ -52,6 +53,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
5253
*/
5354
if (gvfs_config_is_set(GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK))
5455
return 0;
56+
if (core_virtualize_objects)
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
@@ -72,6 +72,7 @@ int core_gvfs;
7272
int merge_log_config = -1;
7373
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7474
unsigned long pack_size_limit_cfg;
75+
int core_virtualize_objects;
7576
int max_allowed_tree_depth =
7677
#ifdef _MSC_VER
7778
/*

environment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,6 @@ extern const char *comment_line_str;
225225
extern char *comment_line_str_to_free;
226226
extern int auto_comment_line_char;
227227

228+
extern int core_virtualize_objects;
228229
# endif /* USE_THE_REPOSITORY_VARIABLE */
229230
#endif /* ENVIRONMENT_H */

object-file.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "fsck.h"
4242
#include "loose.h"
4343
#include "object-file-convert.h"
44+
#include "trace.h"
45+
#include "hook.h"
4446

4547
/* The maximum size for an object header. */
4648
#define MAX_HEADER_LEN 32
@@ -1616,6 +1618,20 @@ void disable_obj_read_lock(void)
16161618
pthread_mutex_destroy(&obj_read_mutex);
16171619
}
16181620

1621+
static int run_read_object_hook(struct repository *r, const struct object_id *oid)
1622+
{
1623+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
1624+
int ret;
1625+
uint64_t start;
1626+
1627+
start = getnanotime();
1628+
strvec_push(&opt.args, oid_to_hex(oid));
1629+
ret = run_hooks_opt(r, "read-object", &opt);
1630+
trace_performance_since(start, "run_read_object_hook");
1631+
1632+
return ret;
1633+
}
1634+
16191635
int fetch_if_missing = 1;
16201636

16211637
static int do_oid_object_info_extended(struct repository *r,
@@ -1628,6 +1644,7 @@ static int do_oid_object_info_extended(struct repository *r,
16281644
int rtype;
16291645
const struct object_id *real = oid;
16301646
int already_retried = 0;
1647+
int tried_hook = 0;
16311648

16321649

16331650
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
@@ -1639,6 +1656,7 @@ static int do_oid_object_info_extended(struct repository *r,
16391656
if (!oi)
16401657
oi = &blank_oi;
16411658

1659+
retry:
16421660
co = find_cached_object(real);
16431661
if (co) {
16441662
if (oi->typep)
@@ -1670,6 +1688,11 @@ static int do_oid_object_info_extended(struct repository *r,
16701688
reprepare_packed_git(r);
16711689
if (find_pack_entry(r, real, &e))
16721690
break;
1691+
if (core_virtualize_objects && !tried_hook) {
1692+
tried_hook = 1;
1693+
if (!run_read_object_hook(r, oid))
1694+
goto retry;
1695+
}
16731696
}
16741697

16751698
/*

0 commit comments

Comments
 (0)