Skip to content

Commit c186248

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 dc7e291 + 920d3f7 commit c186248

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
@@ -1154,18 +1154,25 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
11541154
return ++(d->count) > d->batch_size;
11551155
}
11561156

1157+
static const char *shared_object_dir = NULL;
1158+
11571159
static int pack_loose(struct maintenance_run_opts *opts)
11581160
{
11591161
struct repository *r = the_repository;
11601162
int result = 0;
11611163
struct write_loose_object_data data;
11621164
struct child_process pack_proc = CHILD_PROCESS_INIT;
1165+
const char *object_dir = r->objects->odb->path;
1166+
1167+
/* If set, use the shared object directory. */
1168+
if (shared_object_dir)
1169+
object_dir = shared_object_dir;
11631170

11641171
/*
11651172
* Do not start pack-objects process
11661173
* if there are no loose objects.
11671174
*/
1168-
if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1175+
if (!for_each_loose_file_in_objdir(object_dir,
11691176
bail_on_loose,
11701177
NULL, NULL, NULL))
11711178
return 0;
@@ -1175,7 +1182,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
11751182
strvec_push(&pack_proc.args, "pack-objects");
11761183
if (opts->quiet)
11771184
strvec_push(&pack_proc.args, "--quiet");
1178-
strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1185+
strvec_pushf(&pack_proc.args, "%s/pack/loose", object_dir);
11791186

11801187
pack_proc.in = -1;
11811188

@@ -1194,7 +1201,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
11941201
data.count = 0;
11951202
data.batch_size = 50000;
11961203

1197-
for_each_loose_file_in_objdir(r->objects->odb->path,
1204+
for_each_loose_file_in_objdir(object_dir,
11981205
write_loose_object_to_stdin,
11991206
NULL,
12001207
NULL,
@@ -1584,6 +1591,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
15841591
int i;
15851592
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
15861593
struct gc_config cfg = GC_CONFIG_INIT;
1594+
const char *tmp_obj_dir = NULL;
15871595
struct option builtin_maintenance_run_options[] = {
15881596
OPT_BOOL(0, "auto", &opts.auto_flag,
15891597
N_("run tasks based on the state of the repository")),
@@ -1621,6 +1629,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
16211629
usage_with_options(builtin_maintenance_run_usage,
16221630
builtin_maintenance_run_options);
16231631

1632+
/*
1633+
* To enable the VFS for Git/Scalar shared object cache, use
1634+
* the gvfs.sharedcache config option to redirect the
1635+
* maintenance to that location.
1636+
*/
1637+
if (!git_config_get_value("gvfs.sharedcache", &tmp_obj_dir) &&
1638+
tmp_obj_dir) {
1639+
shared_object_dir = xstrdup(tmp_obj_dir);
1640+
setenv(DB_ENVIRONMENT, shared_object_dir, 1);
1641+
}
1642+
16241643
ret = maintenance_run_tasks(&opts, &cfg);
16251644
gc_config_release(&cfg);
16261645
return ret;

0 commit comments

Comments
 (0)