From 28d04e1ec19777bf6382d016b6e624d0ff4336cd Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 9 Sep 2021 09:47:06 +0000 Subject: run-command: offer to close the object store before running Especially on Windows, where files cannot be deleted if _any_ process holds an open file handle to them, it is important to close the object store (releasing all handles to all `.pack` files) before running a command that might spawn a garbage collection. This scenario is so common that we frequently see the pattern of closing the object store before running auto maintenance or another Git command. Let's make this much more convenient by teaching the `run_command()` machinery a new flag to release the object store before spawning the process. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- run-command.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'run-command.c') diff --git a/run-command.c b/run-command.c index f72e72cce7..e2dc624377 100644 --- a/run-command.c +++ b/run-command.c @@ -8,6 +8,7 @@ #include "string-list.h" #include "quote.h" #include "config.h" +#include "packfile.h" void child_process_init(struct child_process *child) { @@ -740,6 +741,9 @@ fail_pipe: fflush(NULL); + if (cmd->close_object_store) + close_object_store(the_repository->objects); + #ifndef GIT_WINDOWS_NATIVE { int notify_pipe[2]; @@ -1044,6 +1048,7 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, cmd.use_shell = opt & RUN_USING_SHELL ? 1 : 0; cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0; cmd.wait_after_clean = opt & RUN_WAIT_AFTER_CLEAN ? 1 : 0; + cmd.close_object_store = opt & RUN_CLOSE_OBJECT_STORE ? 1 : 0; cmd.dir = dir; cmd.env = env; cmd.trace2_child_class = tr2_class; -- cgit v1.2.3 From 5a22a334cb757753230f1d73da36130513016830 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 9 Sep 2021 09:47:07 +0000 Subject: run_auto_maintenance(): implicitly close the object store Before spawning the auto maintenance, we need to make sure that we release all open file handles to all the `.pack` files (and MIDX files and commit-graph files and...) so that the maintenance process has the freedom to delete those files. So far, we did this manually every time before calling `run_auto_maintenance()`. With the new `close_object_store` flag, we can do that implicitly in that function, which is more robust because future callers won't be able to forget to close the object store. Note: this changes behavior slightly, as we previously _always_ closed the object store, but now we only close the object store when actually running the auto maintenance. In practice, this should not matter (if anything, it might speed up operations where auto maintenance is disabled). Suggested-by: Junio C Hamano Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- run-command.c | 1 + 1 file changed, 1 insertion(+) (limited to 'run-command.c') diff --git a/run-command.c b/run-command.c index e2dc624377..229bdff997 100644 --- a/run-command.c +++ b/run-command.c @@ -1891,6 +1891,7 @@ int run_auto_maintenance(int quiet) return 0; maint.git_cmd = 1; + maint.close_object_store = 1; strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL); strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet"); -- cgit v1.2.3