Skip to content

Commit 76d928d

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 <[email protected]>
1 parent b0abdb1 commit 76d928d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

builtin/gc.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,12 +1338,19 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
13381338
return ++(d->count) > d->batch_size;
13391339
}
13401340

1341+
static const char *shared_object_dir = NULL;
1342+
13411343
static int pack_loose(struct maintenance_run_opts *opts)
13421344
{
13431345
struct repository *r = the_repository;
13441346
int result = 0;
13451347
struct write_loose_object_data data;
13461348
struct child_process pack_proc = CHILD_PROCESS_INIT;
1349+
const char *object_dir = r->objects->sources->path;
1350+
1351+
/* If set, use the shared object directory. */
1352+
if (shared_object_dir)
1353+
object_dir = shared_object_dir;
13471354

13481355
/*
13491356
* Do not start pack-objects process
@@ -1361,7 +1368,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
13611368
strvec_push(&pack_proc.args, "--quiet");
13621369
else
13631370
strvec_push(&pack_proc.args, "--no-quiet");
1364-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->sources->path);
1371+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
13651372

13661373
pack_proc.in = -1;
13671374

@@ -1832,11 +1839,12 @@ static int task_option_parse(const struct option *opt,
18321839
}
18331840

18341841
static int maintenance_run(int argc, const char **argv, const char *prefix,
1835-
struct repository *repo UNUSED)
1842+
struct repository *repo)
18361843
{
18371844
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
18381845
struct string_list selected_tasks = STRING_LIST_INIT_DUP;
18391846
struct gc_config cfg = GC_CONFIG_INIT;
1847+
const char *tmp_obj_dir = NULL;
18401848
struct option builtin_maintenance_run_options[] = {
18411849
OPT_BOOL(0, "auto", &opts.auto_flag,
18421850
N_("run tasks based on the state of the repository")),
@@ -1873,6 +1881,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
18731881
usage_with_options(builtin_maintenance_run_usage,
18741882
builtin_maintenance_run_options);
18751883

1884+
/*
1885+
* To enable the VFS for Git/Scalar shared object cache, use
1886+
* the gvfs.sharedcache config option to redirect the
1887+
* maintenance to that location.
1888+
*/
1889+
if (!repo_config_get_value(repo, "gvfs.sharedcache", &tmp_obj_dir) &&
1890+
tmp_obj_dir) {
1891+
shared_object_dir = xstrdup(tmp_obj_dir);
1892+
setenv(DB_ENVIRONMENT, shared_object_dir, 1);
1893+
}
1894+
18761895
ret = maintenance_run_tasks(&opts, &cfg);
18771896

18781897
string_list_clear(&selected_tasks, 0);

0 commit comments

Comments
 (0)