Skip to content

Commit d481378

Browse files
Ben Peartmjcheetham
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 7d7f7f7 commit d481378

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
@@ -1653,6 +1653,11 @@ int git_default_core_config(const char *var, const char *value,
16531653
return 0;
16541654
}
16551655

1656+
if (!strcmp(var, "core.virtualizeobjects")) {
1657+
core_virtualize_objects = git_config_bool(var, value);
1658+
return 0;
1659+
}
1660+
16561661
/* Add other config variables here and to Documentation/config.adoc. */
16571662
return platform_core_config(var, value, ctx, cb);
16581663
}

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
@@ -214,5 +214,6 @@ extern const char *comment_line_str;
214214
extern char *comment_line_str_to_free;
215215
extern int auto_comment_line_char;
216216

217+
extern int core_virtualize_objects;
217218
# endif /* USE_THE_REPOSITORY_VARIABLE */
218219
#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
@@ -1633,6 +1635,20 @@ void disable_obj_read_lock(void)
16331635
pthread_mutex_destroy(&obj_read_mutex);
16341636
}
16351637

1638+
static int run_read_object_hook(struct repository *r, const struct object_id *oid)
1639+
{
1640+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
1641+
int ret;
1642+
uint64_t start;
1643+
1644+
start = getnanotime();
1645+
strvec_push(&opt.args, oid_to_hex(oid));
1646+
ret = run_hooks_opt(r, "read-object", &opt);
1647+
trace_performance_since(start, "run_read_object_hook");
1648+
1649+
return ret;
1650+
}
1651+
16361652
int fetch_if_missing = 1;
16371653

16381654
static int do_oid_object_info_extended(struct repository *r,
@@ -1645,6 +1661,7 @@ static int do_oid_object_info_extended(struct repository *r,
16451661
int rtype;
16461662
const struct object_id *real = oid;
16471663
int already_retried = 0;
1664+
int tried_hook = 0;
16481665

16491666

16501667
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
@@ -1656,6 +1673,7 @@ static int do_oid_object_info_extended(struct repository *r,
16561673
if (!oi)
16571674
oi = &blank_oi;
16581675

1676+
retry:
16591677
co = find_cached_object(real);
16601678
if (co) {
16611679
if (oi->typep)
@@ -1687,6 +1705,11 @@ static int do_oid_object_info_extended(struct repository *r,
16871705
reprepare_packed_git(r);
16881706
if (find_pack_entry(r, real, &e))
16891707
break;
1708+
if (core_virtualize_objects && !tried_hook) {
1709+
tried_hook = 1;
1710+
if (!run_read_object_hook(r, oid))
1711+
goto retry;
1712+
}
16901713
}
16911714

16921715
/*

0 commit comments

Comments
 (0)