git_infra

Git infra scripts for git.bracken.jp
git clone https://git.bracken.jp/git_infra.git
Log | Files | Refs | LICENSE

commit 98ca2d579beacf37938e1ada3895480c971de04d
parent ec7d2964bc140466b812193f2178465a7567d61e
Author: Chris Bracken <chris@bracken.jp>
Date:   Sat, 26 Jul 2025 08:05:05 -0700

Update from gitout to gout

I renamed gitout to gout since there were a half-dozen other git-related
tools named gitout.

Diffstat:
Mgrm | 44++++++++++++++++++++++----------------------
Dpost-receive.d/gitout | 80-------------------------------------------------------------------------------
Apost-receive.d/gout | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 102 insertions(+), 102 deletions(-)

diff --git a/grm b/grm @@ -26,23 +26,23 @@ GRM_URL_PREFIX="https://git.bracken.jp" # Add Mastodon verification URL to index header. ME_URL="https://famichiki.jp/@akande" -# path of the post-receive hooks for gitout +# path of the post-receive hooks for gout GRM_POSTRECV_HOOK="/home/git/git_infra/post-receive" GRM_POSTRECV_HOOKS_DIR="/home/git/git_infra/post-receive.d" -# root directory of gitout web pages -GITOUT_WEB_ROOT="/usr/local/www/git.bracken.jp" +# root directory of gout web pages +GOUT_WEB_ROOT="/usr/local/www/git.bracken.jp" # # # # #--------------------------------------------# -# for gitout +# for gout export LC_CTYPE="en_US.UTF-8" prog_name="${0##*/}" repos_root=${GRM_REPOS_ROOT:-/home/git} -web_root=${GITOUT_WEB_ROOT:-/srv/git} +web_root=${GOUT_WEB_ROOT:-/srv/git} recompile_repo() { repo_dir="${repos_root}/${1}.git" @@ -52,19 +52,19 @@ recompile_repo() { [ -d "$repo_dir" ] || { echo "[$1] repo not found"; return 1; } if [ -e "$repo_dir/git-daemon-export-ok" ]; then - echo "[$1] recompiling gitout pages..." + echo "[$1] recompiling gout pages..." mkdir -p "$repo_web_dir" cd "${repo_web_dir:?}" && \ rm -f "$cachefile" && \ rm -rf "commit" "file" && \ - gitout -c "$cachefile" "$repo_dir" && \ + gout -c "$cachefile" "$repo_dir" && \ ln -sf log.html index.html && \ ln -sf ../logo.png logo.png && \ ln -sf ../style.css style.css && \ ln -sf ../favicon.png favicon.png && \ echo "[$1] done!" else - echo "[$1] Not recompiling gitout pages: private repo" + echo "[$1] Not recompiling gout pages: private repo" fi } @@ -73,19 +73,19 @@ rebuild_index() { mkdir -p "${web_root}" || return 1; # 1. find all directories in $repos_root ending with .git # 2. filter all the public repos (with git-daemon-export-ok) - # 3. exclude any repo marked with gitout-no-index + # 3. exclude any repo marked with gout-no-index # 4. sort the result # 5. hack for posix compatibility - # 6. run gitout_index on the result + # 6. run gout_index on the result # 7. export result to index.html find "${repos_root}/." ! -name . -prune \ -type d -name "*.git" \ -exec test -e "{}/git-daemon-export-ok" \;\ - -exec test ! -e "{}/gitout-no-index" \; \ + -exec test ! -e "{}/gout-no-index" \; \ -print \ | sort -f \ | sed -e 's/"/"\\""/g' -e 's/.*/"&"/' \ - | xargs gitout_index -m "${ME_URL}" \ + | xargs gout_index -m "${ME_URL}" \ > "${web_root}/index.html" && \ echo "[index] done!" } @@ -141,16 +141,16 @@ ${BLUE}enter index [default: ${GREEN}1${BLUE}]${RESET}" # start creating repo git init --bare "$repo_path" - echo "writing gitout metadata..." + echo "writing gout metadata..." printf "%s\n" "$repo_desc" > "$repo_path/description" printf "%s\n" "$owner" > "$repo_path/owner" printf "%s\n" "$clone_url" > "$repo_path/url" echo "setting visibility..." [ "$exported" = "1" ] && : >> "$repo_path/git-daemon-export-ok" - [ "$hidden" = "1" ] && : >> "$repo_path/gitout-no-index" + [ "$hidden" = "1" ] && : >> "$repo_path/gout-no-index" - echo "installing gitout post-receive hook..." + echo "installing gout post-receive hook..." ln -sf "$GRM_POSTRECV_HOOK" "$repo_path/hooks/post-receive" mkdir -p "$repo_path/hooks/post-receive.d" for hook in "$(ls "$GRM_POSTRECV_HOOKS_DIR")"; do @@ -172,8 +172,8 @@ grm_remove() { rm -rf "${web_root:?}/${repo:?}" || continue; fi done - # only rebuild index if gitout exists - command -v gitout_index -m "${ME_URL}" >/dev/null && rebuild_index & + # only rebuild index if gout exists + command -v gout_index -m "${ME_URL}" >/dev/null && rebuild_index & wait } @@ -183,7 +183,7 @@ grm_list() { find "${repos_root}/." ! -name . -prune \ -type d -name "*.git" \ -exec test -e "{}/git-daemon-export-ok" \; \ - -exec test ! -e "{}/gitout-no-index" \; \ + -exec test ! -e "{}/gout-no-index" \; \ -exec basename {} '.git' \; | sort -f ;; private) find "${repos_root}/." ! -name . -prune \ @@ -194,7 +194,7 @@ grm_list() { find "${repos_root}/." ! -name . -prune \ -type d -name "*.git" \ -exec test -e "{}/git-daemon-export-ok" \; \ - -exec test -e "{}/gitout-no-index" \; \ + -exec test -e "{}/gout-no-index" \; \ -exec basename {} '.git' \; | sort -f ;; *) find "${repos_root}/." ! -name . -prune \ @@ -230,7 +230,7 @@ grm_info() { printf "visibility: " if [ -e "${repo_dir}/git-daemon-export-ok" ]; then - if [ -e "${repo_dir}/gitout-no-index" ]; then + if [ -e "${repo_dir}/gout-no-index" ]; then printf "%b\n" "${YELLOW}unlisted${RESET}" else printf "%b\n" "${GREEN}public${RESET}" @@ -269,8 +269,8 @@ commands: ls private list private repos ls unlisted list unlisted (hidden) repos rm repo1 [repo2..] remove repos - rc recompile gitout index - rc repo1 [repo2..] recompile gitout pages for repos, + rc recompile gout index + rc repo1 [repo2..] recompile gout pages for repos, and recompile index rca recompile all public repos help show help diff --git a/post-receive.d/gitout b/post-receive.d/gitout @@ -1,80 +0,0 @@ -#!/bin/sh -e - -export LC_CTYPE="en_US.UTF-8" - -# Add Mastodon verification URL to index header. -me_url="https://famichiki.jp/@akande" - -# HTML root directory into which gitout will write. -www_root="/usr/local/www/git.bracken.jp" - -# Hooks are called from the repo directory. -repo_dir=$(pwd) - -# The gitout cache file. -# This is an optimisation to avoid regenerating all pages on each push. -cachefile="${repo_dir}/.htmlcache" - -# The directory under which all repos are located. -# Repos under this directory will be added to the repo index page. -repos_root=$(dirname "$repo_dir") - -# The user-friendly name of the repository. -repo_name=$(basename "$repo_dir" '.git') - -# Detect --force pushes. -cd "${repo_dir}" || exit 1 -force=0 -while read -r old new _; do - [ "${old}" = "0000000000000000000000000000000000000000" ] && continue - [ "${new}" = "0000000000000000000000000000000000000000" ] && continue - - hasrevs=$(git rev-list "$old" "^$new" | sed 1q) - if [ -n "$hasrevs" ]; then - echo "[gitout] Force push detected: cleaning cache" - force=1 - break - fi -done - -# If there was a --force push, delete all existing pages. The lack of a cache -# file will trigger a full rebuild below. -if [ "$force" = "1" ]; then - rm -f "$cachefile" - rm -rf "commit" "file" -fi - -# Build the pages. If $cachefile is not present, a full rebuild is performed. -if [ -e "${repo_dir}/git-daemon-export-ok" ]; then - # Change to the directory where we will output HTML pages. - repo_web_dir="${www_root}/${repo_name}" - mkdir -p "$repo_web_dir" - cd "$repo_web_dir" || exit 1 - - # Generate the index page. - # Any repo containing a gitout-no-index file will not be indexed. - echo "[gitout] Building repo index" - find "${repos_root}/." -maxdepth 1 \ - -type d \ - -name "*.git" \ - -exec test -e "{}/git-daemon-export-ok" \; \ - -exec test ! -e "{}/gitout-no-index" \; \ - -print \ - | sort -f \ - | sed -e 's/"/"\\""/g' -e 's/.*/"&"/' \ - | xargs gitout_index -m "$me_url" \ - > "${www_root}/index.html" - - # Rebuild the pages for the repo (including for unlisted repos). - echo "[gitout] Building pages" - gitout -c "$cachefile" "$repo_dir" - - # use log as index page - echo "[gitout] Linking assets" - ln -sf log.html index.html - ln -sf ../style.css style.css - ln -sf ../logo.png logo.png - ln -sf ../favicon.png favicon.png -else - echo "[gitout] Not building pages: private repo" -fi diff --git a/post-receive.d/gout b/post-receive.d/gout @@ -0,0 +1,80 @@ +#!/bin/sh -e + +export LC_CTYPE="en_US.UTF-8" + +# Add Mastodon verification URL to index header. +me_url="https://famichiki.jp/@akande" + +# HTML root directory into which gout will write. +www_root="/usr/local/www/git.bracken.jp" + +# Hooks are called from the repo directory. +repo_dir=$(pwd) + +# The gout cache file. +# This is an optimisation to avoid regenerating all pages on each push. +cachefile="${repo_dir}/.htmlcache" + +# The directory under which all repos are located. +# Repos under this directory will be added to the repo index page. +repos_root=$(dirname "$repo_dir") + +# The user-friendly name of the repository. +repo_name=$(basename "$repo_dir" '.git') + +# Detect --force pushes. +cd "${repo_dir}" || exit 1 +force=0 +while read -r old new _; do + [ "${old}" = "0000000000000000000000000000000000000000" ] && continue + [ "${new}" = "0000000000000000000000000000000000000000" ] && continue + + hasrevs=$(git rev-list "$old" "^$new" | sed 1q) + if [ -n "$hasrevs" ]; then + echo "[gout] Force push detected: cleaning cache" + force=1 + break + fi +done + +# If there was a --force push, delete all existing pages. The lack of a cache +# file will trigger a full rebuild below. +if [ "$force" = "1" ]; then + rm -f "$cachefile" + rm -rf "commit" "file" +fi + +# Build the pages. If $cachefile is not present, a full rebuild is performed. +if [ -e "${repo_dir}/git-daemon-export-ok" ]; then + # Change to the directory where we will output HTML pages. + repo_web_dir="${www_root}/${repo_name}" + mkdir -p "$repo_web_dir" + cd "$repo_web_dir" || exit 1 + + # Generate the index page. + # Any repo containing a gout-no-index file will not be indexed. + echo "[gout] Building repo index" + find "${repos_root}/." -maxdepth 1 \ + -type d \ + -name "*.git" \ + -exec test -e "{}/git-daemon-export-ok" \; \ + -exec test ! -e "{}/gout-no-index" \; \ + -print \ + | sort -f \ + | sed -e 's/"/"\\""/g' -e 's/.*/"&"/' \ + | xargs gout_index -m "$me_url" \ + > "${www_root}/index.html" + + # Rebuild the pages for the repo (including for unlisted repos). + echo "[gout] Building pages" + gout -c "$cachefile" "$repo_dir" + + # use log as index page + echo "[gout] Linking assets" + ln -sf log.html index.html + ln -sf ../style.css style.css + ln -sf ../logo.png logo.png + ln -sf ../favicon.png favicon.png +else + echo "[gout] Not building pages: private repo" +fi