Skip to content

Commit

Permalink
tools: consolidate update-authors.js logic
Browse files Browse the repository at this point in the history
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
Trott authored and danielleadams committed Feb 1, 2022
1 parent b79fdd5 commit 599c119
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions tools/update-authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down

0 comments on commit 599c119

Please sign in to comment.