forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: add mailmap support for Co-authored-by tags
Support `.mailmap` for manually added `Author:` and `Co-authored-by:` tags. PR-URL: nodejs#26383 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
Showing
1 changed file
with
40 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'. | ||
'use strict'; | ||
const { spawn } = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const readline = require('readline'); | ||
|
||
|
@@ -22,6 +23,38 @@ else | |
|
||
output.write('# Authors ordered by first contribution.\n\n'); | ||
|
||
const mailmap = new Map(); | ||
{ | ||
const lines = fs.readFileSync(path.resolve(__dirname, '../', '.mailmap'), | ||
{ encoding: 'utf8' }).split('\n'); | ||
for (let line of lines) { | ||
line = line.trim(); | ||
if (line.startsWith('#') || line === '') continue; | ||
|
||
let match; | ||
// Replaced Name <[email protected]> | ||
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) { | ||
mailmap.set(match[2], { author: match[1] }); | ||
// <[email protected]> <[email protected]> | ||
} else if (match = line.match(/^<([^>]+)>\s+(<[^>]+>)$/)) { | ||
mailmap.set(match[2], { email: match[1] }); | ||
// Replaced Name <[email protected]> <[email protected]> | ||
} else if (match = line.match(/^([^<]+)\s+(<[^>]+>)\s+(<[^>]+>)$/)) { | ||
mailmap.set(match[3], { | ||
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], { | ||
author: match[1], email: match[2] | ||
}); | ||
} else { | ||
console.warn('Unknown .mailmap format:', line); | ||
} | ||
} | ||
} | ||
|
||
const seen = new Set(); | ||
|
||
// Support regular git author metadata, as well as `Author:` and | ||
|
@@ -34,7 +67,13 @@ rl.on('line', (line) => { | |
const match = line.match(authorRe); | ||
if (!match) return; | ||
|
||
const { author, email } = match.groups; | ||
let { author, email } = match.groups; | ||
|
||
const replacement = mailmap.get(author + '\0' + email) || mailmap.get(email); | ||
if (replacement) { | ||
({ author, email } = { author, email, ...replacement }); | ||
} | ||
|
||
if (seen.has(email) || | ||
/@chromium\.org/.test(email) || | ||
email === '<[email protected]>') { | ||
|