Skip to content

Commit f4ff669

Browse files
derrickstoleemjcheetham
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 8ccbead + 5b25536 commit f4ff669

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
@@ -1168,18 +1168,25 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
11681168
return ++(d->count) > d->batch_size;
11691169
}
11701170

1171+
static const char *shared_object_dir = NULL;
1172+
11711173
static int pack_loose(struct maintenance_run_opts *opts)
11721174
{
11731175
struct repository *r = the_repository;
11741176
int result = 0;
11751177
struct write_loose_object_data data;
11761178
struct child_process pack_proc = CHILD_PROCESS_INIT;
1179+
const char *object_dir = r->objects->odb->path;
1180+
1181+
/* If set, use the shared object directory. */
1182+
if (shared_object_dir)
1183+
object_dir = shared_object_dir;
11771184

11781185
/*
11791186
* Do not start pack-objects process
11801187
* if there are no loose objects.
11811188
*/
1182-
if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1189+
if (!for_each_loose_file_in_objdir(object_dir,
11831190
bail_on_loose,
11841191
NULL, NULL, NULL))
11851192
return 0;
@@ -1189,7 +1196,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
11891196
strvec_push(&pack_proc.args, "pack-objects");
11901197
if (opts->quiet)
11911198
strvec_push(&pack_proc.args, "--quiet");
1192-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1199+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
11931200

11941201
pack_proc.in = -1;
11951202

@@ -1208,7 +1215,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
12081215
data.count = 0;
12091216
data.batch_size = 50000;
12101217

1211-
for_each_loose_file_in_objdir(r->objects->odb->path,
1218+
for_each_loose_file_in_objdir(object_dir,
12121219
write_loose_object_to_stdin,
12131220
NULL,
12141221
NULL,
@@ -1598,6 +1605,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
15981605
int i;
15991606
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
16001607
struct gc_config cfg = GC_CONFIG_INIT;
1608+
const char *tmp_obj_dir = NULL;
16011609
struct option builtin_maintenance_run_options[] = {
16021610
OPT_BOOL(0, "auto", &opts.auto_flag,
16031611
N_("run tasks based on the state of the repository")),
@@ -1635,6 +1643,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
16351643
usage_with_options(builtin_maintenance_run_usage,
16361644
builtin_maintenance_run_options);
16371645

1646+
/*
1647+
* To enable the VFS for Git/Scalar shared object cache, use
1648+
* the gvfs.sharedcache config option to redirect the
1649+
* maintenance to that location.
1650+
*/
1651+
if (!git_config_get_value("gvfs.sharedcache", &tmp_obj_dir) &&
1652+
tmp_obj_dir) {
1653+
shared_object_dir = xstrdup(tmp_obj_dir);
1654+
setenv(DB_ENVIRONMENT, shared_object_dir, 1);
1655+
}
1656+
16381657
ret = maintenance_run_tasks(&opts, &cfg);
16391658
gc_config_release(&cfg);
16401659
return ret;

0 commit comments

Comments
 (0)