Skip to content

Commit fbe9e66

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 1e672b4 commit fbe9e66

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

builtin/gc.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,18 +1006,23 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
10061006
return ++(d->count) > d->batch_size;
10071007
}
10081008

1009+
static const char *object_dir = NULL;
1010+
10091011
static int pack_loose(struct maintenance_run_opts *opts)
10101012
{
10111013
struct repository *r = the_repository;
10121014
int result = 0;
10131015
struct write_loose_object_data data;
10141016
struct child_process pack_proc = CHILD_PROCESS_INIT;
10151017

1018+
if (!object_dir)
1019+
object_dir = r->objects->odb->path;
1020+
10161021
/*
10171022
* Do not start pack-objects process
10181023
* if there are no loose objects.
10191024
*/
1020-
if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1025+
if (!for_each_loose_file_in_objdir(object_dir,
10211026
bail_on_loose,
10221027
NULL, NULL, NULL))
10231028
return 0;
@@ -1027,7 +1032,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
10271032
strvec_push(&pack_proc.args, "pack-objects");
10281033
if (opts->quiet)
10291034
strvec_push(&pack_proc.args, "--quiet");
1030-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1035+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
10311036

10321037
pack_proc.in = -1;
10331038

@@ -1040,7 +1045,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
10401045
data.count = 0;
10411046
data.batch_size = 50000;
10421047

1043-
for_each_loose_file_in_objdir(r->objects->odb->path,
1048+
for_each_loose_file_in_objdir(object_dir,
10441049
write_loose_object_to_stdin,
10451050
NULL,
10461051
NULL,
@@ -1418,6 +1423,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14181423
{
14191424
int i;
14201425
struct maintenance_run_opts opts;
1426+
const char *tmp_obj_dir = NULL;
14211427
struct option builtin_maintenance_run_options[] = {
14221428
OPT_BOOL(0, "auto", &opts.auto_flag,
14231429
N_("run tasks based on the state of the repository")),
@@ -1451,6 +1457,18 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14511457
if (argc != 0)
14521458
usage_with_options(builtin_maintenance_run_usage,
14531459
builtin_maintenance_run_options);
1460+
1461+
/*
1462+
* To enable the VFS for Git/Scalar shared object cache, use
1463+
* the gvfs.sharedcache config option to redirect the
1464+
* maintenance to that location.
1465+
*/
1466+
if (!git_config_get_value("gvfs.sharedcache", &tmp_obj_dir) &&
1467+
tmp_obj_dir) {
1468+
object_dir = xstrdup(tmp_obj_dir);
1469+
setenv(DB_ENVIRONMENT, object_dir, 1);
1470+
}
1471+
14541472
return maintenance_run_tasks(&opts);
14551473
}
14561474

0 commit comments

Comments
 (0)