Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: warn about duplicates when generating AUTHORS file #40304

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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); }
Comment on lines 13 to 15
Copy link
Contributor

@aduh95 aduh95 Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be using localeCompare if we are passing names in addition to email addresses?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes you say that?

Copy link
Member Author

@Trott Trott Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asking my question another way: How/where would it be used? We're not comparing anything, at least not explicitly. Can you either show some code (or pseudocode) and/or some name/email addresses that would be a problem if we don't use localeCompare? I'm not clear on what the benefit is in this context or even how it would be used.

}

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