Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / script / credits.sh
1 #!/bin/sh
2
3 range="$1"
4 TMP=/tmp/credits
5 declare -A mail2author
6 declare -A mail2organization
7 remap="s/'/ /g"
8 git log --pretty='%ae %aN <%aE>' $range | sed -e "$remap" | sort -u > $TMP
9 while read mail who ; do
10     author=$(echo $who | git -c mailmap.file=.peoplemap check-mailmap --stdin)
11     mail2author[$mail]="$author"
12     organization=$(echo $who | git -c mailmap.file=.organizationmap check-mailmap --stdin)
13     mail2organization[$mail]="$organization"
14 done < $TMP
15 declare -A author2lines
16 declare -A organization2lines
17 git log --no-merges --pretty='%ae' $range | sed -e "$remap" | sort -u > $TMP
18 while read mail ; do 
19     count=$(git log --numstat --author="$mail" --pretty='%h' $range | 
20         perl -e 'while(<STDIN>) { if(/(\d+)\t(\d+)/) { $added += $1; $deleted += $2 } }; print $added + $deleted;')
21     (( author2lines["${mail2author[$mail]}"] += $count ))
22     (( organization2lines["${mail2organization[$mail]}"] += $count ))
23 done < $TMP
24 echo
25 echo "Number of lines added and removed, by authors"
26 for author in "${!author2lines[@]}" ; do
27     printf "%6s %s\n" ${author2lines["$author"]} "$author"
28 done | sort -rn | nl
29 echo
30 echo "Number of lines added and removed, by organization"
31 for organization in "${!organization2lines[@]}" ; do
32     printf "%6s %s\n" ${organization2lines["$organization"]} "$organization"
33 done | sort -rn | nl
34 echo
35 echo "Commits, by authors"
36 git log --no-merges --pretty='%aN <%aE>' $range | git -c mailmap.file=.peoplemap check-mailmap --stdin | sort | uniq -c | sort -rn | nl
37 echo
38 echo "Commits, by organizations"
39 git log --no-merges --pretty='%aN <%aE>' $range | git -c mailmap.file=.organizationmap check-mailmap --stdin | sort | uniq -c | sort -rn | nl
40 echo
41 echo "Reviews, by authors (one review spans multiple commits)"
42 git log --pretty=%b $range | perl -n -e 'print "$_\n" if(s/^\s*Reviewed-by:\s*(.*<.*>)\s*$/\1/i)' | git check-mailmap --stdin | git -c mailmap.file=.peoplemap check-mailmap --stdin | sort | uniq -c | sort -rn | nl
43 echo
44 echo "Reviews, by organizations (one review spans multiple commits)"
45 git log --pretty=%b $range | perl -n -e 'print "$_\n" if(s/^\s*Reviewed-by:\s*(.*<.*>)\s*$/\1/i)' | git check-mailmap --stdin | git -c mailmap.file=.organizationmap check-mailmap --stdin | sort | uniq -c | sort -rn | nl