Skip to content

Commit ca58871

Browse files
authored
Merge pull request #243 from yoichi/identify-author-by-email
Identify author by email
2 parents 13b9727 + c68e021 commit ca58871

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/info.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl Info {
394394
args.push("--no-merges");
395395
}
396396

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

399399
let output = Command::new("git")
400400
.args(args)
@@ -489,10 +489,13 @@ impl Info {
489489

490490
fn get_authors(git_history: &[String], n: usize) -> Vec<(String, usize, usize)> {
491491
let mut authors = std::collections::HashMap::new();
492+
let mut author_name_by_email = std::collections::HashMap::new();
492493
let mut total_commits = 0;
493494
for line in git_history {
494-
let commit_author = line.split('\t').collect::<Vec<_>>()[1].to_string();
495-
let commit_count = authors.entry(commit_author.to_string()).or_insert(0);
495+
let author_email = line.split('\t').collect::<Vec<_>>()[1].to_string();
496+
let author_name = line.split('\t').collect::<Vec<_>>()[2].to_string();
497+
let commit_count = authors.entry(author_email.to_string()).or_insert(0);
498+
author_name_by_email.entry(author_email.to_string()).or_insert(author_name);
496499
*commit_count += 1;
497500
total_commits += 1;
498501
}
@@ -506,7 +509,7 @@ impl Info {
506509
.into_iter()
507510
.map(|(author, count)| {
508511
(
509-
author.trim_matches('\'').to_string(),
512+
author_name_by_email.get(&author).unwrap().trim_matches('\'').to_string(),
510513
count,
511514
count * 100 / total_commits,
512515
)

0 commit comments

Comments
 (0)