Skip to content

Instantly share code, notes, and snippets.

@commonquail
Created August 4, 2015 12:01
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 commonquail/32c62ee9fcd989fdd8c4 to your computer and use it in GitHub Desktop.
Save commonquail/32c62ee9fcd989fdd8c4 to your computer and use it in GitHub Desktop.
Very simple commit message stats
#!/bin/bash
set -o errexit
set -o nounset
[[ $# -eq 1 ]] || {
echo "usage: $0 <author>"
exit 1
}
author=$1
# Calculates $part's percentage of $total.
#
# Arguments:
# - outvar: the name of an out-variable to store the result in
# - float: the $part of $total
# - float: the $total
pct_of()
{
local _outvar=$1
local _in_part=$2
local _in_total=$3
eval $_outvar="$(echo "scale=4; ${_in_part} / ${_in_total} * 100" | bc)"
}
# Cleans up Git's log messages.
#
# Extracts only the message bodies and
# filters out any occurrences of git-svn-id.
#
# Arguments:
# - string: an optional author name to pass to git log --author=
clean_git_log()
{
git log --author=${1:-} --format=%B | grep -v ^git-svn-id
}
#
# Arguments:
# - string: the name of the count statistic
# - int: the current statistic's total
# - int: the part of the statistic's total the author is responsible for
print_counts()
{
local _in_category=$1
local _in_total=$2
local _in_author=$3
pct_of _pct ${_in_author} ${_in_total}
printf "${_in_category} Counts\n"
printf "%-6s\t%-6s\t%5s\n" "Total" "Author" "%"
printf "%6d\t%6d\t%5.2f\n" ${_in_total} ${_in_author} ${_pct}
}
total_commit_count=$(git rev-list HEAD --count)
author_commit_count=$(git rev-list HEAD --count --author=${author})
total_word_count=$(clean_git_log | wc -w)
author_word_count=$(clean_git_log ${author} | wc -w)
total_char_count=$(clean_git_log | wc -c)
author_char_count=$(clean_git_log ${author} | wc -c)
print_counts "Commit" ${total_commit_count} ${author_commit_count}
echo
print_counts "Word" ${total_word_count} ${author_word_count}
echo
print_counts "Character" ${total_char_count} ${author_char_count}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment