-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathadd-authors
executable file
·20 lines (20 loc) · 951 Bytes
/
add-authors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
mark=$BASHPID
for i in `git ls-files|grep -v -x -F -f update-copyright-blacklist`
do
if [ -f $i -a ! -L $i ]
then
AUTHORS=$(git shortlog -n -s $i| cut -c8- | while read author; do git log -w -b --shortstat --author="$author" $i | grep -E "fil(e|es) changed" | awk "{files+=\$1; inserted+=\$4; deleted+=\$6} END {if(!(files==inserted && files==deleted) || !(files==1 && inserted==1 && deleted==0)) {print \"$author\"}}"; done | sed -e 's/$/,/g' | tr '[\n]' '[ ]' | sed -e 's/, $//g')
PLURAL=$(echo $AUTHORS | sed -e 's/[^,]*//g' -e 's/,,*/,/g' | tr [,] [s])
if grep -q 'Authors*:' $i
then
echo "update author in $i"
sed -e 's/Authors*: \(.*\)^/Author'"$PLURAL"': '"$AUTHORS"'/g' <$i >$i.$mark
else
echo "add author in $i"
sed -e 's/\(.*\)\(Copyright .* Free Software Foundation, Inc\.\)/\1Author'"$PLURAL"': '"$AUTHORS"'\n\1\2/g' <$i >$i.$mark
fi
chmod --reference=$i $i.$mark
mv $i.$mark $i
fi
done