Skip to content

Commit 04ff547

Browse files
committed
Improve unification of contributors by taking the lower-case email as identity
Additionally we sort contributors by name in case they have the same amount of commits to assure stable results, which may help in some cases where similar commits counts would be displayed as they are in the top 3.
1 parent a5ab965 commit 04ff547

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/info/repo.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,22 @@ pub struct Repo<'a> {
2323
time_of_first_commit: git::actor::Time,
2424
}
2525

26-
#[derive(Hash, PartialEq, Eq)]
26+
#[derive(Hash, PartialEq, Eq, Ord, PartialOrd)]
2727
pub struct Sig {
2828
name: git::bstr::BString,
2929
email: git::bstr::BString,
3030
}
3131

3232
impl From<git::actor::Signature> for Sig {
33-
fn from(git::actor::Signature { name, email, .. }: git::actor::Signature) -> Self {
33+
fn from(
34+
git::actor::Signature {
35+
name, mut email, ..
36+
}: git::actor::Signature,
37+
) -> Self {
38+
// authors who aren't mail-mapped would otherwise seem dissimilar if the email case is different.
39+
// Explicitly lower-casing it normalizes for that.
40+
// This comes at the cost of displaying only lower-case emails as well, which seems beneficial.
41+
email.make_ascii_lowercase();
3442
Self { name, email }
3543
}
3644
}
@@ -90,7 +98,8 @@ impl<'a> Repo<'a> {
9098
author_to_number_of_commits.into_iter().collect();
9199

92100
let total_num_authors = authors_by_number_of_commits.len();
93-
authors_by_number_of_commits.sort_by(|(_, a_count), (_, b_count)| b_count.cmp(a_count));
101+
authors_by_number_of_commits
102+
.sort_by(|(sa, a_count), (sb, b_count)| b_count.cmp(a_count).then_with(|| sa.cmp(&sb)));
94103

95104
let authors: Vec<Author> = authors_by_number_of_commits
96105
.into_iter()

0 commit comments

Comments
 (0)