Skip to content

Commit 55b8304

Browse files
addaleaxBridgeAR
authored andcommitted
tools: add mailmap support for Co-authored-by tags
Support `.mailmap` for manually added `Author:` and `Co-authored-by:` tags. PR-URL: #26383 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent dc2119a commit 55b8304

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

‎tools/update-authors.js‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'.
44
'use strict';
55
const{ spawn }=require('child_process');
6+
constpath=require('path');
67
constfs=require('fs');
78
constreadline=require('readline');
89

@@ -22,6 +23,38 @@ else
2223

2324
output.write('# Authors ordered by first contribution.\n\n');
2425

26+
constmailmap=newMap();
27+
{
28+
constlines=fs.readFileSync(path.resolve(__dirname,'../','.mailmap'),
29+
{encoding: 'utf8'}).split('\n');
30+
for(letlineoflines){
31+
line=line.trim();
32+
if(line.startsWith('#')||line==='')continue;
33+
34+
letmatch;
35+
// Replaced Name <original@example.com>
36+
if(match=line.match(/^([^<]+)\s+(<[^>]+>)$/)){
37+
mailmap.set(match[2],{author: match[1]});
38+
// <replaced@example.com> <original@example.com>
39+
}elseif(match=line.match(/^<([^>]+)>\s+(<[^>]+>)$/)){
40+
mailmap.set(match[2],{email: match[1]});
41+
// Replaced Name <replaced@example.com> <original@example.com>
42+
}elseif(match=line.match(/^([^<]+)\s+(<[^>]+>)\s+(<[^>]+>)$/)){
43+
mailmap.set(match[3],{
44+
author: match[1],email: match[2]
45+
});
46+
// Replaced Name <replaced@example.com> Original Name <original@example.com>
47+
}elseif(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+
2558
constseen=newSet();
2659

2760
// Support regular git author metadata, as well as `Author:` and
@@ -34,7 +67,13 @@ rl.on('line', (line) => {
3467
constmatch=line.match(authorRe);
3568
if(!match)return;
3669

37-
const{ author, email }=match.groups;
70+
let{ author, email }=match.groups;
71+
72+
constreplacement=mailmap.get(author+'\0'+email)||mailmap.get(email);
73+
if(replacement){
74+
({ author, email }={ author, email, ...replacement});
75+
}
76+
3877
if(seen.has(email)||
3978
/@chromium\.org/.test(email)||
4079
email==='<erik.corry@gmail.com>'){

0 commit comments

Comments
 (0)