Last active
January 19, 2017 18:54
-
-
Save luismrsilva/53a38fcd1797cc287e2b1468e9241072 to your computer and use it in GitHub Desktop.
Estimate git repository working hours by adding time between commits (for a given optional author)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Estimate repository working hours by adding time between commits. | |
# If diference between two commits is larger than THRESHOLD, PRECOMMIT_TIME is used instead. | |
# 2016-06-06 luismrsilva | |
# (c) 2016 by Luís Silva. | |
# Disclamer: use at your own risk. | |
# First argument: optional commit author. (see man git-log, --author=<pattern>) | |
AUTHOR_PATTERN=$1 | |
### Config ### | |
# Time (seconds) to add when diff exceeds threshold | |
PRECOMMIT_TIME=3600 | |
# Ignore diff > than this (seconds): | |
THRESHOLD=$((5*3600)) | |
### --- ### | |
COMMIT_COUNT=0 | |
TOTAL=0 | |
IGNORED=0 | |
LINES=$(git log --author="$AUTHOR_PATTERN" --format="%at" --reverse | sort) | |
for l in $LINES; do | |
TIME=$((l-LAST)) | |
# Show the commit date | |
echo -n $(date +%c -d@${l}) | |
echo -ne "\t" | |
echo -ne $TIME "\t\t~" $((TIME/60/60))h | |
if [ $TIME -lt $THRESHOLD ]; then | |
echo | |
TOTAL=$((TOTAL+TIME)) | |
else | |
echo -e "\t(ignoring)" | |
IGNORED=$((IGNORED+1)) | |
fi | |
LAST=$l | |
COMMIT_COUNT=$((COMMIT_COUNT+1)) | |
done | |
echo "======" | |
if [ "$AUTHOR_PATTERN" = "" ]; then | |
echo "Considering all $COMMIT_COUNT commits." | |
else | |
echo "Considering $COMMIT_COUNT commits for author with pattern \"$AUTHOR_PATTERN\"." | |
fi | |
echo "======" | |
echo "In seconds: $TOTAL" | |
echo "In hours: " $((TOTAL/60/60)) | |
echo "# ignored: $IGNORED" | |
echo "Grand total in hours: " $(((TOTAL + IGNORED*PRECOMMIT_TIME)/60/60)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment