| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | #! /bin/sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export LANG=C LC_ALL=C LC_COLLATE=C | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Load git log | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | raw_git_log="$(git log)" | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  | git_data="$(echo "$raw_git_log" | grep 'Author:' | | 
					
						
							|  |  |  |   sed -e 's/^ *Author://; s/\\//g; s/^ *//; s/ *$//; | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  |   s/ @ .*//; s/ *[<]/\t/; s/[>]//')"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Name - nick - email correspondence from log and from maintainer list | 
					
						
							|  |  |  | # Also there are a few manual entries | 
					
						
							| 
									
										
										
										
											2018-03-18 00:16:43 -05:00
										 |  |  | maintainers="$(cat "$(dirname "$0")/../maintainer-list.nix" | | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  |   grep '=' | sed -re 's/\\"/''/g; | 
					
						
							| 
									
										
										
										
											2015-12-08 19:11:43 +01:00
										 |  |  |   s/[ 	]*([^ 	=]*)[ 	]*=[ 	]*" *(.*[^ ]) *[<](.*)[>] *".*/\1\t\2\t\3/')"
 | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  | git_lines="$( ( echo "$git_data"; | 
					
						
							| 
									
										
										
										
											2014-10-07 16:25:33 +04:00
										 |  |  |     cat "$(dirname "$0")/vanity-manual-equalities.txt") | sort |uniq)"
 | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  | emails="$( | 
					
						
							|  |  |  |     ( echo "$maintainers" | cut -f 3; echo "$git_data" | cut -f 2 ) | | 
					
						
							|  |  |  |     sort | uniq | grep -E ".+@.+[.].+" | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  |     )"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fetchGithubName () { | 
					
						
							|  |  |  |     commitid="$( | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  |         echo "$raw_git_log" | grep -B3 "Author: .*[<]$1[>]" | head -n 3 | | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  |             grep '^commit ' | tail -n 1 | sed -e 's/^commit //' | 
					
						
							|  |  |  |     )"
 | 
					
						
							|  |  |  |     userid="$( | 
					
						
							|  |  |  |         curl https://github.com/NixOS/nixpkgs/commit/"$commitid" 2>/dev/null | | 
					
						
							| 
									
										
										
										
											2016-02-24 10:37:34 +01:00
										 |  |  |         grep committed -B10 | grep 'href="/' | | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  |         sed -re 's@.* href="/@@; s@".*@@' | | 
					
						
							|  |  |  | 	grep -v "/commit/" | 
					
						
							|  |  |  |     )";
 | 
					
						
							|  |  |  |     echo "$userid" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ -n "$NIXPKGS_GITHUB_NAME_CACHE" ] && { | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  |     echo "$emails" | while read email; do | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  |         line="$(grep "$email	" "$NIXPKGS_GITHUB_NAME_CACHE")" | 
					
						
							|  |  |  | 	[ -z "$line" ] && { | 
					
						
							|  |  |  |             echo "$email	$(fetchGithubName "$email")" >> \
 | 
					
						
							|  |  |  |                 "$NIXPKGS_GITHUB_NAME_CACHE" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | # For RDF | 
					
						
							|  |  |  | normalize_name () { | 
					
						
							| 
									
										
										
										
											2015-01-18 16:01:28 +03:00
										 |  |  | 	sed -e 's/%/%25/g; s/ /%20/g; s/'\''/%27/g; s/"/%22/g; s/`/%60/g; s/\^/%5e/g; ' | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | denormalize_name () { | 
					
						
							| 
									
										
										
										
											2015-01-18 16:01:28 +03:00
										 |  |  | 	sed -e 's/%20/ /g; s/%27/'\''/g; s/%22/"/g; s/%60/`/g; s/%5e/^/g; s/%25/%/g;'; | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | n3="$(mktemp --suffix .n3)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # «The same person» relation and a sorting hint | 
					
						
							|  |  |  | # Full name is something with a space | 
					
						
							|  |  |  | ( | 
					
						
							|  |  |  | echo "$git_lines" | sed -re 's@(.*)\t(.*)@<my://name/\1>	<my://can-be>	<my://name/\2>.@' | 
					
						
							|  |  |  | echo "$git_lines" | sed -re 's@(.*)\t(.*)@<my://name/\2>	<my://can-be>	<my://name/\1>.@' | 
					
						
							|  |  |  | echo "$maintainers" | sed -re 's@(.*)\t(.*)\t(.*)@<my://name/\1>	<my://can-be>	<my://name/\2>.@' | 
					
						
							|  |  |  | echo "$maintainers" | sed -re 's@(.*)\t(.*)\t(.*)@<my://name/\2>	<my://can-be>	<my://name/\3>.@' | 
					
						
							|  |  |  | echo "$maintainers" | sed -re 's@(.*)\t(.*)\t(.*)@<my://name/\3>	<my://can-be>	<my://name/\1>.@' | 
					
						
							|  |  |  | echo "$git_lines" | grep ' ' | cut -f 1 | sed -e 's@.*@<my://name/&>	<my://is-name>	<my://0>.@' | 
					
						
							|  |  |  | echo "$git_lines" | grep -v ' ' | cut -f 1 | sed -e 's@.*@<my://name/&>	<my://is-name>	<my://1>.@' | 
					
						
							|  |  |  | echo "$maintainers" | cut -f 2 | sed -e 's@.*@<my://name/&>	<my://is-name>	<my://0>.@' | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | [ -n "$NIXPKGS_GITHUB_NAME_CACHE" ] && cat "$NIXPKGS_GITHUB_NAME_CACHE" | | 
					
						
							|  |  |  |     grep -v "	$" | | 
					
						
							|  |  |  |     sed -re 's@(.*)\t(.*)@<my://name/\1>	<my://at-github>	<my://github/\2>.@' | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | ) | normalize_name | grep -E '<my://[-a-z]+>' | sort | uniq > "$n3" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Get transitive closure | 
					
						
							| 
									
										
										
										
											2014-10-05 16:16:37 +02:00
										 |  |  | sparql="$(nix-build '<nixpkgs>' -Q -A apache-jena --no-out-link)/bin/sparql" | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | name_list="$( | 
					
						
							|  |  |  | 	"$sparql" --results=TSV --data="$n3" "
 | 
					
						
							|  |  |  | 	select ?x ?y ?g where { | 
					
						
							|  |  |  | 	  ?x <my://can-be>+ ?y. | 
					
						
							|  |  |  | 	  ?x <my://is-name> ?g. | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  | 	" | tail -n +2 |
 | 
					
						
							|  |  |  | 	sed -re 's@<my://name/@@g; s@<my://@@g; s@>@@g;' | | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | 	sort -k 2,3 -t '	' | 
					
						
							|  |  |  | )"
 | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | github_name_list="$( | 
					
						
							|  |  |  | 	"$sparql" --results=TSV --data="$n3" "
 | 
					
						
							|  |  |  | 	select ?x ?y where { | 
					
						
							|  |  |  | 	  ?x (<my://can-be>+ / <my://at-github>) ?y. | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  | 	" | tail -n +2 |
 | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | 	sed -re 's@<my://(name|github)/@@g; s@<my://@@g; s@>@@g;' | 
					
						
							|  |  |  | )"
 | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Take first spelling option for every person | 
					
						
							|  |  |  | name_list_canonical="$(echo "$name_list" | cut -f 1,2 | uniq -f1)" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  | cleaner_script="$(echo "$name_list_canonical" | denormalize_name | | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  |   sed -re 's/(.*)\t(.*)/s#^\2$#\1#g/g')"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | # Add github usernames | 
					
						
							|  |  |  | if [ -n "$NIXPKGS_GITHUB_NAME_CACHE" ]; then | 
					
						
							| 
									
										
										
										
											2016-09-26 19:24:05 +02:00
										 |  |  |     github_adder_script="$(mktemp)" | 
					
						
							|  |  |  |     echo "$github_name_list" | | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  |         grep -E "$(echo "$name_list_canonical" | cut -f 2 | | 
					
						
							|  |  |  | 	    tr '\n' '|' )" |
 | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  | 	sort | uniq | | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  |         sed -re 's/(.*)\t(.*)/s| \1$| \1\t\2|g;/' | | 
					
						
							| 
									
										
										
										
											2016-09-26 19:24:05 +02:00
										 |  |  | 	denormalize_name > "$github_adder_script" | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2016-09-26 19:24:05 +02:00
										 |  |  |     github_adder_script='/dev/null' | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-24 19:54:36 +04:00
										 |  |  | echo "$name_list" | denormalize_name | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  | echo "$git_data" | cut -f 1 | | 
					
						
							| 
									
										
										
										
											2014-11-04 12:57:50 +03:00
										 |  |  |     sed -e "$cleaner_script" | | 
					
						
							| 
									
										
										
										
											2016-09-26 19:24:05 +02:00
										 |  |  |     sort | uniq -c | sort -k1n | sed -rf "$github_adder_script" | | 
					
						
							| 
									
										
										
										
											2014-10-12 23:05:14 +04:00
										 |  |  |     sed -re 's/^ *([0-9]+) /\1\t/' |