Skip to content

Commit

Permalink
Allow filtering for email address
Browse files Browse the repository at this point in the history
The --author parameter does now also include
the email address of the author.

This allows filtering by domain endings,
e.g. @accenture.com
  • Loading branch information
Florian Bramer committed Jan 8, 2025
1 parent 90b67f1 commit ac1827b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> Result<(), String> {
.long("author")
.value_name("pattern")
.help(
"only include commits where author's name contains <pattern> (case insensitive)",
"only include commits where author's name or email contains <pattern> (case insensitive)",
)
.takes_value(true),
)
Expand Down
12 changes: 8 additions & 4 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ pub struct RepoCommit {
pub repo: Arc<Repo>,
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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
2 changes: 1 addition & 1 deletion src/views/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl ListView {
let item = &self.items[i];
if focused {
let item_without_color = SpannedString::<Style>::plain(item.source());
printer.with_style(theme::ColorStyle::highlight(), |printer: &Printer| {
printer.with_style(ColorStyle::highlight(), |printer: &Printer| {
printer.print_styled((0, 0), SpannedStr::from(&item_without_color));
});
} else {
Expand Down

0 comments on commit ac1827b

Please sign in to comment.