1
0
Fork 0

Added hashcache

This will be used to generate links to previous commits (to avoid putting full URLs in the articles themselves)
master
Mike Gerwitz 2013-03-05 23:41:27 -05:00
parent 8ac9aa9531
commit 3c06dfc763
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
2 changed files with 75 additions and 1 deletions

68
hashcache 100755
View File

@ -0,0 +1,68 @@
#!/bin/bash
#
# Hash cache storage and retrieval operations
#
# 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/>.
# #
# intended to be configured from a configuration file; lowercase to help
# mitigate global env var conflicts
cachefile="${hashcache:-.hashcache}"
# 'cause it rhymes and 'cause it's useful
_cache()
{
hash="$1"
value="$2"
echo "$hash $value" >>"$cachefile"
}
# retrieves the value associated with the given hash
_retrieve()
{
hash="$1"
# if multiple identical hashes exist, then the last one takes precedence
# (ideally, such a thing should never happen, but it's best to be prepared)
grep "^$hash " "$cachefile" \
| tail -n1 \
| cut -d' ' -f2-
}
# clears the cache file
_wipe()
{
>"$cachefile"
}
# the hash is required, but the value to set it to is optional
hash="${1?No hash provided}"
set="$2"
# poor man's argument parsing (we don't need no stinkin' options [yet]); "clear"
# is not a valid hash currently, though I suppose a sadistic repository could
# allow such, and we're supposed to be repo-agnostic
if [ "$hash" == 'clear' ]; then
_wipe
elif [ "$set" ]; then
_cache "$hash" "$set"
else
_retrieve "$hash"
fi

View File

@ -26,6 +26,11 @@ path_out="${2?Missing output path}"
# provide default message formatter if necessary
msgfmt="${msgfmt:-./msgfmt}"
# clear the cachefile
./hashcache clear
# output XHTML5 header
cat <<EOH
<!DOCTYPE html>
<html>
@ -93,7 +98,8 @@ while read hash commit ts id subject; do
# invoke template
"$repotype"/commit2html "$commit" | ./tpl/commit.sh
) > "$path_out/$pagefile"
) > "$path_out/$pagefile" \
&& ./hashcache "$hash" "$pagefile"
done
yearrange="$firstyear"