Skip to content

Commit 31b8dee

Browse files
derrickstoleedscho
authored andcommitted
maintenance: care about gvfs.sharedCache config
For Scalar and VFS for Git, we use an alternate as a shared object cache. We need to enable the maintenance builtin to work on that shared object cache, especially in the background. 'scalar run <task>' would set GIT_OBJECT_DIRECTORY to handle this. We set GIT_OBJECT_DIRECTORY based on the gvfs.sharedCache config, but we also need the checks in pack_loose() to look at that object directory instead of the current ODB's. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent 4558673 commit 31b8dee

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

builtin/gc.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,18 +999,23 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
999999
return ++(d->count) > d->batch_size;
10001000
}
10011001

1002+
static const char *object_dir = NULL;
1003+
10021004
static int pack_loose(struct maintenance_run_opts *opts)
10031005
{
10041006
struct repository *r = the_repository;
10051007
int result = 0;
10061008
struct write_loose_object_data data;
10071009
struct child_process pack_proc = CHILD_PROCESS_INIT;
10081010

1011+
if (!object_dir)
1012+
object_dir = r->objects->odb->path;
1013+
10091014
/*
10101015
* Do not start pack-objects process
10111016
* if there are no loose objects.
10121017
*/
1013-
if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1018+
if (!for_each_loose_file_in_objdir(object_dir,
10141019
bail_on_loose,
10151020
NULL, NULL, NULL))
10161021
return 0;
@@ -1020,7 +1025,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
10201025
strvec_push(&pack_proc.args, "pack-objects");
10211026
if (opts->quiet)
10221027
strvec_push(&pack_proc.args, "--quiet");
1023-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1028+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
10241029

10251030
pack_proc.in = -1;
10261031

@@ -1033,7 +1038,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
10331038
data.count = 0;
10341039
data.batch_size = 50000;
10351040

1036-
for_each_loose_file_in_objdir(r->objects->odb->path,
1041+
for_each_loose_file_in_objdir(object_dir,
10371042
write_loose_object_to_stdin,
10381043
NULL,
10391044
NULL,
@@ -1441,6 +1446,16 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14411446
if (argc != 0)
14421447
usage_with_options(builtin_maintenance_run_usage,
14431448
builtin_maintenance_run_options);
1449+
1450+
/*
1451+
* To enable the VFS for Git/Scalar shared object cache, use
1452+
* the gvfs.sharedcache config option to redirect the
1453+
* maintenance to that location.
1454+
*/
1455+
if (!git_config_get_value("gvfs.sharedcache", &object_dir) &&
1456+
object_dir)
1457+
setenv(DB_ENVIRONMENT, object_dir, 1);
1458+
14441459
return maintenance_run_tasks(&opts);
14451460
}
14461461

0 commit comments

Comments
 (0)