Skip to content

Identify author by email #243

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

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl Info {
args.push("--no-merges");
}

args.push("--pretty=%cr\t%an");
args.push("--pretty=%cr\t%ae\t%an");

let output = Command::new("git")
.args(args)
Expand Down Expand Up @@ -489,10 +489,13 @@ impl Info {

fn get_authors(git_history: &[String], n: usize) -> Vec<(String, usize, usize)> {
let mut authors = std::collections::HashMap::new();
let mut author_name_by_email = std::collections::HashMap::new();
let mut total_commits = 0;
for line in git_history {
let commit_author = line.split('\t').collect::<Vec<_>>()[1].to_string();
let commit_count = authors.entry(commit_author.to_string()).or_insert(0);
let author_email = line.split('\t').collect::<Vec<_>>()[1].to_string();
let author_name = line.split('\t').collect::<Vec<_>>()[2].to_string();
Copy link
Owner

Choose a reason for hiding this comment

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

This should probably be called commit_author_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I think the following variable names are good because of the relationship with the format string of git log.

  • %an = author_name
  • %ae = author_email

I've renamed commit_author to author_email in c68e021

let commit_count = authors.entry(author_email.to_string()).or_insert(0);
author_name_by_email.entry(author_email.to_string()).or_insert(author_name);
*commit_count += 1;
total_commits += 1;
}
Expand All @@ -506,7 +509,7 @@ impl Info {
.into_iter()
.map(|(author, count)| {
(
author.trim_matches('\'').to_string(),
author_name_by_email.get(&author).unwrap().trim_matches('\'').to_string(),
count,
count * 100 / total_commits,
)
Expand Down