Skip to content

Commit 82c6b97

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 59f87c6 commit 82c6b97

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
@@ -1030,18 +1030,23 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
10301030
return ++(d->count) > d->batch_size;
10311031
}
10321032

1033+
static const char *object_dir = NULL;
1034+
10331035
static int pack_loose(struct maintenance_run_opts *opts)
10341036
{
10351037
struct repository *r = the_repository;
10361038
int result = 0;
10371039
struct write_loose_object_data data;
10381040
struct child_process pack_proc = CHILD_PROCESS_INIT;
10391041

1042+
if (!object_dir)
1043+
object_dir = r->objects->odb->path;
1044+
10401045
/*
10411046
* Do not start pack-objects process
10421047
* if there are no loose objects.
10431048
*/
1044-
if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1049+
if (!for_each_loose_file_in_objdir(object_dir,
10451050
bail_on_loose,
10461051
NULL, NULL, NULL))
10471052
return 0;
@@ -1051,7 +1056,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
10511056
strvec_push(&pack_proc.args, "pack-objects");
10521057
if (opts->quiet)
10531058
strvec_push(&pack_proc.args, "--quiet");
1054-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1059+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
10551060

10561061
pack_proc.in = -1;
10571062

@@ -1064,7 +1069,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
10641069
data.count = 0;
10651070
data.batch_size = 50000;
10661071

1067-
for_each_loose_file_in_objdir(r->objects->odb->path,
1072+
for_each_loose_file_in_objdir(object_dir,
10681073
write_loose_object_to_stdin,
10691074
NULL,
10701075
NULL,
@@ -1442,6 +1447,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14421447
{
14431448
int i;
14441449
struct maintenance_run_opts opts;
1450+
const char *tmp_obj_dir = NULL;
14451451
struct option builtin_maintenance_run_options[] = {
14461452
OPT_BOOL(0, "auto", &opts.auto_flag,
14471453
N_("run tasks based on the state of the repository")),
@@ -1475,6 +1481,18 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
14751481
if (argc != 0)
14761482
usage_with_options(builtin_maintenance_run_usage,
14771483
builtin_maintenance_run_options);
1484+
1485+
/*
1486+
* To enable the VFS for Git/Scalar shared object cache, use
1487+
* the gvfs.sharedcache config option to redirect the
1488+
* maintenance to that location.
1489+
*/
1490+
if (!git_config_get_value("gvfs.sharedcache", &tmp_obj_dir) &&
1491+
tmp_obj_dir) {
1492+
object_dir = xstrdup(tmp_obj_dir);
1493+
setenv(DB_ENVIRONMENT, object_dir, 1);
1494+
}
1495+
14781496
return maintenance_run_tasks(&opts);
14791497
}
14801498

0 commit comments

Comments
 (0)