From: Siraaj Khandkar Date: Mon, 23 Dec 2019 15:09:59 +0000 (-0500) Subject: Implement git-activity-by-year X-Git-Url: https://git.xandkar.net/?p=selfanal.git;a=commitdiff_plain Implement git-activity-by-year --- diff --git a/git-activity-by-year b/git-activity-by-year new file mode 100755 index 0000000..82512dc --- /dev/null +++ b/git-activity-by-year @@ -0,0 +1,68 @@ +#! /bin/sh + +set -e + +root="$1" +typ="$2" + +case "$typ" in + 'commits') ;; + 'changes') ;; + '') typ='commits';; + *) + echo "Usage: $0 DIRECTORY [commits|changes]" >&2 + exit 1 +esac + +find "$root" -type d -name '.git' \ +| while read -r dir + do + cd "$dir" || exit 1 + git log --format=%ci --numstat + done \ +| gawk ' + /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} / { + date = $1 + split(date, d, "-") + year = d[1] + commits[year]++ + } + + /^[0-9]+\s+[0-9]+\s+/ { + additions = $1 + deletions = $2 + changes[year] += additions + deletions + } + + END { + for (year in changes) { + print year, "commits", commits[year] + print year, "changes", changes[year] + } + }' \ +| awk -v type_selected="$typ" ' + { + year = $1 + type = $2 + value = $3 + d[year, type] = value + if (value > max[type]) + max[type] = value + } + + END { + for (yeartype in d) { + split(yeartype, yt, SUBSEP) + year = yt[1] + type = yt[2] + value = d[yeartype] + if (type == type_selected) { + printf "%s ", year + for (i = 1; i <= (value * 100) / max[type]; i++) { + printf "|" + } + printf "\n" + } + } + }' \ +| sort -n -k 1