Skip to content

Commit 46e56e4

Browse files
derrickstoleedscho
authored andcommitted
Merge pull request #301: Update 'git maintenance' to match upstream
This PR updates our `vfs-2.29.0` branch's version of `git maintenance` to match the latest in upstream. Unfortunately, not all of these commits made it to the `2.30` release candidate, but there are more commits from the series making it in. They will cause a conflict in the `vfs-2.30.0` rebase, so merge them in here. This also includes the `fixup!` reverts of the earlier versions. Finally, I also noticed that we started depending on `git maintenance start` in Scalar for macOS, but we never checked that this worked with the shared object cache. It doesn't! 😨 The very tip commit of this PR includes logic to make `git maintenance run` care about `gvfs.sharedCache`. Functional test updates in Scalar will follow.
2 parents 5dc2e19 + b3eec39 commit 46e56e4

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

builtin/gc.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,18 +1338,25 @@ 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
13501357
* if there are no loose objects.
13511358
*/
1352-
if (!for_each_loose_file_in_objdir(r->objects->sources->path,
1359+
if (!for_each_loose_file_in_objdir(object_dir,
13531360
bail_on_loose,
13541361
NULL, NULL, NULL))
13551362
return 0;
@@ -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

@@ -1389,7 +1396,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
13891396
else if (data.batch_size > 0)
13901397
data.batch_size--; /* Decrease for equality on limit. */
13911398

1392-
for_each_loose_file_in_objdir(r->objects->sources->path,
1399+
for_each_loose_file_in_objdir(object_dir,
13931400
write_loose_object_to_stdin,
13941401
NULL,
13951402
NULL,
@@ -1834,11 +1841,12 @@ static int task_option_parse(const struct option *opt,
18341841
}
18351842

18361843
static int maintenance_run(int argc, const char **argv, const char *prefix,
1837-
struct repository *repo UNUSED)
1844+
struct repository *repo)
18381845
{
18391846
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
18401847
struct string_list selected_tasks = STRING_LIST_INIT_DUP;
18411848
struct gc_config cfg = GC_CONFIG_INIT;
1849+
const char *tmp_obj_dir = NULL;
18421850
struct option builtin_maintenance_run_options[] = {
18431851
OPT_BOOL(0, "auto", &opts.auto_flag,
18441852
N_("run tasks based on the state of the repository")),
@@ -1875,6 +1883,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
18751883
usage_with_options(builtin_maintenance_run_usage,
18761884
builtin_maintenance_run_options);
18771885

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

18801899
string_list_clear(&selected_tasks, 0);

0 commit comments

Comments
 (0)