2012-10-07 11:43:41 -04:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Generates HTML from repository commit messages
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
# #
|
|
|
|
|
2013-05-19 15:56:17 -04:00
|
|
|
declare -xr repotype="${1?Missing repository type}"
|
|
|
|
declare -xr path_out="${2?Missing output path}"
|
2012-10-07 11:43:41 -04:00
|
|
|
|
2012-10-19 20:09:31 -04:00
|
|
|
# provide default message formatter if necessary
|
|
|
|
msgfmt="${msgfmt:-./msgfmt}"
|
|
|
|
|
2013-05-27 16:51:41 -04:00
|
|
|
source include/tpl "$path_tpl"
|
2013-05-19 16:19:21 -04:00
|
|
|
|
2013-05-21 17:20:58 -04:00
|
|
|
|
|
|
|
# generates output filename
|
|
|
|
outfgen()
|
|
|
|
{
|
|
|
|
ts="${1?Missing timestamp}"
|
|
|
|
id="${2?Missing commit id}"
|
|
|
|
|
|
|
|
dateout="$( ./tsdate "$ts" %Y-%m-%d )"
|
|
|
|
month="$( ./tsdate "$ts" %m )"
|
|
|
|
year="${dateout%%-*}"
|
|
|
|
|
2013-06-06 14:23:58 -04:00
|
|
|
echo "$year/$month/$id"
|
2013-05-21 17:20:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-19 15:56:17 -04:00
|
|
|
# performs index generation; by separating this into a procedure, we allow the
|
|
|
|
# template to invoke it at any point and further process the output
|
|
|
|
do-index()
|
|
|
|
{
|
2013-05-25 22:14:42 -04:00
|
|
|
# commands to invoke to output heading, index lines and index footers
|
|
|
|
# (intended to close headings)
|
|
|
|
headout="$1"
|
|
|
|
lineout="$2"
|
|
|
|
footout="$3"
|
|
|
|
|
2013-05-25 20:05:00 -04:00
|
|
|
prevdate=
|
|
|
|
lastts=
|
|
|
|
firstyear=0
|
|
|
|
lastyear=0
|
|
|
|
lasthash=
|
|
|
|
|
|
|
|
# generate index
|
|
|
|
while read hash commit ts id subject; do
|
|
|
|
# ignore commits that begin with ':'
|
|
|
|
[[ "$subject" == :* ]] && {
|
|
|
|
echo "Ignoring $commit: $subject" >&2
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Found $commit: $subject" >&2
|
|
|
|
|
|
|
|
dateout="$( ./tsdate "$ts" %Y-%m-%d )"
|
|
|
|
dategroup="${dateout%-*}"
|
|
|
|
day="${dateout##*-}"
|
|
|
|
month="$( ./tsdate "$ts" %m )"
|
|
|
|
year="${dateout%%-*}"
|
|
|
|
|
|
|
|
# commits are ordered by date desc
|
|
|
|
lasthash="${lasthash:-$hash}"
|
|
|
|
lastts="${lastts:-$ts}"
|
|
|
|
lastyear="${lastyear:-$year}"
|
|
|
|
firstyear="$year"
|
|
|
|
|
2013-06-06 14:23:58 -04:00
|
|
|
pagefile_base="$( outfgen "$ts" "$id" )"
|
|
|
|
pagefile_url="$pagefile_base$html_url_ext"
|
|
|
|
pagefile="$pagefile_base$html_ext"
|
2013-05-27 16:50:34 -04:00
|
|
|
fmtsubject="$( "$msgfmt" -P < <( echo "$subject"; echo ) )"
|
2013-05-25 20:05:00 -04:00
|
|
|
|
|
|
|
[ "$prevdate" == "$dategroup" ] || {
|
2013-05-25 22:14:42 -04:00
|
|
|
[ -z "$prevdate" ] || $footout
|
|
|
|
$headout "$dategroup"
|
2013-05-25 20:05:00 -04:00
|
|
|
}
|
|
|
|
|
2013-06-06 14:23:58 -04:00
|
|
|
$lineout "$day" "$pagefile_url" "$fmtsubject"
|
2013-05-25 20:05:00 -04:00
|
|
|
|
|
|
|
prevdate="$dategroup"
|
|
|
|
|
|
|
|
# create the containing directory (if it does not yet exist and then
|
|
|
|
# generate the commit page
|
|
|
|
mkdir -p "$( dirname "$path_out/$pagefile" )" \
|
|
|
|
&& (
|
|
|
|
# make the majority of the data available as environment variables (for
|
|
|
|
# convenience), lowercase so as not to be conflict with conventional
|
|
|
|
# environment variables
|
|
|
|
export hash commit id subject="$fmtsubject" timestamp="$ts"
|
|
|
|
export dategroup month day year
|
|
|
|
|
|
|
|
# invoke template
|
|
|
|
"$repotype"/commit2html "$commit" | apply-template commit
|
|
|
|
) > "$path_out/$pagefile" \
|
2013-06-06 14:23:58 -04:00
|
|
|
&& ./hashcache "$hash" "$pagefile_url" "$subject"
|
2013-05-25 20:05:00 -04:00
|
|
|
done
|
|
|
|
|
2013-05-25 22:14:42 -04:00
|
|
|
$footout
|
|
|
|
|
2013-05-25 20:05:00 -04:00
|
|
|
yearrange="$firstyear"
|
|
|
|
if [ "$lastyear" -gt "$firstyear" ]; then
|
|
|
|
yearrange="$firstyear–$lastyear"
|
|
|
|
fi
|
2013-05-19 15:56:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# let the template finish
|
2013-05-27 16:51:41 -04:00
|
|
|
export -f do-index outfgen
|
2013-05-19 15:56:17 -04:00
|
|
|
exec-template index
|