1
0

list-contributors.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. FORMAT="%aN,<%aE>" #Set git output format in "Name,<Email>" //Capital in aN and aE means replace str based on .mailmap
  3. TARGET=(examples lkmpg.tex) #Target files we want to trace
  4. DIR=`git rev-parse --show-toplevel` #Get root dir of the repo
  5. TARGET=("${TARGET[@]/#/$DIR/}") #Concat $DIR BEFORE ALL elements in array TARGET
  6. #The str in each line should be Username,<useremail>
  7. function gen-raw-list()
  8. {
  9. git log --pretty="$FORMAT" ${TARGET[@]} | sort -u
  10. }
  11. function parse-list()
  12. {
  13. > Contributors # Clear contributors' list (Overwrite with null)
  14. while read -r line; do
  15. User=`echo "$line" | awk -F "," '{print $1}'`
  16. if [[ `grep -w "$User" Exclude` ]]; then
  17. echo "[skip] $User"
  18. continue;
  19. fi
  20. echo "[Add] $User"
  21. MainMail=`echo "$line" | awk -F "[<*>]" '{print $2}'`
  22. Emails=(`cat $DIR/.mailmap | grep -w "$User" | awk -F "[<*>]" '{print $4}' | sort -u`)
  23. for Email in ${Emails[@]}; do
  24. if [[ "$Email" != "$MainMail" ]]; then
  25. line="$line,<$Email>";
  26. fi
  27. done
  28. echo "$line" >> Contributors
  29. done <<< $(gen-raw-list)
  30. cat Include >> Contributors
  31. }
  32. function sort-list()
  33. {
  34. if [[ `git diff Contributors` ]]; then
  35. sort -f -o Contributors{,}
  36. git add $DIR/scripts/Contributors
  37. fi
  38. }
  39. #For all lines before endline, print "name, % <email>"
  40. #For endline print "name. % <email>"
  41. function gen-tex-file()
  42. {
  43. cat Contributors | awk -F "," \
  44. ' BEGIN{k=0}{name[k]=$1;email[k++]=$2}
  45. END{
  46. for(i=0;i<k;i++){
  47. name[i]=(i<k-1)?name[i]",":name[i]".";
  48. printf("%-30s %% %s\n",name[i],email[i]);
  49. }
  50. }
  51. '
  52. }
  53. parse-list
  54. sort-list
  55. gen-tex-file > $DIR/contrib.tex