Skip to content

Commit 9150f1d

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 ace2e25 commit 9150f1d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

builtin/gc.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,18 +1301,25 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
13011301
return ++(d->count) > d->batch_size;
13021302
}
13031303

1304+
static const char *shared_object_dir = NULL;
1305+
13041306
static int pack_loose(struct maintenance_run_opts *opts)
13051307
{
13061308
struct repository *r = the_repository;
13071309
int result = 0;
13081310
struct write_loose_object_data data;
13091311
struct child_process pack_proc = CHILD_PROCESS_INIT;
1312+
const char *object_dir = r->objects->odb->path;
1313+
1314+
/* If set, use the shared object directory. */
1315+
if (shared_object_dir)
1316+
object_dir = shared_object_dir;
13101317

13111318
/*
13121319
* Do not start pack-objects process
13131320
* if there are no loose objects.
13141321
*/
1315-
if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1322+
if (!for_each_loose_file_in_objdir(object_dir,
13161323
bail_on_loose,
13171324
NULL, NULL, NULL))
13181325
return 0;
@@ -1324,7 +1331,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
13241331
strvec_push(&pack_proc.args, "--quiet");
13251332
else
13261333
strvec_push(&pack_proc.args, "--no-quiet");
1327-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1334+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
13281335

13291336
pack_proc.in = -1;
13301337

@@ -1352,7 +1359,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
13521359
else if (data.batch_size > 0)
13531360
data.batch_size--; /* Decrease for equality on limit. */
13541361

1355-
for_each_loose_file_in_objdir(r->objects->odb->path,
1362+
for_each_loose_file_in_objdir(object_dir,
13561363
write_loose_object_to_stdin,
13571364
NULL,
13581365
NULL,
@@ -1766,6 +1773,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
17661773
int i;
17671774
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
17681775
struct gc_config cfg = GC_CONFIG_INIT;
1776+
const char *tmp_obj_dir = NULL;
17691777
struct option builtin_maintenance_run_options[] = {
17701778
OPT_BOOL(0, "auto", &opts.auto_flag,
17711779
N_("run tasks based on the state of the repository")),
@@ -1803,6 +1811,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
18031811
usage_with_options(builtin_maintenance_run_usage,
18041812
builtin_maintenance_run_options);
18051813

1814+
/*
1815+
* To enable the VFS for Git/Scalar shared object cache, use
1816+
* the gvfs.sharedcache config option to redirect the
1817+
* maintenance to that location.
1818+
*/
1819+
if (!git_config_get_value("gvfs.sharedcache", &tmp_obj_dir) &&
1820+
tmp_obj_dir) {
1821+
shared_object_dir = xstrdup(tmp_obj_dir);
1822+
setenv(DB_ENVIRONMENT, shared_object_dir, 1);
1823+
}
1824+
18061825
ret = maintenance_run_tasks(&opts, &cfg);
18071826
gc_config_release(&cfg);
18081827
return ret;

0 commit comments

Comments
 (0)