#!/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 . # # declare -xr repotype="${1?Missing repository type}" declare -xr path_out="${2?Missing output path}" # provide default message formatter if necessary msgfmt="${msgfmt:-./msgfmt}" # default template path (the former is exported so that templates themselves may # make use of default templates) declare -xr path_default_tpl=./tpl declare -xr path_tpl="${path_tpl:-$path_default_tpl}" resolv-template() { name="$1" [ -x "$path_tpl/$name" ] \ && echo "$path_tpl/$name" \ || echo "$path_default_tpl/$name" } apply-template() { $( resolv-template "$1" ) } exec-template() { exec $( resolv-template "$1" ) } # allows custom templates to invoke the default template (say, to set/override # options) resume-default() { exec "$path_default_tpl/$1" } # 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() { 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" pagefile="$( ./outfgen "$ts" "$id" )" fmtsubject="$( "$msgfmt" < <( echo "$subject"; echo ) )" [ "$prevdate" == "$dategroup" ] || { echo "

$dategroup

" } printf '' \ "$day" "$pagefile" "$fmtsubject" 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 export path_root='../../' # invoke template "$repotype"/commit2html "$commit" | apply-template commit ) > "$path_out/$pagefile" \ && ./hashcache "$hash" "$pagefile" done yearrange="$firstyear" if [ "$lastyear" -gt "$firstyear" ]; then yearrange="$firstyear–$lastyear" fi } # let the template finish export -f do-index resolv-template apply-template exec-template resume-default exec-template index