Skip to content

Commit

Permalink
tools: warn about duplicates when generating AUTHORS file
Browse files Browse the repository at this point in the history
PR-URL: #40304
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
  • Loading branch information
Trott authored and targos committed Oct 13, 2021
1 parent 6c091c7 commit c3a744f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tools/update-authors.js
Expand Up @@ -11,6 +11,7 @@ class CaseIndifferentMap {
_map = new Map();

get(key) { return this._map.get(key.toLowerCase()); }
has(key) { return this._map.has(key.toLowerCase()); }
set(key, value) { return this._map.set(key.toLowerCase(), value); }
}

Expand Down Expand Up @@ -64,6 +65,30 @@ const mailmap = new CaseIndifferentMap();
}
}

const previousAuthors = new CaseIndifferentMap();
{
const lines = fs.readFileSync(path.resolve(__dirname, '../', 'AUTHORS'),
{ encoding: 'utf8' }).split('\n');
for (let line of lines) {
line = line.trim();
if (line.startsWith('#') || line === '') continue;

let match;
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) {
const name = match[1];
const email = match[2];
if (previousAuthors.has(name)) {
const emails = previousAuthors.get(name);
emails.push(email);
} else {
previousAuthors.set(name, [email]);
}
} else {
console.warn('Unknown AUTHORS format:', line);
}
}
}

const seen = new Set();

// Support regular git author metadata, as well as `Author:` and
Expand Down Expand Up @@ -93,6 +118,11 @@ rl.on('line', (line) => {

seen.add(email);
output.write(`${author} ${email}\n`);
const duplicate = previousAuthors.get(author);
if (duplicate && !duplicate.includes(email)) {
console.warn('Author name already in AUTHORS file. Possible duplicate:');
console.warn(` ${author} <${email}>`);
}
});

rl.on('close', () => {
Expand Down

0 comments on commit c3a744f

Please sign in to comment.