Skip to content

Commit c4dee2c

Browse files
dschogitster
authored andcommitted
Close object store closer to spawning child processes
In many cases where we spawned child processes that _may_ trigger a repack, we explicitly closed the object store first (so that the `repack` process can delete the `.pack` files, which would otherwise not be possible on Windows since files cannot be deleted as long as they as still in use). Wherever possible, we now use the new `close_object_store` bit of the `run_command()` API, to delay closing the object store even further. This makes the code easier to maintain because it is now more obvious that we only release those file handles because of those child processes. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a22a33 commit c4dee2c

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

builtin/gc.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
663663
gc_before_repack();
664664

665665
if (!repository_format_precious_objects) {
666-
close_object_store(the_repository->objects);
667-
if (run_command_v_opt(repack.v, RUN_GIT_CMD))
666+
if (run_command_v_opt(repack.v,
667+
RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE))
668668
die(FAILED_RUN, repack.v[0]);
669669

670670
if (prune_expire) {
@@ -848,7 +848,7 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
848848
{
849849
struct child_process child = CHILD_PROCESS_INIT;
850850

851-
child.git_cmd = 1;
851+
child.git_cmd = child.close_object_store = 1;
852852
strvec_pushl(&child.args, "commit-graph", "write",
853853
"--split", "--reachable", NULL);
854854

@@ -864,7 +864,6 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
864864
if (!the_repository->settings.core_commit_graph)
865865
return 0;
866866

867-
close_object_store(the_repository->objects);
868867
if (run_write_commit_graph(opts)) {
869868
error(_("failed to write commit-graph"));
870869
return 1;
@@ -913,7 +912,7 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
913912
{
914913
struct child_process child = CHILD_PROCESS_INIT;
915914

916-
child.git_cmd = 1;
915+
child.git_cmd = child.close_object_store = 1;
917916
strvec_push(&child.args, "gc");
918917

919918
if (opts->auto_flag)
@@ -923,7 +922,6 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
923922
else
924923
strvec_push(&child.args, "--no-quiet");
925924

926-
close_object_store(the_repository->objects);
927925
return run_command(&child);
928926
}
929927

@@ -1097,14 +1095,12 @@ static int multi_pack_index_expire(struct maintenance_run_opts *opts)
10971095
{
10981096
struct child_process child = CHILD_PROCESS_INIT;
10991097

1100-
child.git_cmd = 1;
1098+
child.git_cmd = child.close_object_store = 1;
11011099
strvec_pushl(&child.args, "multi-pack-index", "expire", NULL);
11021100

11031101
if (opts->quiet)
11041102
strvec_push(&child.args, "--no-progress");
11051103

1106-
close_object_store(the_repository->objects);
1107-
11081104
if (run_command(&child))
11091105
return error(_("'git multi-pack-index expire' failed"));
11101106

@@ -1155,7 +1151,7 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
11551151
{
11561152
struct child_process child = CHILD_PROCESS_INIT;
11571153

1158-
child.git_cmd = 1;
1154+
child.git_cmd = child.close_object_store = 1;
11591155
strvec_pushl(&child.args, "multi-pack-index", "repack", NULL);
11601156

11611157
if (opts->quiet)
@@ -1164,8 +1160,6 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
11641160
strvec_pushf(&child.args, "--batch-size=%"PRIuMAX,
11651161
(uintmax_t)get_auto_pack_size());
11661162

1167-
close_object_store(the_repository->objects);
1168-
11691163
if (run_command(&child))
11701164
return error(_("'git multi-pack-index repack' failed"));
11711165

builtin/pull.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static int run_fetch(const char *repo, const char **refspecs)
578578
strvec_pushv(&args, refspecs);
579579
} else if (*refspecs)
580580
BUG("refspecs without repo?");
581-
ret = run_command_v_opt(args.v, RUN_GIT_CMD);
581+
ret = run_command_v_opt(args.v, RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE);
582582
strvec_clear(&args);
583583
return ret;
584584
}
@@ -999,7 +999,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
999999
oidclr(&rebase_fork_point);
10001000
}
10011001

1002-
close_object_store(the_repository->objects);
10031002
if (run_fetch(repo, refspecs))
10041003
return 1;
10051004

builtin/receive-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,10 +2580,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
25802580
proc.no_stdin = 1;
25812581
proc.stdout_to_stderr = 1;
25822582
proc.err = use_sideband ? -1 : 0;
2583-
proc.git_cmd = 1;
2583+
proc.git_cmd = proc.close_object_store = 1;
25842584
proc.argv = argv_gc_auto;
25852585

2586-
close_object_store(the_repository->objects);
25872586
if (!start_command(&proc)) {
25882587
if (use_sideband)
25892588
copy_to_sideband(proc.err, -1, NULL);

0 commit comments

Comments
 (0)