-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
- Loading branch information
1 parent
b79fdd5
commit 599c119
Showing
1 changed file
with
9 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,25 +39,13 @@ const mailmap = new CaseIndifferentMap(); | |
line = line.trim(); | ||
if (line.startsWith('#') || line === '') continue; | ||
|
||
let match; | ||
// Replaced Name <[email protected]> | ||
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) { | ||
mailmap.set(match[2].toLowerCase(), { | ||
author: match[1], email: match[2] | ||
}); | ||
// <[email protected]> <[email protected]> | ||
} else if (match = line.match(/^<([^>]+)>\s+(<[^>]+>)$/)) { | ||
mailmap.set(match[2].toLowerCase(), { email: match[1] }); | ||
// Replaced Name <[email protected]> <[email protected]> | ||
} else if (match = line.match(/^([^<]+)\s+(<[^>]+>)\s+(<[^>]+>)$/)) { | ||
mailmap.set(match[3].toLowerCase(), { | ||
author: match[1], email: match[2] | ||
}); | ||
// Replaced Name <[email protected]> Original Name <[email protected]> | ||
} else if (match = | ||
line.match(/^([^<]+)\s+(<[^>]+>)\s+([^<]+)\s+(<[^>]+>)$/)) { | ||
mailmap.set(match[3] + '\0' + match[4].toLowerCase(), { | ||
author: match[1], email: match[2] | ||
const match = line.match(/^(?:([^<]+)\s+)?(?:(<[^>]+>)\s+)?(?:([^<]+)\s+)?(<[^>]+>)$/); | ||
if (match) { | ||
const [, replaceName, replaceEmail, originalName, originalEmail] = match; | ||
const key = originalName ? `${originalName}\0${originalEmail.toLocaleLowerCase()}` : originalEmail.toLowerCase(); | ||
mailmap.set(key, { | ||
author: replaceName || originalName, | ||
email: replaceEmail || originalEmail, | ||
}); | ||
} else { | ||
console.warn('Unknown .mailmap format:', line); | ||
|
@@ -73,8 +61,8 @@ const previousAuthors = new CaseIndifferentMap(); | |
line = line.trim(); | ||
if (line.startsWith('#') || line === '') continue; | ||
|
||
let match; | ||
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) { | ||
const match = line.match(/^([^<]+)\s+(<[^>]+>)$/); | ||
if (match) { | ||
const name = match[1]; | ||
const email = match[2]; | ||
if (previousAuthors.has(name)) { | ||
|