gitweb/genindex.sh: maintain a gitdir.list file
[girocco.git] / gitweb / genindex.sh
blob06eda6087e29a3f7f4edf398915111719215b9d1
1 #!/bin/sh
3 # genindex - Generate gitweb project list from Girocco's
5 # Usage: genindex.sh [project-to-update]
7 # If project-to-update is given, then only that one will be updated
9 . @basedir@/shlib.sh
11 set -e
13 update="${1%.git}"
15 # Use the correct umask so the list file is group-writable, if owning_group set
16 if [ -n "$cfg_owning_group" ]; then
17 umask 002
20 # gitweb calls CGI::Util::unescape on both the path and owner, but the only
21 # character we allow that needs to be escaped is '+' which is allowed in
22 # both the owner email and in the project name. Otherwise '+' will be
23 # displayed as a ' ' in the owner email and will cause a project name
24 # containing it to be omitted from the project list page.
26 if [ -z "$update" ] || [ ! -s "$cfg_projlist_cache_dir/gitproj.list" ]; then
27 # Must read all the owners so don't bother with join at all
28 exec 3>/tmp/gitdir.listu.$$
29 get_repo_list | while read proj; do
30 echo "$proj $(cd "$cfg_reporoot/$proj.git" &&
31 echo "$proj $(pwd -P)" >&3 &&
32 config_get owner)"
33 done | perl -MDigest::MD5=md5_hex -ne \
34 '@_=split;print "$_[0] ",md5_hex(lc($_[1]))," $_[1]\n";' |
35 LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$
36 test $? -eq 0
37 exec 3>&-
38 LC_ALL=C sort -k 1,1 </tmp/gitdir.listu.$$ >/tmp/gitdir.list.$$
39 rm -f /tmp/gitdir.listu.$$
40 else
41 get_repo_list | LC_ALL=C sort -k 1,1 >/tmp/gitproj.srt.$$
42 LC_ALL=C join -a 1 /tmp/gitproj.srt.$$ "$cfg_projlist_cache_dir/gitproj.list" |
43 while read proj hash owner; do
44 if [ "$proj" = "$update" ] || [ -z "$owner" ] || [ -z "$hash" ]; then
45 echo "$proj recalc $(cd "$cfg_reporoot/$proj.git" && config_get owner)"
46 else
47 echo "$proj $hash $owner"
49 done | perl -MDigest::MD5=md5_hex -ne \
50 '@_=split;print "$_[0] ",$_[1] eq "recalc"?md5_hex(lc($_[2])):$_[1]," $_[2]\n";' |
51 LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$
52 test $? -eq 0
53 LC_ALL=C join -a 1 -t ' ' /tmp/gitproj.srt.$$ "$cfg_projlist_cache_dir/gitdir.list" |
54 while read proj path; do
55 if [ "$proj" = "$update" ] || [ -z "$path" ]; then
56 echo "$proj $(cd "$cfg_reporoot/$proj.git" && pwd -P)"
57 else
58 echo "$proj $path"
60 done |
61 LC_ALL=C sort -k 1,1 >/tmp/gitdir.list.$$
62 test $? -eq 0
63 rm -f /tmp/gitproj.srt.$$
65 cut -d ' ' -f 1,3- </tmp/gitproj.list.$$ | sed -e 's/ /.git /;s/+/%2B/g' >/tmp/gitweb.list.$$
67 # Set the proper group, if configured, before the move
68 if [ -n "$cfg_owning_group" ]; then
69 chgrp "$cfg_owning_group" /tmp/gitproj.list.$$ /tmp/gitdir.list.$$ /tmp/gitweb.list.$$
72 # Atomically move into place
73 mv -f /tmp/gitproj.list.$$ "$cfg_projlist_cache_dir/gitproj.list"
74 mv -f /tmp/gitdir.list.$$ "$cfg_projlist_cache_dir/gitdir.list"
75 mv -f /tmp/gitweb.list.$$ "$cfg_projlist_cache_dir/gitweb.list"