Skip to content

Commit 28d04e1

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3322a9d commit 28d04e1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

run-command.c

Lines changed: 5 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];
@@ -1044,6 +1048,7 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir,
10441048
cmd.use_shell = opt & RUN_USING_SHELL ? 1 : 0;
10451049
cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0;
10461050
cmd.wait_after_clean = opt & RUN_WAIT_AFTER_CLEAN ? 1 : 0;
1051+
cmd.close_object_store = opt & RUN_CLOSE_OBJECT_STORE ? 1 : 0;
10471052
cmd.dir = dir;
10481053
cmd.env = env;
10491054
cmd.trace2_child_class = tr2_class;

run-command.h

Lines changed: 9 additions & 0 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;
@@ -240,6 +248,7 @@ int run_auto_maintenance(int quiet);
240248
#define RUN_USING_SHELL (1<<4)
241249
#define RUN_CLEAN_ON_EXIT (1<<5)
242250
#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)