Skip to content

Commit 69a4394

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 04e60c0 commit 69a4394

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
@@ -1678,6 +1678,11 @@ int git_default_core_config(const char *var, const char *value,
16781678
return 0;
16791679
}
16801680

1681+
if (!strcmp(var, "core.virtualizeobjects")) {
1682+
core_virtualize_objects = git_config_bool(var, value);
1683+
return 0;
1684+
}
1685+
16811686
/* Add other config variables here and to Documentation/config.txt. */
16821687
return platform_core_config(var, value, ctx, cb);
16831688
}

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
@@ -75,6 +75,7 @@ int core_gvfs;
7575
int merge_log_config = -1;
7676
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7777
unsigned long pack_size_limit_cfg;
78+
int core_virtualize_objects;
7879
int max_allowed_tree_depth =
7980
#ifdef _MSC_VER
8081
/*

environment.h

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

229+
extern int core_virtualize_objects;
229230
# endif /* USE_THE_REPOSITORY_VARIABLE */
230231
#endif /* ENVIRONMENT_H */

object-file.c

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

4446
/* The maximum size for an object header. */
4547
#define MAX_HEADER_LEN 32
@@ -1620,6 +1622,20 @@ void disable_obj_read_lock(void)
16201622
pthread_mutex_destroy(&obj_read_mutex);
16211623
}
16221624

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

16251641
static int do_oid_object_info_extended(struct repository *r,
@@ -1632,6 +1648,7 @@ static int do_oid_object_info_extended(struct repository *r,
16321648
int rtype;
16331649
const struct object_id *real = oid;
16341650
int already_retried = 0;
1651+
int tried_hook = 0;
16351652

16361653

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

1663+
retry:
16461664
co = find_cached_object(real);
16471665
if (co) {
16481666
if (oi->typep)
@@ -1674,6 +1692,11 @@ static int do_oid_object_info_extended(struct repository *r,
16741692
reprepare_packed_git(r);
16751693
if (find_pack_entry(r, real, &e))
16761694
break;
1695+
if (core_virtualize_objects && !tried_hook) {
1696+
tried_hook = 1;
1697+
if (!run_read_object_hook(r, oid))
1698+
goto retry;
1699+
}
16771700
}
16781701

16791702
/*

0 commit comments

Comments
 (0)