Skip to content

Commit beb994c

Browse files
jeffhostetlerdscho
authored andcommitted
sha1-file: create shared-cache directory if it doesn't exist
The config variable `gvfs.sharedCache` contains the pathname to an alternate <odb> that will be used by `gvfs-helper` to store dynamically-fetched missing objects. If this directory does not exist on disk, `prepare_alt_odb()` omits this directory from the in-memory list of alternates. This causes `git` commands (and `gvfs-helper` in particular) to fall-back to `.git/objects` for storage of these objects. This disables the shared-cache and leads to poorer performance. Teach `alt_obj_usable()` and `prepare_alt_odb()`, match up the directory named in `gvfs.sharedCache` with an entry in `.git/objects/info/alternates` and force-create the `<odb>` root directory (and the associated `<odb>/pack` directory) if necessary. If the value of `gvfs.sharedCache` refers to a directory that is NOT listed as an alternate, create an in-memory alternate entry in the odb-list. (This is similar to how GIT_ALTERNATE_OBJECT_DIRECTORIES works.) This work happens the first time that `prepare_alt_odb()` is called. Furthermore, teach the `--shared-cache=<odb>` command line option in `gvfs-helper` (which is runs after the first call to `prepare_alt_odb()`) to override the inherited shared-cache (and again, create the ODB directory if necessary). Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 041bbba commit beb994c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

gvfs-helper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ static int option_parse_shared_cache_directory(const struct option *opt,
690690
*/
691691
strbuf_addbuf(&gvfs_shared_cache_pathname, &buf_arg);
692692

693-
add_to_alternates_memory(buf_arg.buf);
693+
odb_add_to_alternates_memory(the_repository->objects, buf_arg.buf);
694694

695695
strbuf_release(&buf_arg);
696696
return 0;
@@ -709,7 +709,7 @@ static int option_parse_shared_cache_directory(const struct option *opt,
709709
strbuf_setlen(&gvfs_shared_cache_pathname, 0);
710710
strbuf_addbuf(&gvfs_shared_cache_pathname, &buf_arg);
711711

712-
add_to_alternates_memory(buf_arg.buf);
712+
odb_add_to_alternates_memory(the_repository->objects, buf_arg.buf);
713713

714714
/*
715715
* alt_odb_usable() releases gvfs_shared_cache_pathname
@@ -1037,7 +1037,7 @@ static void select_odb(void)
10371037
&gvfs_shared_cache_pathname);
10381038
else
10391039
strbuf_addstr(&gh__global.buf_odb_path,
1040-
the_repository->objects->odb->path);
1040+
the_repository->objects->sources->path);
10411041
}
10421042

10431043
/*

odb.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static int alt_odb_usable(struct object_database *o,
100100
struct strbuf *path,
101101
const char *normalized_objdir, khiter_t *pos)
102102
{
103+
extern struct strbuf gvfs_shared_cache_pathname;
103104
int r;
104105

105106
if (!strbuf_cmp(path, &gvfs_shared_cache_pathname)) {
@@ -123,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
123124
*/
124125
strbuf_addf(&buf_pack_foo, "%s/pack/foo", path->buf);
125126

126-
scld = safe_create_leading_directories(the_repository, buf_pack_foo.buf);
127+
scld = safe_create_leading_directories(o->repo, buf_pack_foo.buf);
127128
if (scld != SCLD_OK && scld != SCLD_EXISTS) {
128129
error_errno(_("could not create shared-cache ODB '%s'"),
129130
gvfs_shared_cache_pathname.buf);
@@ -648,12 +649,14 @@ int odb_for_each_alternate(struct object_database *odb,
648649

649650
void odb_prepare_alternates(struct object_database *odb)
650651
{
652+
extern struct strbuf gvfs_shared_cache_pathname;
653+
651654
if (odb->loaded_alternates)
652655
return;
653656

654657
link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
655658

656-
read_info_alternates(r, r->objects->odb->path, 0);
659+
read_info_alternates(odb, odb->repo->objects->sources->path, 0);
657660

658661
if (gvfs_shared_cache_pathname.len &&
659662
!gvfs_matched_shared_cache_to_alternate) {
@@ -677,11 +680,11 @@ void odb_prepare_alternates(struct object_database *odb)
677680
* for us to update .git/objects/info/alternates instead.
678681
* The code here is considered a backstop.
679682
*/
680-
link_alt_odb_entries(r, gvfs_shared_cache_pathname.buf,
683+
link_alt_odb_entries(odb, gvfs_shared_cache_pathname.buf,
681684
'\n', NULL, 0);
682685
}
683686

684-
r->objects->loaded_alternates = 1;
687+
odb->repo->objects->loaded_alternates = 1;
685688
}
686689

687690
int odb_has_alternates(struct object_database *odb)

0 commit comments

Comments
 (0)