Skip to content

Instantly share code, notes, and snippets.

@mgiuffrida
Created June 5, 2017 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgiuffrida/d366a8d6d8e48ebfcf260559bae05b23 to your computer and use it in GitHub Desktop.
Save mgiuffrida/d366a8d6d8e48ebfcf260559bae05b23 to your computer and use it in GitHub Desktop.
count lines inserted by each user
#!/bin/sh
DIRS=(
chrome/browser/ui/webui/settings/
chrome/browser/resources/settings/
chrome/test/data/webui/settings/
ui/webui/resources/cr_elements/cr_dialog/
ui/webui/resources/cr_elements/policy/
ui/webui/resources/cr_elements/network/
)
FILES=(
ui/webui/resources/cr_elements/shared_style_css.html
ui/webui/resources/cr_elements/shared_vars_css.html
chrome/app/settings_*
)
set -e
START=2015-01-01
END=2017-07-01
COUNTS=""
git log --pretty=format:%h --after "$START" --before "$END" -- ${DIRS[@]} | {
while read; do
commit=$REPLY
INSERTIONS=0
#DELETIONS=0
DIFFSTATS=()
for dir in ${DIRS[@]}; do
DIFFSTATS+=("$(git show "$commit" --stat --relative="$dir" --pretty=oneline)")
done
for file in ${FILES[@]}; do
DIFFSTATS+=("$(git show "$commit" --stat --pretty=oneline "$file")")
done
for diff in "${DIFFSTATS[@]}"; do
if [[ $(echo -e "$diff" | wc -l) -lt 2 ]]; then
continue
fi
DIFFSTAT=$(echo -e "$diff" | tail -n 1)
if echo "$DIFFSTAT" | grep -q insertion; then
INSERTIONS=$((INSERTIONS + $(echo "$DIFFSTAT" | sed 's%.* \([0-9]*\) insertion.*$%\1%')))
fi
# optional: do something with deletions...
#if echo "$DIFFSTAT" | grep -q deletion; then
#DELETIONS=$((DELETIONS + $(echo "$DIFFSTAT" | sed 's%.* \([0-9]*\) deletion.*$%\1%')))
#fi
done
TOTAL=$((INSERTIONS))
#TOTAL=$((INSERTIONS - DELETIONS))
if [[ $TOTAL -gt 0 ]]; then
AUTHOR=$(git log -n 1 "$commit" --pretty='%ae')
COUNTS+="$AUTHOR $TOTAL\n"
fi
done;
echo -e "$COUNTS" | awk '{a[$1]+=$2}END{for(i in a) print a[i], i}' | grep -v '^0$' | sort -n
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment