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 <gitster@pobox.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Sep 9, 2021 at 09:47 UTC 5a22a334cb757753230f1d73da36130513016830
5 files changed +1 -5
builtin/am.c
-1
@@ -1848,7 +1848,6 @@ next:
1848 */
1849 if (!state->rebasing) {
1850 am_destroy(state);
1851 - close_object_store(the_repository->objects);
1851 run_auto_maintenance(state->quiet);
1852 }
1853 }
builtin/fetch.c
-2
@@ -2133,8 +2133,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2133 NULL);
2134 }
2135
2136 - close_object_store(the_repository->objects);
2137 -
2136 if (enable_auto_gc)
2137 run_auto_maintenance(verbosity < 0);
2138
builtin/merge.c
-1
@@ -469,7 +469,6 @@ static void finish(struct commit *head_commit,
469 * We ignore errors in 'gc --auto', since the
470 * user should see them.
471 */
472 - close_object_store(the_repository->objects);
472 run_auto_maintenance(verbosity < 0);
473 }
474 }
builtin/rebase.c
-1
@@ -740,7 +740,6 @@ static int finish_rebase(struct rebase_options *opts)
740 delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
741 unlink(git_path_auto_merge(the_repository));
742 apply_autostash(state_dir_path("autostash", opts));
743 - close_object_store(the_repository->objects);
743 /*
744 * We ignore errors in 'git maintenance run --auto', since the
745 * user should see them.
run-command.c
+1
@@ -1891,6 +1891,7 @@ int run_auto_maintenance(int quiet)
1891 return 0;
1892
1893 maint.git_cmd = 1;
1894 + maint.close_object_store = 1;
1895 strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
1896 strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
1897