From b86ed822ff20752307a33ff1ae2159ac5b9ba554 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 1 Aug 2026 22:15:37 -1000 Subject: Rewrite the agefile hook for reliability --- custom/hooks/post-receive.agefile | 31 +++++++++++++++++++++++++------ 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" -- cgit v2.8.0