diff options
context:
space:
mode:
Diffstat (limited to 'custom')
-rwxr-xr-xcustom/hooks/post-receive.cgit-cache38
1 file changed, 38 insertions, 0 deletions
diff --git a/custom/hooks/post-receive.cgit-cache b/custom/hooks/post-receive.cgit-cache
new file mode 100755
index 0000000..484bac0
--- /dev/null
+++ b/custom/hooks/post-receive.cgit-cache
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# Example hook that drops cgit's output cache after a push, so new commits
+# show up right away instead of once the cache-*-ttl minutes have passed.
+#
+# This only matters when cache-size in your cgitrc is above 0, which turns
+# the cache on. With it off the hook does nothing and costs one stat call.
+#
+# cgit names each cache slot after a hash of the request url, so there is no
+# way to expire one repository's pages on their own and this clears the lot.
+# cgit refills a slot the next time something asks for it. The cached
+# repository scan goes too, which is what makes a brand new repository appear
+# without waiting out cache-scanrc-ttl.
+#
+# This hook assumes the default cache-root of "/var/cache/cgit". If you
+# change the value in your cgitrc then you must also change it here.
+#
+# The web server owns the cache root, so the pushing user needs write access
+# to it. Making the directory group writable and putting both users in that
+# group is usually enough. Nothing here fails a push if that access is
+# missing, since a stale page is not worth rejecting a push over.
+#
+# To install the hook, copy (or link) it to the file "hooks/post-receive" in
+# each of your repositories. Git runs one post-receive per repository, so
+# fold this together with the agefile hook if you want both.
+#
+
+set -eu
+
+cache_root=/var/cache/cgit
+
+[ -d "$cache_root" ] || exit 0
+
+# Everything directly under the cache root is a cache file, so the only thing
+# worth keeping is the lock files, which belong to writers still working.
+# The "! -name . -prune" pair is how POSIX find stays out of subdirectories.
+find "$cache_root"/. ! -name . -prune \
+ ! -name '*.lock' -type f -exec rm -f {} + || exit 0