Skip to content

Instantly share code, notes, and snippets.

@robskillington
Last active January 14, 2019 01:28
Show Gist options
  • Save robskillington/0ac3f1e6f958d90e922b18509d039708 to your computer and use it in GitHub Desktop.
Save robskillington/0ac3f1e6f958d90e922b18509d039708 to your computer and use it in GitHub Desktop.
git log stats for author over time window with exclusion of vendor directories
#!/bin/bash
read -r -d '' REPOS << EOM
$GOPATH/src/github.com/uber-go/tally
EOM
FROM="500 weeks ago"
UNTIL="1 day ago"
curr=$(pwd)
i=0
commits=0
inserted=0
deleted=0
for repo in $(echo $REPOS | tr " " "\n"); do
for author in $(echo $AUTHORS | tr "," "\n"); do
i=$(expr $i + 1)
if [ "$(expr $i % 2)" = 0 ]; then
continue
fi
cd $repo
echo $repo
out=$(git log --shortstat --author "$author" --since "$FROM" --until "$UNTIL" -- $repo ":(exclude,glob)./oss_repos/**/*" ":(exclude,glob)./vendor/**/*" | fgrep 'file' | fgrep ' changed' | awk 'BEGIN {commits=0; inserted=0; deleted=0} {commits+=1; inserted+=$4; deleted+=$6} END {print "{\"commits\":", commits, ",\"lines_inserted\":", inserted, ", \"lines_deleted\":", deleted, "}"}')
echo $out
this_commits=$(echo $out | jq .commits)
this_inserted=$(echo $out | jq .lines_inserted)
this_deleted=$(echo $out | jq .lines_deleted)
commits=$(expr $commits + $this_commits)
inserted=$(expr $inserted + $this_inserted)
deleted=$(expr $deleted + $this_deleted)
done
done
echo "{\"total_commits\": ${commits}, \"total_inserted\": ${inserted}, \"total_deleted\": ${deleted}}"
cd $curr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment