Implement git-activity-by-year master
authorSiraaj Khandkar <siraaj@khandkar.net>
Mon, 23 Dec 2019 15:09:59 +0000 (10:09 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Mon, 23 Dec 2019 15:09:59 +0000 (10:09 -0500)
git-activity-by-year [new file with mode: 0755]

diff --git a/git-activity-by-year b/git-activity-by-year
new file mode 100755 (executable)
index 0000000..82512dc
--- /dev/null
@@ -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
This page took 0.030717 seconds and 4 git commands to generate.