Skip to content

Commit

Permalink
gix mailmap verify can now detect collisions (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 29, 2022
1 parent 384ed66 commit f89fe2f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
20 changes: 20 additions & 0 deletions git-mailmap/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
use crate::Entry;
use bstr::BStr;

/// Acccess
impl<'a> Entry<'a> {
/// The name to map to.
pub fn new_name(&self) -> Option<&'a BStr> {
self.new_name
}
/// The email map to.
pub fn new_email(&self) -> Option<&'a BStr> {
self.new_email
}
/// The name to look for and replace.
pub fn old_name(&self) -> Option<&'a BStr> {
self.old_name
}
/// The email to look for and replace.
pub fn old_email(&self) -> &'a BStr {
self.old_email
}
}

/// Constructors indicating what kind of mapping is created.
///
/// Only these combinations of values are valid.
Expand Down
16 changes: 16 additions & 0 deletions gitoxide-core/src/mailmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::OutputFormat;
use anyhow::{bail, Context};
use git_repository as git;
use std::collections::HashSet;
use std::io::Write;
use std::path::Path;

Expand All @@ -17,6 +18,21 @@ pub fn verify(path: impl AsRef<Path>, format: OutputFormat, mut out: impl Write)
err_count += 1;
writeln!(out, "{}", err)?;
}

let mut seen = HashSet::<(_, _)>::default();
for entry in git::mailmap::parse(&buf).filter_map(Result::ok) {
if !seen.insert((entry.old_email(), entry.old_name())) {
writeln!(
out,
"NOTE: entry ({:?}, {:?}) -> ({:?}, {:?}) is being overwritten",
entry.old_email(),
entry.old_name(),
entry.new_email(),
entry.new_name()
)?;
}
}

if err_count == 0 {
writeln!(out, "{} lines OK", git::mailmap::parse(&buf).count())?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ pub mod mailmap {

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Parse all entries in the mailmap and report malformed lines.
/// Parse all entries in the mailmap and report malformed lines or collisions.
Verify,
}
}
Expand Down

0 comments on commit f89fe2f

Please sign in to comment.