Created
August 23, 2015 17:52
-
-
Save enten/c4f9e35279c1278844c3 to your computer and use it in GitHub Desktop.
Create MAINTAINERS file from git commits
This file contains hidden or 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/sh | |
# contributors: Generate MAINTAINERS content from git commits | |
# | |
# Author: Steven Enten <[email protected]> | |
# License : MIT | |
# Requirements: dirname cat echo eval grep read readlink shift tail | |
# Site: https//github.com/enten/losh | |
set -u | |
# | |
# consts | |
# | |
CMDDESC="Generate MAINTAINERS content from git commits" | |
FILE= | |
# | |
# vars | |
# | |
buffer= | |
tmp= | |
# | |
# initialize vars | |
# | |
init() { | |
tmp=$(dirname $(readlink -f $(echo $0))) | |
while [ ! -f "$tmp/MAINTAINERS" ]; do | |
tmp=$(dirname $tmp) | |
[ "$tmp" = "/" ] && break | |
done | |
[ ! -f "$tmp/MAINTAINERS" ] && echo "MAINTAINERS was not found" && exit 1 | |
FILE="$tmp/MAINTAINERS" | |
return 0 | |
} | |
# | |
# Add new maintainer into MAINTAINERS | |
# | |
add_maintainer() { | |
echo $buffer | grep -q "$1" | |
if [ $? -ne 0 ]; then | |
[ -z "$buffer" ] && buffer="$1" || buffer="$buffer $1" | |
tmp=$(echo "git log --author='$1'") | |
echo "$1 (since $(eval $tmp --format='%aD' | tail -n 1), $(eval $tmp --format='%ar' | tail -n 1))" >> $FILE | |
fi | |
} | |
# | |
# Generate MAINTAINERS file | |
# | |
update_maintainers() { | |
echo "# Last update: $(date)" > $FILE | |
buffer= | |
git log --format='%an <%ae>' > $FILE.tmp | |
while read i; do | |
add_maintainer "$i" | |
done < $FILE.tmp | |
rm -f $FILE.tmp | |
} | |
# | |
# Print MAINTAINERS content | |
# | |
print_maintainers() { | |
cat $FILE | |
} | |
# | |
# One main to rull them all | |
# | |
main() { | |
init | |
update_maintainers | |
print_maintainers | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment