Skip to content

Commit 599c119

Browse files
Trottdanielleadams
authored andcommitted
tools: consolidate update-authors.js logic
Use a single regex and fewer logical branches in the code. PR-URL: #41255 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
1 parent b79fdd5 commit 599c119

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

‎tools/update-authors.js‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,13 @@ const mailmap = new CaseIndifferentMap();
3939
line=line.trim();
4040
if(line.startsWith('#')||line==='')continue;
4141

42-
letmatch;
43-
// Replaced Name <original@example.com>
44-
if(match=line.match(/^([^<]+)\s+(<[^>]+>)$/)){
45-
mailmap.set(match[2].toLowerCase(),{
46-
author: match[1],email: match[2]
47-
});
48-
// <replaced@example.com> <original@example.com>
49-
}elseif(match=line.match(/^<([^>]+)>\s+(<[^>]+>)$/)){
50-
mailmap.set(match[2].toLowerCase(),{email: match[1]});
51-
// Replaced Name <replaced@example.com> <original@example.com>
52-
}elseif(match=line.match(/^([^<]+)\s+(<[^>]+>)\s+(<[^>]+>)$/)){
53-
mailmap.set(match[3].toLowerCase(),{
54-
author: match[1],email: match[2]
55-
});
56-
// Replaced Name <replaced@example.com> Original Name <original@example.com>
57-
}elseif(match=
58-
line.match(/^([^<]+)\s+(<[^>]+>)\s+([^<]+)\s+(<[^>]+>)$/)){
59-
mailmap.set(match[3]+'\0'+match[4].toLowerCase(),{
60-
author: match[1],email: match[2]
42+
constmatch=line.match(/^(?:([^<]+)\s+)?(?:(<[^>]+>)\s+)?(?:([^<]+)\s+)?(<[^>]+>)$/);
43+
if(match){
44+
const[,replaceName,replaceEmail,originalName,originalEmail]=match;
45+
constkey=originalName ? `${originalName}\0${originalEmail.toLocaleLowerCase()}` : originalEmail.toLowerCase();
46+
mailmap.set(key,{
47+
author: replaceName||originalName,
48+
email: replaceEmail||originalEmail,
6149
});
6250
}else{
6351
console.warn('Unknown .mailmap format:',line);
@@ -73,8 +61,8 @@ const previousAuthors = new CaseIndifferentMap();
7361
line=line.trim();
7462
if(line.startsWith('#')||line==='')continue;
7563

76-
letmatch;
77-
if(match=line.match(/^([^<]+)\s+(<[^>]+>)$/)){
64+
constmatch=line.match(/^([^<]+)\s+(<[^>]+>)$/);
65+
if(match){
7866
constname=match[1];
7967
constemail=match[2];
8068
if(previousAuthors.has(name)){

0 commit comments

Comments
 (0)