aboutsummaryrefslogtreecommitdiff
path: root/builtin-gc.c
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@frugalware.org>2008-04-02 21:34:38 +0200
committerJunio C Hamano <gitster@pobox.com>2008-04-09 01:31:13 -0700
commitbde30540169dd625cbd862ff6f38bc8224ec081c (patch)
tree8fa0474ce4e5913451fc8b4aa0c1638f83fe4c04 /builtin-gc.c
parent1d2375ddfee18bd3effd2c1f98527cc2f8b1df0a (diff)
downloadgit-bde30540169dd625cbd862ff6f38bc8224ec081c.tar.gz
git-bde30540169dd625cbd862ff6f38bc8224ec081c.tar.xz
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 <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
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;
}