You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vanity.sh 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #! /bin/sh
  2. export LANG=C LC_ALL=C LC_COLLATE=C
  3. # Load git log
  4. raw_git_log="$(git log)"
  5. git_data="$(echo "$raw_git_log" | grep 'Author:' |
  6. sed -e 's/^ *Author://; s/\\//g; s/^ *//; s/ *$//;
  7. s/ @ .*//; s/ *[<]/\t/; s/[>]//')"
  8. # Name - nick - email correspondence from log and from maintainer list
  9. # Also there are a few manual entries
  10. maintainers="$(cat "$(dirname "$0")/../maintainer-list.nix" |
  11. grep '=' | sed -re 's/\\"/''/g;
  12. s/[ ]*([^ =]*)[ ]*=[ ]*" *(.*[^ ]) *[<](.*)[>] *".*/\1\t\2\t\3/')"
  13. git_lines="$( ( echo "$git_data";
  14. cat "$(dirname "$0")/vanity-manual-equalities.txt") | sort |uniq)"
  15. emails="$(
  16. ( echo "$maintainers" | cut -f 3; echo "$git_data" | cut -f 2 ) |
  17. sort | uniq | grep -E ".+@.+[.].+"
  18. )"
  19. fetchGithubName () {
  20. commitid="$(
  21. echo "$raw_git_log" | grep -B3 "Author: .*[<]$1[>]" | head -n 3 |
  22. grep '^commit ' | tail -n 1 | sed -e 's/^commit //'
  23. )"
  24. userid="$(
  25. curl https://github.com/NixOS/nixpkgs/commit/"$commitid" 2>/dev/null |
  26. grep committed -B10 | grep 'href="/' |
  27. sed -re 's@.* href="/@@; s@".*@@' |
  28. grep -v "/commit/"
  29. )";
  30. echo "$userid"
  31. }
  32. [ -n "$NIXPKGS_GITHUB_NAME_CACHE" ] && {
  33. echo "$emails" | while read email; do
  34. line="$(grep "$email " "$NIXPKGS_GITHUB_NAME_CACHE")"
  35. [ -z "$line" ] && {
  36. echo "$email $(fetchGithubName "$email")" >> \
  37. "$NIXPKGS_GITHUB_NAME_CACHE"
  38. }
  39. done
  40. }
  41. # For RDF
  42. normalize_name () {
  43. sed -e 's/%/%25/g; s/ /%20/g; s/'\''/%27/g; s/"/%22/g; s/`/%60/g; s/\^/%5e/g; '
  44. }
  45. denormalize_name () {
  46. sed -e 's/%20/ /g; s/%27/'\''/g; s/%22/"/g; s/%60/`/g; s/%5e/^/g; s/%25/%/g;';
  47. }
  48. n3="$(mktemp --suffix .n3)"
  49. # «The same person» relation and a sorting hint
  50. # Full name is something with a space
  51. (
  52. echo "$git_lines" | sed -re 's@(.*)\t(.*)@<my://name/\1> <my://can-be> <my://name/\2>.@'
  53. echo "$git_lines" | sed -re 's@(.*)\t(.*)@<my://name/\2> <my://can-be> <my://name/\1>.@'
  54. echo "$maintainers" | sed -re 's@(.*)\t(.*)\t(.*)@<my://name/\1> <my://can-be> <my://name/\2>.@'
  55. echo "$maintainers" | sed -re 's@(.*)\t(.*)\t(.*)@<my://name/\2> <my://can-be> <my://name/\3>.@'
  56. echo "$maintainers" | sed -re 's@(.*)\t(.*)\t(.*)@<my://name/\3> <my://can-be> <my://name/\1>.@'
  57. echo "$git_lines" | grep ' ' | cut -f 1 | sed -e 's@.*@<my://name/&> <my://is-name> <my://0>.@'
  58. echo "$git_lines" | grep -v ' ' | cut -f 1 | sed -e 's@.*@<my://name/&> <my://is-name> <my://1>.@'
  59. echo "$maintainers" | cut -f 2 | sed -e 's@.*@<my://name/&> <my://is-name> <my://0>.@'
  60. [ -n "$NIXPKGS_GITHUB_NAME_CACHE" ] && cat "$NIXPKGS_GITHUB_NAME_CACHE" |
  61. grep -v " $" |
  62. sed -re 's@(.*)\t(.*)@<my://name/\1> <my://at-github> <my://github/\2>.@'
  63. ) | normalize_name | grep -E '<my://[-a-z]+>' | sort | uniq > "$n3"
  64. # Get transitive closure
  65. sparql="$(nix-build '<nixpkgs>' -Q -A apache-jena --no-out-link)/bin/sparql"
  66. name_list="$(
  67. "$sparql" --results=TSV --data="$n3" "
  68. select ?x ?y ?g where {
  69. ?x <my://can-be>+ ?y.
  70. ?x <my://is-name> ?g.
  71. }
  72. " | tail -n +2 |
  73. sed -re 's@<my://name/@@g; s@<my://@@g; s@>@@g;' |
  74. sort -k 2,3 -t ' '
  75. )"
  76. github_name_list="$(
  77. "$sparql" --results=TSV --data="$n3" "
  78. select ?x ?y where {
  79. ?x (<my://can-be>+ / <my://at-github>) ?y.
  80. }
  81. " | tail -n +2 |
  82. sed -re 's@<my://(name|github)/@@g; s@<my://@@g; s@>@@g;'
  83. )"
  84. # Take first spelling option for every person
  85. name_list_canonical="$(echo "$name_list" | cut -f 1,2 | uniq -f1)"
  86. cleaner_script="$(echo "$name_list_canonical" | denormalize_name |
  87. sed -re 's/(.*)\t(.*)/s#^\2$#\1#g/g')"
  88. # Add github usernames
  89. if [ -n "$NIXPKGS_GITHUB_NAME_CACHE" ]; then
  90. github_adder_script="$(mktemp)"
  91. echo "$github_name_list" |
  92. grep -E "$(echo "$name_list_canonical" | cut -f 2 |
  93. tr '\n' '|' )" |
  94. sort | uniq |
  95. sed -re 's/(.*)\t(.*)/s| \1$| \1\t\2|g;/' |
  96. denormalize_name > "$github_adder_script"
  97. else
  98. github_adder_script='/dev/null'
  99. fi
  100. echo "$name_list" | denormalize_name
  101. echo
  102. echo "$git_data" | cut -f 1 |
  103. sed -e "$cleaner_script" |
  104. sort | uniq -c | sort -k1n | sed -rf "$github_adder_script" |
  105. sed -re 's/^ *([0-9]+) /\1\t/'