Last active
December 21, 2023 03:41
-
-
Save pinealan/b73acee32f29c594c19ebd54dbd7c357 to your computer and use it in GitHub Desktop.
Parse git log stats and give an overview of daily repo changes
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 | |
OPT="" | |
AUTHOR="" | |
for i in "$@"; do | |
case $i in | |
-a|--all) | |
OPT+="--all" | |
OPT+=" " | |
shift;; | |
-A=*|--author=*) | |
AUTHOR=${i#*=} | |
AUTHOR=--author=$AUTHOR | |
shift;; | |
esac | |
done | |
git log $OPT $AUTHOR --stat \ | |
| grep "file changed\|files changed\|Date" \ | |
| awk ' | |
# Record the date of a new commit | |
$1 ~ /Date\:/ { | |
date = ($2 " " $3 " " $4); | |
commits[date] += 1; | |
} | |
# Record the insertions and deletions in the commit | |
/files changed/ || /file changed/ { | |
if ($5 ~ /insertions/) { | |
inserts[date] += $4; | |
} | |
if ($5 ~ /deletions/) { | |
deletes[date] += $4; | |
} | |
if ($7 ~ /deletions/) { | |
deletes[date] += $6; | |
} | |
} | |
# Print out the summary | |
END { | |
for (i in commits){ | |
printf "%-11s: %2i commits, %6i inserts(+), %6i deletes(-), %6i net\n", i, commits[i], inserts[i], deletes[i], inserts[i] - deletes[i]; | |
} | |
}' \ | |
| sort -k2Mr -k3gr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment