From 3c06dfc763cb6db07e3730b91c4961f7cc19e99f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 5 Mar 2013 23:41:27 -0500 Subject: [PATCH] Added hashcache This will be used to generate links to previous commits (to avoid putting full URLs in the articles themselves) --- hashcache | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ processor | 8 ++++++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 hashcache diff --git a/hashcache b/hashcache new file mode 100755 index 0000000..7645973 --- /dev/null +++ b/hashcache @@ -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 . +# # + +# 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 diff --git a/processor b/processor index 80fd8ce..c8c7862 100755 --- a/processor +++ b/processor @@ -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 < @@ -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"