aboutsummaryrefslogtreecommitdiff
path: root/builtin-gc.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-04-19 21:12:24 -0700
committerJunio C Hamano <gitster@pobox.com>2008-04-19 21:12:24 -0700
commita2fa254bd24c6f21c66869fc74b56b0aa1719851 (patch)
tree8de45d648286825d2fca04fcc0c2c9ac343b112a /builtin-gc.c
parent3642617ee7359eed5e108fea48981841591142bf (diff)
parentf949844263e866774063511c4538b96068dd8d1b (diff)
downloadgit-a2fa254bd24c6f21c66869fc74b56b0aa1719851.tar.gz
git-a2fa254bd24c6f21c66869fc74b56b0aa1719851.tar.xz
Merge branch 'mv/defer-gc'
* mv/defer-gc: contrib/hooks: add an example pre-auto-gc hook Documentation/hooks: add pre-auto-gc hook git-gc --auto: add pre-auto-gc hook
Diffstat (limited to 'builtin-gc.c')
-rw-r--r--builtin-gc.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/builtin-gc.c b/builtin-gc.c
index 8cef36f6a..f99ebc792 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -157,6 +157,34 @@ static int too_many_packs(void)
return gc_auto_pack_limit <= cnt;
}
+static int run_hook(void)
+{
+ const char *argv[2];
+ struct child_process hook;
+ int ret;
+
+ argv[0] = git_path("hooks/pre-auto-gc");
+ argv[1] = NULL;
+
+ if (access(argv[0], X_OK) < 0)
+ return 0;
+
+ memset(&hook, 0, sizeof(hook));
+ hook.argv = argv;
+ hook.no_stdin = 1;
+ hook.stdout_to_stderr = 1;
+
+ ret = start_command(&hook);
+ if (ret) {
+ warning("Could not spawn %s", argv[0]);
+ return ret;
+ }
+ ret = finish_command(&hook);
+ if (ret == -ERR_RUN_COMMAND_WAITPID_SIGNAL)
+ warning("%s exited due to uncaught signal", argv[0]);
+ return ret;
+}
+
static int need_to_gc(void)
{
/*
@@ -176,6 +204,9 @@ static int need_to_gc(void)
append_option(argv_repack, "-A", MAX_ADD);
else if (!too_many_loose_objects())
return 0;
+
+ if (run_hook())
+ return 0;
return 1;
}