Skip to content

Commit

Permalink
Remove additional deduplication of contributors by email
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 2, 2022
1 parent b9b65c7 commit fb4d449
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions src/info/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use git2::{Repository, RepositoryOpenFlags, Status, StatusOptions, StatusShow};
use git_repository as git;
use git_repository::bstr::ByteSlice;
use regex::Regex;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::path::Path;
use time::format_description::well_known::Rfc3339;
Expand All @@ -26,63 +25,15 @@ pub struct Repo<'a> {
time_of_first_commit: git::actor::Time,
}

#[derive(Hash, PartialOrd, Ord, Eq, PartialEq)]
pub struct Sig {
name: git::bstr::BString,
email: git::bstr::BString,
email_lowercase: Option<String>,
}

impl From<git::actor::Signature> for Sig {
fn from(git::actor::Signature { name, email, .. }: git::actor::Signature) -> Self {
let needs_lowercase = email.chars().any(|c| c.to_ascii_lowercase() != c);
let email_lowercase = needs_lowercase.then(|| email.chars().collect::<String>());
Self {
name,
email,
email_lowercase,
}
}
}

impl std::hash::Hash for Sig {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.email_lowercase
.as_ref()
.map(|email_lc| email_lc.hash(state))
.unwrap_or_else(|| self.email.hash(state));
self.name.hash(state);
}
}

impl Eq for Sig {}

impl PartialEq<Self> for Sig {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == Ordering::Equal
}
}

impl PartialOrd<Self> for Sig {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.cmp(other).into()
}
}

impl Ord for Sig {
fn cmp(&self, other: &Self) -> Ordering {
self.email_lowercase
.as_ref()
.and_then(|a_email_lc| {
other
.email_lowercase
.as_ref()
.map(|b_email_lc| (a_email_lc, b_email_lc))
})
.map_or_else(
|| self.email.cmp(&other.email),
|(a_email_lc, b_email_lc)| a_email_lc.cmp(b_email_lc),
)
.then_with(|| self.name.cmp(&other.name))
Self { name, email }
}
}

Expand Down

0 comments on commit fb4d449

Please sign in to comment.