From ac1827b11cb36008f33df6da53896099247d15d2 Mon Sep 17 00:00:00 2001 From: Florian Bramer Date: Wed, 8 Jan 2025 15:46:33 +0100 Subject: [PATCH] Allow filtering for email address The --author parameter does now also include the email address of the author. This allows filtering by domain endings, e.g. @accenture.com --- src/main.rs | 2 +- src/model.rs | 12 ++++++++---- src/report.rs | 2 +- src/views/list_view.rs | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 961bd0b..e936b74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,7 @@ fn main() -> Result<(), String> { .long("author") .value_name("pattern") .help( - "only include commits where author's name contains (case insensitive)", + "only include commits where author's name or email contains (case insensitive)", ) .takes_value(true), ) diff --git a/src/model.rs b/src/model.rs index 0e8b726..840b9dd 100644 --- a/src/model.rs +++ b/src/model.rs @@ -163,7 +163,8 @@ pub struct RepoCommit { pub repo: Arc, pub commit_time: Time, pub summary: String, - pub author: String, + pub author_name: String, + pub author_email: String, pub committer: String, pub commit_id: Oid, pub message: String, @@ -175,7 +176,8 @@ impl RepoCommit { repo, commit_time: commit.time(), summary: commit.summary().unwrap_or("None").into(), - author: commit.author().name().unwrap_or("None").into(), + author_name: commit.author().name().unwrap_or("None").into(), + author_email: commit.author().email().unwrap_or("None").into(), committer: commit.committer().name().unwrap_or("None").into(), commit_id: commit.id(), message: commit.message().unwrap_or("").to_string(), @@ -241,8 +243,10 @@ impl Classifier { } if let Some(ref author) = self.author { - let ca = commit.author().name().unwrap_or("").to_ascii_lowercase(); - include &= ca.contains(author); + let current_author_name = commit.author().name().unwrap_or("").to_ascii_lowercase(); + let current_author_email = commit.author().email().unwrap_or("").to_ascii_lowercase(); + + include &= current_author_name.contains(author) || current_author_email.contains(author); } (include, abort) diff --git a/src/report.rs b/src/report.rs index 03923c0..6170d4d 100644 --- a/src/report.rs +++ b/src/report.rs @@ -153,7 +153,7 @@ fn model_into_spreadsheet( for commit in &model.commits { builder.add_cell(commit.time_as_str())?; builder.add_cell(commit.repo.rel_path.clone())?; - builder.add_cell(commit.author.to_string())?; + builder.add_cell(commit.author_name.to_string())?; builder.add_cell(commit.summary.to_string())?; builder.add_cell(commit.message.to_string())?; builder.finish_row()?; diff --git a/src/views/list_view.rs b/src/views/list_view.rs index 367b66a..d4f8ef4 100644 --- a/src/views/list_view.rs +++ b/src/views/list_view.rs @@ -356,7 +356,7 @@ impl ListView { let item = &self.items[i]; if focused { let item_without_color = SpannedString::