1
0
Fork 0
repo2html/repo2html

113 lines
3.5 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# Detects repository VCS and begins VCS-specific processing
#
# Copyright (C) 2012 Mike Gerwitz
#
# This file is part of repo2html.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# repository detection
repotype=
if repodir="$( git rev-parse --git-dir 2>/dev/null )"; then
# use absolute path for git directory
export GIT_DIR="$( cd $repodir && pwd )"
repotype=git
else
# contribute!
echo "fatal: only git repositories are currently supported" >&2
exit 128
fi
# store our cwd and enter our own (to make invoking relative scripts easier)
path_out="$( pwd )"
path="$( dirname "$0" )"
cd "$path"
# provides configuration warning and outputs a default
cwarn()
{
echo "Warning: no $1 provided; defaulting to: ${2:-(empty)}" >&2
echo "$2"
}
# configuration (note that this setup in conjunction with the below defaults
# imply that they can be passed in as environment variables as an alternative to
# options)
while getopts t:d:c:l:f:R: opt; do
case "$opt" in
t) title="$OPTARG";;
d) desc="$OPTARG";;
c) copyright="$OPTARG";;
l) license="$OPTARG";;
f) msgfmt="$OPTARG";;
R) rss_count="$OPTARG";;
?) exit 64;;
esac
done
shift $((OPTIND-1))
url_root="${1?Missing root URL (for RSS)}"
# default title to repository name (as taken from the directory)
title="${title:-$( cwarn title $( basename "$path_out" ) )}"
desc="${desc:-$( cwarn description )}"
# default to a restrictive copyright (unfortunately, that's the best we can do,
# since copyright is restrictive by default)
copyright="${copyright:-$( cwarn copyright 'Respective Authors' )}"
license="${license:-$( cwarn license )}"
# provide default message formatter if necessary
msgfmt="${msgfmt:-./msgfmt}"
# make configuration available to all scripts
export title desc copyright license msgfmt url_root
# clear the cachefile (TODO: we could maintain cache files from previous runs if
# we offer a flag that opts out of reprocessing previously processed commits)
echo "Clearing hashcache..." >&2
./hashcache clear
# set the cref error log, which will allow us to re-process *only* those commits
# that actually need to be reprocessed; this avoids the need to prime the
# hashcache, saving cycles
cref_errlog_first=.cref-errlog
export cref_errlog="$cref_errlog_first"
>"$cref_errlog"
# pass commit list to the HTML and RSS processors (cache list to disk for
# reference and further processing)
listcache=.list
"$repotype"/list | tee \
>( ./rss "$repotype" "$url_root" "$rss_count" > "$path_out/rss.xml" ) \
"$listcache" \
| ./processor "$repotype" "$path_out"
# re-process cref errors (but only once; any errors at this point will be
# considered to be problem refs)
export cref_errlog=.cref-bad
>"$cref_errlog"
grep -f"$cref_errlog_first" "$listcache" \
| ./processor "$repotype" "$path_out" \
2> >( sed 's/^/[Reprocessing] /g' >&2 )
# if any invalid crefs remain, then they're bad
[ -s "$cref_errlog" ] && {
echo "warning: bad cref(s); see $cref_errlog" >&2
}