#!/usr/bin/env bash
set -euo pipefail
for tool in git jq; do
if ! command -v "${tool}" > /dev/null 2>&1; then
echo "Error: ${tool} not found in PATH" >&2
exit 1
fi
done
: > stats.out
mapfile -t taglist < <(
git for-each-ref --sort=creatordate \
--format='%(refname:short) %(creatordate:short)' refs/tags |
awk '{print $1 ":readmeData.json " $2}'
)
exec 3< <(printf '%s\n' "${taglist[@]}" | cut -d' ' -f1 | git cat-file --batch)
for line in "${taglist[@]}"; do
date=${line#* }
if ! read -r -a header_fields <&3; then
break
fi
if ((${#header_fields[@]} < 3)); then
continue
fi
size=${header_fields[2]}
if [[ ! "${size}" =~ ^[0-9]+$ ]]; then
continue
fi
IFS= read -r -N "${size}" blob <&3
read -r _ <&3 || true
if [[ -z "${blob}" ]]; then
continue
fi
jq -nr --arg date "${date}" --argjson blob "${blob}" '
$blob.base.entries // empty
| if type=="array" then
.[] | "\($date),\(.)"
else
"\($date),\(.)"
end
' >> stats.out 2> /dev/null || true
done