tCache last revision and speed up generation. - bitreich-memestats - metrics and graphs for the bitreich meme collection
git clone git://src.adamsgaard.dk/bitreich-memestats
Log
Files
Refs
LICENSE
---
commit 726dbaf74c47d4260c83251a2145d780a5d15bc9
parent e082f9a06845793bcfa455df769420c1c926a85e
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun, 29 Aug 2021 20:42:49 +0200

Cache last revision and speed up generation.

Diffstat:
  M Makefile                            |       2 +-
  M extract-memecount.sh                |      31 +++++++++++++++++++++++++++----

2 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/Makefile b/Makefile
t@@ -17,7 +17,7 @@ memecount_semilog: plot-memecount.sh memecount.log
 
 # output format: datecommitn_memes
 memecount.log: extract-memecount.sh
-        ./extract-memecount.sh $(ANNNA) > $@
+        ./extract-memecount.sh $(ANNNA) $@
 
 clean:
         rm -f media-stats
diff --git a/extract-memecount.sh b/extract-memecount.sh
t@@ -1,16 +1,36 @@
 #!/bin/sh
 # generate table of hashtag numbers over time
 
-annnadir="${1:-$HOME/code/annna}"
+if [ $# -lt 1 ];
+then
+        printf "usage: %s annnadir [memecount.log]\n" "$(basename "$0")" >&2
+        exit 1
+fi
+
+annnadir="${1}"
 memefile="modules/hashtags/hashtags.txt"
 update_annna=yes
-fromrevision="${2}"
+outputfile="${2:-memecount.log}"
+revisionrange=""
 
 if [ ! -e "${annnadir}/${memefile}" ]; then
         printf 'error: could not open %s\n' "${annnadir}/${memefile}"
         exit 1
 fi
 
+if [ -f "${outputfile}" ]; then
+        lastrevision="$(tail -n 1 "${outputfile}" | cut -f 2)"
+        revisionrange="${lastrevision}..HEAD"
+fi
+
+case "${outputfile}" in
+/*)
+        ;;
+*)
+        outputfile="$(pwd)/${outputfile}"
+        ;;
+esac
+
 cd "$annnadir"
 if [ "$update_annna" = "yes" ]; then
         git pull >/dev/null 2>&1
t@@ -19,7 +39,8 @@ fi
 headcommit="$(git rev-parse HEAD)"
 i=0
 # derived from Hiltjo Posthuma's loc.sh
-git log --pretty='format:%H %cd %at' --date="format:%Y-%m-%d" | \
+git log --pretty='format:%H %cd %at' --date="format:%Y-%m-%d" \
+        "${revisionrange}" | \
         sort -k 2 | uniq -f 1 | \
         while read -r commit date timestamp; do
 
t@@ -52,8 +73,10 @@ git log --pretty='format:%H %cd %at' --date="format:%Y-%m-%d" | \
                         lastprintdate="$date"
 
                         printf '%s\t%s\t%s\t%s\t%s\n' \
-                                "$date" "$commit" "$n" "$timestamp" "$dn_dt"
+                                "$date" "$commit" "$n" "$timestamp" "$dn_dt" \
+                                >> "${outputfile}"
 
                 fi
         fi
 done
+