Skip to content

Commit 242f79e

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 024c8b9 + 0b64e50 commit 242f79e

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
@@ -1159,18 +1159,25 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
11591159
return ++(d->count) > d->batch_size;
11601160
}
11611161

1162+
static const char *shared_object_dir = NULL;
1163+
11621164
static int pack_loose(struct maintenance_run_opts *opts)
11631165
{
11641166
struct repository *r = the_repository;
11651167
int result = 0;
11661168
struct write_loose_object_data data;
11671169
struct child_process pack_proc = CHILD_PROCESS_INIT;
1170+
const char *object_dir = r->objects->odb->path;
1171+
1172+
/* If set, use the shared object directory. */
1173+
if (shared_object_dir)
1174+
object_dir = shared_object_dir;
11681175

11691176
/*
11701177
* Do not start pack-objects process
11711178
* if there are no loose objects.
11721179
*/
1173-
if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1180+
if (!for_each_loose_file_in_objdir(object_dir,
11741181
bail_on_loose,
11751182
NULL, NULL, NULL))
11761183
return 0;
@@ -1180,7 +1187,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
11801187
strvec_push(&pack_proc.args, "pack-objects");
11811188
if (opts->quiet)
11821189
strvec_push(&pack_proc.args, "--quiet");
1183-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1190+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
11841191

11851192
pack_proc.in = -1;
11861193

@@ -1199,7 +1206,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
11991206
data.count = 0;
12001207
data.batch_size = 50000;
12011208

1202-
for_each_loose_file_in_objdir(r->objects->odb->path,
1209+
for_each_loose_file_in_objdir(object_dir,
12031210
write_loose_object_to_stdin,
12041211
NULL,
12051212
NULL,
@@ -1589,6 +1596,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
15891596
int i;
15901597
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
15911598
struct gc_config cfg = GC_CONFIG_INIT;
1599+
const char *tmp_obj_dir = NULL;
15921600
struct option builtin_maintenance_run_options[] = {
15931601
OPT_BOOL(0, "auto", &opts.auto_flag,
15941602
N_("run tasks based on the state of the repository")),
@@ -1626,6 +1634,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
16261634
usage_with_options(builtin_maintenance_run_usage,
16271635
builtin_maintenance_run_options);
16281636

1637+
/*
1638+
* To enable the VFS for Git/Scalar shared object cache, use
1639+
* the gvfs.sharedcache config option to redirect the
1640+
* maintenance to that location.
1641+
*/
1642+
if (!git_config_get_value("gvfs.sharedcache", &tmp_obj_dir) &&
1643+
tmp_obj_dir) {
1644+
shared_object_dir = xstrdup(tmp_obj_dir);
1645+
setenv(DB_ENVIRONMENT, shared_object_dir, 1);
1646+
}
1647+
16291648
ret = maintenance_run_tasks(&opts, &cfg);
16301649
gc_config_release(&cfg);
16311650
return ret;

0 commit comments

Comments
 (0)