Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 46b364a

Browse filesBrowse files
Trotttargos
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 fe21607 commit 46b364a
Copy full SHA for 46b364a

File tree

Expand file treeCollapse file tree

1 file changed

+9
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-21
lines changed
Open diff view settings
Collapse file

‎tools/update-authors.js‎

Copy file name to clipboardExpand all lines: tools/update-authors.js
+9-21Lines 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-
let match;
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-
} else if (match = line.match(/^<([^>]+)>\s+(<[^>]+>)$/)) {
50-
mailmap.set(match[2].toLowerCase(), { email: match[1] });
51-
// Replaced Name <replaced@example.com> <original@example.com>
52-
} else if (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-
} else if (match =
58-
line.match(/^([^<]+)\s+(<[^>]+>)\s+([^<]+)\s+(<[^>]+>)$/)) {
59-
mailmap.set(match[3] + '\0' + match[4].toLowerCase(), {
60-
author: match[1], email: match[2]
42+
const match = line.match(/^(?:([^<]+)\s+)?(?:(<[^>]+>)\s+)?(?:([^<]+)\s+)?(<[^>]+>)$/);
43+
if (match) {
44+
const [, replaceName, replaceEmail, originalName, originalEmail] = match;
45+
const key = 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-
let match;
77-
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) {
64+
const match = line.match(/^([^<]+)\s+(<[^>]+>)$/);
65+
if (match) {
7866
const name = match[1];
7967
const email = match[2];
8068
if (previousAuthors.has(name)) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.