diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Rewrite the agefile hook for reliability
Diffstat (limited to 'custom/hooks')
-rwxr-xr-xcustom/hooks/post-receive.agefile31
1 file changed, 25 insertions, 6 deletions
diff --git a/custom/hooks/post-receive.agefile b/custom/hooks/post-receive.agefile
index 2f72ae9..80c67c2 100755
--- a/custom/hooks/post-receive.agefile
+++ b/custom/hooks/post-receive.agefile
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# An example hook to update the "agefile" for CGit's idle time calculation.
+# Example hook that updates the "agefile" cgit reads for the idle column.
#
# 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
@@ -10,10 +10,29 @@
# each of your repositories.
#
+set -eu
+
+# The pushing user's umask decides the mode of a freshly written agefile, so
+# force one that leaves the file readable by the web server.
+umask 022
+
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"
+# Committer dates rather than author dates, so a push of rebased or imported
+# history still counts as recent activity. Branch tips only, since an
+# annotated tag carries no committer date of its own and would sort in as an
+# empty line.
+date="$(git for-each-ref --sort=-committerdate --count=1 \
+ --format='%(committerdate:iso8601)' refs/heads/)"
+
+# A repository with no branches keeps whatever cgit already had, rather than
+# being handed an empty file.
+[ -n "$date" ] || exit 0
+
+mkdir -p "$(dirname "$agefile")"
+
+# Write through a temporary file so a reader never sees a half written date.
+tmpfile="$agefile.$$"
+trap 'rm -f "$tmpfile"' EXIT
+printf '%s\n' "$date" >"$tmpfile"
+mv "$tmpfile" "$agefile"