Skip to content

Instantly share code, notes, and snippets.

@enten
Created August 23, 2015 17:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enten/c4f9e35279c1278844c3 to your computer and use it in GitHub Desktop.
Save enten/c4f9e35279c1278844c3 to your computer and use it in GitHub Desktop.
Create MAINTAINERS file from git commits
#!/bin/sh
# contributors: Generate MAINTAINERS content from git commits
#
# Author: Steven Enten <steven@enten.fr>
# 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