Skip to content

Commit c042ad5

Browse files
committed
Merge branch 'js/run-command-close-packs'
The run-command API has been updated so that the callers can easily ask the file descriptors open for packfiles to be closed immediately before spawning commands that may trigger auto-gc. * js/run-command-close-packs: Close object store closer to spawning child processes run_auto_maintenance(): implicitly close the object store run-command: offer to close the object store before running run-command: prettify the `RUN_COMMAND_*` flags pull: release packs before fetching commit-graph: when closing the graph, also release the slab
2 parents a16dd13 + c4dee2c commit c042ad5

File tree

10 files changed

+32
-27
lines changed

10 files changed

+32
-27
lines changed

builtin/am.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,6 @@ static void am_run(struct am_state *state, int resume)
18481848
*/
18491849
if (!state->rebasing) {
18501850
am_destroy(state);
1851-
close_object_store(the_repository->objects);
18521851
run_auto_maintenance(state->quiet);
18531852
}
18541853
}

builtin/fetch.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,8 +2148,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
21482148
NULL);
21492149
}
21502150

2151-
close_object_store(the_repository->objects);
2152-
21532151
if (enable_auto_gc)
21542152
run_auto_maintenance(verbosity < 0);
21552153

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/merge.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ static void finish(struct commit *head_commit,
469469
* We ignore errors in 'gc --auto', since the
470470
* user should see them.
471471
*/
472-
close_object_store(the_repository->objects);
473472
run_auto_maintenance(verbosity < 0);
474473
}
475474
}

builtin/pull.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "wt-status.h"
2727
#include "commit-reach.h"
2828
#include "sequencer.h"
29+
#include "packfile.h"
2930

3031
/**
3132
* Parses the value of --rebase. If value is a false value, returns
@@ -577,7 +578,7 @@ static int run_fetch(const char *repo, const char **refspecs)
577578
strvec_pushv(&args, refspecs);
578579
} else if (*refspecs)
579580
BUG("refspecs without repo?");
580-
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);
581582
strvec_clear(&args);
582583
return ret;
583584
}

builtin/rebase.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ static int finish_rebase(struct rebase_options *opts)
744744
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
745745
unlink(git_path_auto_merge(the_repository));
746746
apply_autostash(state_dir_path("autostash", opts));
747-
close_object_store(the_repository->objects);
748747
/*
749748
* We ignore errors in 'git maintenance run --auto', since the
750749
* user should see them.

builtin/receive-pack.c

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

2584-
close_object_store(the_repository->objects);
25852584
if (!start_command(&proc)) {
25862585
if (use_sideband)
25872586
copy_to_sideband(proc.err, -1, NULL);

commit-graph.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ static void close_commit_graph_one(struct commit_graph *g)
713713
if (!g)
714714
return;
715715

716+
clear_commit_graph_data_slab(&commit_graph_data_slab);
716717
close_commit_graph_one(g->base_graph);
717718
free_commit_graph(g);
718719
}

run-command.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "string-list.h"
99
#include "quote.h"
1010
#include "config.h"
11+
#include "packfile.h"
1112

1213
void child_process_init(struct child_process *child)
1314
{
@@ -740,6 +741,9 @@ int start_command(struct child_process *cmd)
740741

741742
fflush(NULL);
742743

744+
if (cmd->close_object_store)
745+
close_object_store(the_repository->objects);
746+
743747
#ifndef GIT_WINDOWS_NATIVE
744748
{
745749
int notify_pipe[2];
@@ -1042,6 +1046,7 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir,
10421046
cmd.use_shell = opt & RUN_USING_SHELL ? 1 : 0;
10431047
cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0;
10441048
cmd.wait_after_clean = opt & RUN_WAIT_AFTER_CLEAN ? 1 : 0;
1049+
cmd.close_object_store = opt & RUN_CLOSE_OBJECT_STORE ? 1 : 0;
10451050
cmd.dir = dir;
10461051
cmd.env = env;
10471052
cmd.trace2_child_class = tr2_class;
@@ -1884,6 +1889,7 @@ int run_auto_maintenance(int quiet)
18841889
return 0;
18851890

18861891
maint.git_cmd = 1;
1892+
maint.close_object_store = 1;
18871893
strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
18881894
strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
18891895

run-command.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ struct child_process {
134134
*/
135135
unsigned use_shell:1;
136136

137+
/**
138+
* Release any open file handles to the object store before running
139+
* the command; This is necessary e.g. when the spawned process may
140+
* want to repack because that would delete `.pack` files (and on
141+
* Windows, you cannot delete files that are still in use).
142+
*/
143+
unsigned close_object_store:1;
144+
137145
unsigned stdout_to_stderr:1;
138146
unsigned clean_on_exit:1;
139147
unsigned wait_after_clean:1;
@@ -233,13 +241,14 @@ int run_hook_ve(const char *const *env, const char *name, va_list args);
233241
*/
234242
int run_auto_maintenance(int quiet);
235243

236-
#define RUN_COMMAND_NO_STDIN 1
237-
#define RUN_GIT_CMD 2 /*If this is to be git sub-command */
238-
#define RUN_COMMAND_STDOUT_TO_STDERR 4
239-
#define RUN_SILENT_EXEC_FAILURE 8
240-
#define RUN_USING_SHELL 16
241-
#define RUN_CLEAN_ON_EXIT 32
242-
#define RUN_WAIT_AFTER_CLEAN 64
244+
#define RUN_COMMAND_NO_STDIN (1<<0)
245+
#define RUN_GIT_CMD (1<<1)
246+
#define RUN_COMMAND_STDOUT_TO_STDERR (1<<2)
247+
#define RUN_SILENT_EXEC_FAILURE (1<<3)
248+
#define RUN_USING_SHELL (1<<4)
249+
#define RUN_CLEAN_ON_EXIT (1<<5)
250+
#define RUN_WAIT_AFTER_CLEAN (1<<6)
251+
#define RUN_CLOSE_OBJECT_STORE (1<<7)
243252

244253
/**
245254
* Convenience functions that encapsulate a sequence of

0 commit comments

Comments
 (0)