Skip to content

Commit d66e31f

Browse files
Ben Peartderrickstolee
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]>
1 parent 36343ce commit d66e31f

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,8 @@ int use_optional_locks(void);
10751075
extern char comment_line_char;
10761076
extern int auto_comment_line_char;
10771077

1078+
extern int core_virtualize_objects;
1079+
10781080
enum log_refs_config {
10791081
LOG_REFS_UNSET = -1,
10801082
LOG_REFS_NONE = 0,

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,11 @@ int git_default_core_config(const char *var, const char *value, void *cb)
17791779
return 0;
17801780
}
17811781

1782+
if (!strcmp(var, "core.virtualizeobjects")) {
1783+
core_virtualize_objects = git_config_bool(var, value);
1784+
return 0;
1785+
}
1786+
17821787
/* Add other config variables here and to Documentation/config.txt. */
17831788
return platform_core_config(var, value, cb);
17841789
}

connected.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
4848
*/
4949
if (gvfs_config_is_set(GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK))
5050
return 0;
51+
if (core_virtualize_objects)
52+
return 0;
5153

5254
if (!opt)
5355
opt = &defaults;

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ int core_gvfs;
7676
int merge_log_config = -1;
7777
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7878
unsigned long pack_size_limit_cfg;
79+
int core_virtualize_objects;
7980
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
8081

8182
#ifndef PROTECT_HFS_DEFAULT

object-file.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "promisor-remote.h"
3535
#include "submodule.h"
3636
#include "fsck.h"
37+
#include "hook.h"
3738

3839
/* The maximum size for an object header. */
3940
#define MAX_HEADER_LEN 32
@@ -1537,6 +1538,20 @@ void disable_obj_read_lock(void)
15371538
pthread_mutex_destroy(&obj_read_mutex);
15381539
}
15391540

1541+
static int run_read_object_hook(const struct object_id *oid)
1542+
{
1543+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
1544+
int ret;
1545+
uint64_t start;
1546+
1547+
start = getnanotime();
1548+
strvec_push(&opt.args, oid_to_hex(oid));
1549+
ret = run_hooks_opt("read-object", &opt);
1550+
trace_performance_since(start, "run_read_object_hook");
1551+
1552+
return ret;
1553+
}
1554+
15401555
int fetch_if_missing = 1;
15411556

15421557
static int do_oid_object_info_extended(struct repository *r,
@@ -1549,6 +1564,7 @@ static int do_oid_object_info_extended(struct repository *r,
15491564
int rtype;
15501565
const struct object_id *real = oid;
15511566
int already_retried = 0;
1567+
int tried_hook = 0;
15521568

15531569

15541570
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
@@ -1560,6 +1576,7 @@ static int do_oid_object_info_extended(struct repository *r,
15601576
if (!oi)
15611577
oi = &blank_oi;
15621578

1579+
retry:
15631580
co = find_cached_object(real);
15641581
if (co) {
15651582
if (oi->typep)
@@ -1591,6 +1608,11 @@ static int do_oid_object_info_extended(struct repository *r,
15911608
reprepare_packed_git(r);
15921609
if (find_pack_entry(r, real, &e))
15931610
break;
1611+
if (core_virtualize_objects && !tried_hook) {
1612+
tried_hook = 1;
1613+
if (!run_read_object_hook(oid))
1614+
goto retry;
1615+
}
15941616
}
15951617

15961618
/*

0 commit comments

Comments
 (0)