]> git.ipfire.org Git - thirdparty/git.git/commitdiff
run-command: offer to close the object store before running
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 9 Sep 2021 09:47:06 +0000 (09:47 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Sep 2021 19:56:11 +0000 (12:56 -0700)
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c
run-command.h

index f72e72cce73f1a1decbdd99b098f050f37bea41f..e2dc62437745becd6046282d0c10b2d459c7b7cd 100644 (file)
@@ -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;
index 3893193f32f658bc8dce1d512bf0508d72219672..ad207daced7912c2d9b7069583f551a046278fe4 100644 (file)
@@ -134,6 +134,14 @@ struct child_process {
         */
        unsigned use_shell:1;
 
+       /**
+        * Release any open file handles to the object store before running
+        * the command; This is necessary e.g. when the spawned process may
+        * want to repack because that would delete `.pack` files (and on
+        * Windows, you cannot delete files that are still in use).
+        */
+       unsigned close_object_store:1;
+
        unsigned stdout_to_stderr:1;
        unsigned clean_on_exit:1;
        unsigned wait_after_clean:1;
@@ -240,6 +248,7 @@ int run_auto_maintenance(int quiet);
 #define RUN_USING_SHELL                        (1<<4)
 #define RUN_CLEAN_ON_EXIT              (1<<5)
 #define RUN_WAIT_AFTER_CLEAN           (1<<6)
+#define RUN_CLOSE_OBJECT_STORE         (1<<7)
 
 /**
  * Convenience functions that encapsulate a sequence of