Skip to content

Commit bde3054

Browse files
Miklos Vajnagitster
authored andcommitted
git-gc --auto: add pre-auto-gc hook
If such a hook is available and exits with a non-zero status, then git-gc --auto won't run. Signed-off-by: Miklos Vajna <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d2375d commit bde3054

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

builtin-gc.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,34 @@ static int too_many_packs(void)
157157
return gc_auto_pack_limit <= cnt;
158158
}
159159

160+
static int run_hook(void)
161+
{
162+
const char *argv[2];
163+
struct child_process hook;
164+
int ret;
165+
166+
argv[0] = git_path("hooks/pre-auto-gc");
167+
argv[1] = NULL;
168+
169+
if (access(argv[0], X_OK) < 0)
170+
return 0;
171+
172+
memset(&hook, 0, sizeof(hook));
173+
hook.argv = argv;
174+
hook.no_stdin = 1;
175+
hook.stdout_to_stderr = 1;
176+
177+
ret = start_command(&hook);
178+
if (ret) {
179+
warning("Could not spawn %s", argv[0]);
180+
return ret;
181+
}
182+
ret = finish_command(&hook);
183+
if (ret == -ERR_RUN_COMMAND_WAITPID_SIGNAL)
184+
warning("%s exited due to uncaught signal", argv[0]);
185+
return ret;
186+
}
187+
160188
static int need_to_gc(void)
161189
{
162190
/*
@@ -176,6 +204,9 @@ static int need_to_gc(void)
176204
append_option(argv_repack, "-A", MAX_ADD);
177205
else if (!too_many_loose_objects())
178206
return 0;
207+
208+
if (run_hook())
209+
return 0;
179210
return 1;
180211
}
181212

0 commit comments

Comments
 (0)