stagit (2462B)
1 #!/bin/sh -e 2 3 export LC_CTYPE="en_US.UTF-8" 4 5 # HTML root directory into which stagit will write. 6 www_root="/usr/local/www/git.bracken.jp" 7 8 # Hooks are called from the repo directory. 9 repo_dir=$(pwd) 10 11 # The stagit cache file. 12 # This is an optimisation to avoid regenerating all pages on each push. 13 cachefile="${repo_dir}/.htmlcache" 14 15 # The directory under which all repos are located. 16 # Repos under this directory will be added to the repo index page. 17 repos_root=$(dirname "$repo_dir") 18 19 # The user-friendly name of the repository. 20 repo_name=$(basename "$repo_dir" '.git') 21 22 # Detect --force pushes. 23 cd "${repo_dir}" || exit 1 24 force=0 25 while read -r old new _; do 26 [ "${old}" = "0000000000000000000000000000000000000000" ] && continue 27 [ "${new}" = "0000000000000000000000000000000000000000" ] && continue 28 29 hasrevs=$(git rev-list "$old" "^$new" | sed 1q) 30 if [ -n "$hasrevs" ]; then 31 echo "[stagit] Force push detected: cleaning cache" 32 force=1 33 break 34 fi 35 done 36 37 # If there was a --force push, delete all existing pages. The lack of a cache 38 # file will trigger a full rebuild below. 39 if [ "$force" = "1" ]; then 40 rm -f "$cachefile" 41 rm -rf "commit" "file" 42 fi 43 44 # Build the pages. If $cachefile is not present, a full rebuild is performed. 45 if [ -e "${repo_dir}/git-daemon-export-ok" ]; then 46 # Change to the directory where we will output HTML pages. 47 repo_web_dir="${www_root}/${repo_name}" 48 mkdir -p "$repo_web_dir" 49 cd "$repo_web_dir" || exit 1 50 51 # Generate the index page. 52 # Any repo containing a stagit-no-index file will not be indexed. 53 echo "[stagit] Building repo index" 54 find "${repos_root}/." -maxdepth 1 \ 55 -type d \ 56 -name "*.git" \ 57 -exec test -e "{}/git-daemon-export-ok" \; \ 58 -exec test ! -e "{}/stagit-no-index" \; \ 59 -print \ 60 | sort -f \ 61 | sed -e 's/"/"\\""/g' -e 's/.*/"&"/' \ 62 | xargs stagit-index \ 63 > "${www_root}/index.html" 64 65 # Rebuild the pages for the repo (including for unlisted repos). 66 echo "[stagit] Building pages" 67 stagit -c "$cachefile" "$repo_dir" 68 69 # use log as index page 70 echo "[stagit] Linking assets" 71 ln -sf log.html index.html 72 ln -sf ../style.css style.css 73 ln -sf ../logo.png logo.png 74 ln -sf ../favicon.png favicon.png 75 else 76 echo "[stagit] Not building pages: private repo" 77 fi