3
3
// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'.
4
4
'use strict' ;
5
5
const { spawn } = require ( 'child_process' ) ;
6
+ const path = require ( 'path' ) ;
6
7
const fs = require ( 'fs' ) ;
7
8
const readline = require ( 'readline' ) ;
8
9
22
23
23
24
output . write ( '# Authors ordered by first contribution.\n\n' ) ;
24
25
26
+ const mailmap = new Map ( ) ;
27
+ {
28
+ const lines = fs . readFileSync ( path . resolve ( __dirname , '../' , '.mailmap' ) ,
29
+ { encoding : 'utf8' } ) . split ( '\n' ) ;
30
+ for ( let line of lines ) {
31
+ line = line . trim ( ) ;
32
+ if ( line . startsWith ( '#' ) || line === '' ) continue ;
33
+
34
+ let match ;
35
+ // Replaced Name <[email protected] >
36
+ if ( match = line . match ( / ^ ( [ ^ < ] + ) \s + ( < [ ^ > ] + > ) $ / ) ) {
37
+ mailmap . set ( match [ 2 ] , { author : match [ 1 ] } ) ;
38
+
39
+ } else if ( match = line . match ( / ^ < ( [ ^ > ] + ) > \s + ( < [ ^ > ] + > ) $ / ) ) {
40
+ mailmap . set ( match [ 2 ] , { email : match [ 1 ] } ) ;
41
+
42
+ } else if ( match = line . match ( / ^ ( [ ^ < ] + ) \s + ( < [ ^ > ] + > ) \s + ( < [ ^ > ] + > ) $ / ) ) {
43
+ mailmap . set ( match [ 3 ] , {
44
+ author : match [ 1 ] , email : match [ 2 ]
45
+ } ) ;
46
+ // Replaced Name <[email protected] > Original Name <[email protected] >
47
+ } else if ( match =
48
+ line . match ( / ^ ( [ ^ < ] + ) \s + ( < [ ^ > ] + > ) \s + ( [ ^ < ] + ) \s + ( < [ ^ > ] + > ) $ / ) ) {
49
+ mailmap . set ( match [ 3 ] + '\0' + match [ 4 ] , {
50
+ author : match [ 1 ] , email : match [ 2 ]
51
+ } ) ;
52
+ } else {
53
+ console . warn ( 'Unknown .mailmap format:' , line ) ;
54
+ }
55
+ }
56
+ }
57
+
25
58
const seen = new Set ( ) ;
26
59
27
60
// Support regular git author metadata, as well as `Author:` and
@@ -34,7 +67,13 @@ rl.on('line', (line) => {
34
67
const match = line . match ( authorRe ) ;
35
68
if ( ! match ) return ;
36
69
37
- const { author, email } = match . groups ;
70
+ let { author, email } = match . groups ;
71
+
72
+ const replacement = mailmap . get ( author + '\0' + email ) || mailmap . get ( email ) ;
73
+ if ( replacement ) {
74
+ ( { author, email } = { author, email, ...replacement } ) ;
75
+ }
76
+
38
77
if ( seen . has ( email ) ||
39
78
/ @ c h r o m i u m \. o r g / . test ( email ) ||
40
79
email === '<[email protected] >' ) {
0 commit comments