Skip to content

Commit c6dc4e5

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 fcc15b3 commit c6dc4e5

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,11 @@ int git_default_core_config(const char *var, const char *value,
17011701
return 0;
17021702
}
17031703

1704+
if (!strcmp(var, "core.virtualizeobjects")) {
1705+
core_virtualize_objects = git_config_bool(var, value);
1706+
return 0;
1707+
}
1708+
17041709
/* Add other config variables here and to Documentation/config.txt. */
17051710
return platform_core_config(var, value, ctx, cb);
17061711
}

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
@@ -84,6 +84,7 @@ int core_gvfs;
8484
int merge_log_config = -1;
8585
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
8686
unsigned long pack_size_limit_cfg;
87+
int core_virtualize_objects;
8788
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
8889
int max_allowed_tree_depth =
8990
#ifdef _MSC_VER

environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ struct strvec;
1111
extern const char *comment_line_str;
1212
extern int auto_comment_line_char;
1313

14+
extern int core_virtualize_objects;
15+
1416
/*
1517
* Wrapper of getenv() that returns a strdup value. This value is kept
1618
* in argv to be freed later.

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
@@ -1545,6 +1547,20 @@ void disable_obj_read_lock(void)
15451547
pthread_mutex_destroy(&obj_read_mutex);
15461548
}
15471549

1550+
static int run_read_object_hook(const struct object_id *oid)
1551+
{
1552+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
1553+
int ret;
1554+
uint64_t start;
1555+
1556+
start = getnanotime();
1557+
strvec_push(&opt.args, oid_to_hex(oid));
1558+
ret = run_hooks_opt("read-object", &opt);
1559+
trace_performance_since(start, "run_read_object_hook");
1560+
1561+
return ret;
1562+
}
1563+
15481564
int fetch_if_missing = 1;
15491565

15501566
static int do_oid_object_info_extended(struct repository *r,
@@ -1557,6 +1573,7 @@ static int do_oid_object_info_extended(struct repository *r,
15571573
int rtype;
15581574
const struct object_id *real = oid;
15591575
int already_retried = 0;
1576+
int tried_hook = 0;
15601577

15611578

15621579
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
@@ -1568,6 +1585,7 @@ static int do_oid_object_info_extended(struct repository *r,
15681585
if (!oi)
15691586
oi = &blank_oi;
15701587

1588+
retry:
15711589
co = find_cached_object(real);
15721590
if (co) {
15731591
if (oi->typep)
@@ -1599,6 +1617,11 @@ static int do_oid_object_info_extended(struct repository *r,
15991617
reprepare_packed_git(r);
16001618
if (find_pack_entry(r, real, &e))
16011619
break;
1620+
if (core_virtualize_objects && !tried_hook) {
1621+
tried_hook = 1;
1622+
if (!run_read_object_hook(oid))
1623+
goto retry;
1624+
}
16021625
}
16031626

16041627
/*

0 commit comments

Comments
 (0)