Skip to content

Instantly share code, notes, and snippets.

@jonhoo
Created January 8, 2015 22:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonhoo/8f0d046a2fba7d52f71d to your computer and use it in GitHub Desktop.
Save jonhoo/8f0d046a2fba7d52f71d to your computer and use it in GitHub Desktop.
Plot commit activity across all local git repositories

These scripts will find all git repositories on the local machine, find all commits made by some user (specified as arguments to find-commits), and plot the number of commits, lines added, and lines removed over time. Commits that add or remove over 10000 lines will be ignored (for huge data files and such).

To run:

$ ./find-commits.sh jon@thesquareplanet.com jon@tsp.io > commits.txt
$ cat commits.txt | ./draw-commits.sh
#!/bin/bash
data=""
p=""
add=0
del=0
n=0
while read -r line; do
t=$(echo "$line" | awk '{print $1}')
a=$(echo "$line" | awk '{print $2}')
d=$(echo "$line" | awk '{print $3}')
if [[ $t == $p ]]; then
((add+=a))
((del+=d))
((n+=1))
else
if [[ $p != "" ]]; then
data="$data$p $add $del $n
"
fi
add=$a
del=$d
n=1
p="$t"
fi
done < <(cat - \
| sed 's/T/ /' \
| awk '{print $1" "$3" "$4}' \
| sed 's/-[0-9]* / /' \
| sed '/[0-9][0-9][0-9][0-9][0-9]/d' \
| sort \
)
echo "
set term pngcairo size 1280,720
set xdata time
set timefmt '%Y-%m'
set multiplot layout 2,1
plot '-' using 1:2 with lines lt 2 lw 3 t 'adds', \
'-' using 1:3 with lines lt 7 lw 3 t 'dels'
${data}e
${data}e
plot '-' using 1:4 with lines lt 3 lw 3 t 'commits'
${data}e
" | gnuplot | display -
#!/bin/bash
filter=""
for email in "$@"; do
filter="$filter --author=$email"
done
data=()
while read -r repo; do
repo="$(realpath "$repo/..")"
echo -n "Scanning ${repo}... " > /dev/stderr
ncommits=0
while read -r commit; do
((ncommits+=1))
add=0
del=0
ref=$(echo "$commit" | awk '{print $1}')
while read -r ar; do
a=$(echo "$ar" | awk '{print $1}')
d=$(echo "$ar" | awk '{print $2}')
((add+=a))
((del+=d))
done < <(git -C "$repo" log -n1 --numstat "$ref" | grep -P '^\d+')
data[${#data[@]}]="$(echo "$commit" | sed 's/^[^ ]* //') $add $del"
done < <(git -C "$repo" log \
$filter \
--pretty=format:'%h %aI' \
--abbrev-commit \
2>/dev/null)
if ((ncommits == 0)); then
echo -en "\033[2K\r" > /dev/stderr
continue
fi
echo -e "\e[32mOK\e[0m ($ncommits commits)" > /dev/stderr
done < <(find / -type d -name .git 2>/dev/null)
echo "${#data[@]} commits" > /dev/stderr
for d in "${data[@]}"; do
echo "$d"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment