cgit

commit 121e65391446069a538ae8d3f7938452178de7c6

Author: John Keeping <john@keeping.me.uk>

contrib/hooks: add sample post-receive hook using agefile

One of the most frequent questions on the mailing list relates to the
idle time in the repository list.  The answer to this is to use the
"agefile" feature to calculate the time of the last change whenever the
repository receives changes.

Add a sample post-receive hook in a new "contrib" directory so that we
can just point people at the repository in the future.

Signed-off-by: John Keeping <john@keeping.me.uk>

 contrib/hooks/post-receive.agefile | 19 +++++++++++++++++++


diff --git a/contrib/hooks/post-receive.agefile b/contrib/hooks/post-receive.agefile
new file mode 100755
index 0000000000000000000000000000000000000000..2f72ae9c0dd549d10dde3335f11dc4fa453eaf97
--- /dev/null
+++ b/contrib/hooks/post-receive.agefile
@@ -0,0 +1,19 @@
+#!/bin/sh
+#
+# An example hook to update the "agefile" for CGit's idle time calculation.
+#
+# This hook assumes that you are using the default agefile location of
+# "info/web/last-modified".  If you change the value in your cgitrc then you
+# must also change it here.
+#
+# To install the hook, copy (or link) it to the file "hooks/post-receive" in
+# each of your repositories.
+#
+
+agefile="$(git rev-parse --git-dir)"/info/web/last-modified
+
+mkdir -p "$(dirname "$agefile")" &&
+git for-each-ref \
+	--sort=-authordate --count=1 \
+	--format='%(authordate:iso8601)' \
+	>"$agefile"