Skip to content

Commit 5c1fb20

Browse files
Ben Peartvdye
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 <Ben.Peart@microsoft.com>
1 parent c103076 commit 5c1fb20

5 files changed

Lines changed: 34 additions & 0 deletions

File tree

config.c

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

1853+
if (!strcmp(var, "core.virtualizeobjects")) {
1854+
core_virtualize_objects = git_config_bool(var, value);
1855+
return 0;
1856+
}
1857+
18531858
/* Add other config variables here and to Documentation/config.txt. */
18541859
return platform_core_config(var, value, cb);
18551860
}

connected.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "git-compat-util.h"
2+
#include "environment.h"
23
#include "gettext.h"
34
#include "hex.h"
45
#include "gvfs.h"
@@ -50,6 +51,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
5051
*/
5152
if (gvfs_config_is_set(GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK))
5253
return 0;
54+
if (core_virtualize_objects)
55+
return 0;
5356

5457
if (!opt)
5558
opt = &defaults;

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ int core_gvfs;
8383
int merge_log_config = -1;
8484
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
8585
unsigned long pack_size_limit_cfg;
86+
int core_virtualize_objects;
8687
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
8788

8889
#ifndef PROTECT_HFS_DEFAULT

environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct repository;
1212
extern char comment_line_char;
1313
extern int auto_comment_line_char;
1414

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

object-file.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "submodule.h"
4545
#include "fsck.h"
4646
#include "wrapper.h"
47+
#include "trace.h"
48+
#include "hook.h"
4749

4850
/* The maximum size for an object header. */
4951
#define MAX_HEADER_LEN 32
@@ -1553,6 +1555,20 @@ void disable_obj_read_lock(void)
15531555
pthread_mutex_destroy(&obj_read_mutex);
15541556
}
15551557

1558+
static int run_read_object_hook(const struct object_id *oid)
1559+
{
1560+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
1561+
int ret;
1562+
uint64_t start;
1563+
1564+
start = getnanotime();
1565+
strvec_push(&opt.args, oid_to_hex(oid));
1566+
ret = run_hooks_opt("read-object", &opt);
1567+
trace_performance_since(start, "run_read_object_hook");
1568+
1569+
return ret;
1570+
}
1571+
15561572
int fetch_if_missing = 1;
15571573

15581574
static int do_oid_object_info_extended(struct repository *r,
@@ -1565,6 +1581,7 @@ static int do_oid_object_info_extended(struct repository *r,
15651581
int rtype;
15661582
const struct object_id *real = oid;
15671583
int already_retried = 0;
1584+
int tried_hook = 0;
15681585

15691586

15701587
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
@@ -1576,6 +1593,7 @@ static int do_oid_object_info_extended(struct repository *r,
15761593
if (!oi)
15771594
oi = &blank_oi;
15781595

1596+
retry:
15791597
co = find_cached_object(real);
15801598
if (co) {
15811599
if (oi->typep)
@@ -1607,6 +1625,11 @@ static int do_oid_object_info_extended(struct repository *r,
16071625
reprepare_packed_git(r);
16081626
if (find_pack_entry(r, real, &e))
16091627
break;
1628+
if (core_virtualize_objects && !tried_hook) {
1629+
tried_hook = 1;
1630+
if (!run_read_object_hook(oid))
1631+
goto retry;
1632+
}
16101633
}
16111634

16121635
/*

0 commit comments

Comments
 (0)