From cde1c7f8831021da9222e89120133e2753414162 Mon Sep 17 00:00:00 2001 From: extrawurst <776816+extrawurst@users.noreply.github.com> Date: Mon, 21 Aug 2023 12:11:53 +0200 Subject: [PATCH] Search commits by author (#1822) --- asyncgit/src/sync/logwalker.rs | 26 +++++++++++++++++--- src/components/log_search_popup.rs | 39 ++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/asyncgit/src/sync/logwalker.rs b/asyncgit/src/sync/logwalker.rs index e9f0422d37..b67aed7f2f 100644 --- a/asyncgit/src/sync/logwalker.rs +++ b/asyncgit/src/sync/logwalker.rs @@ -65,13 +65,13 @@ bitflags! { const MESSAGE = 0b0000_0001; /// const FILENAMES = 0b0000_0010; + /// + const AUTHORS = 0b0000_0100; //TODO: // const COMMIT_HASHES = 0b0000_0100; // /// // const DATES = 0b0000_1000; // /// - // const AUTHORS = 0b0001_0000; - // /// // const DIFFS = 0b0010_0000; } } @@ -210,7 +210,27 @@ pub fn filter_commit_by_search( .map(|diff| filter.match_diff(&diff)) .unwrap_or_default(); - Ok(msg_match || file_match) + let authors_match = filter + .options + .fields + .contains(SearchFields::AUTHORS) + .then(|| { + let name_match = commit + .author() + .name() + .map(|name| filter.match_text(name)) + .unwrap_or_default(); + let mail_match = commit + .author() + .email() + .map(|name| filter.match_text(name)) + .unwrap_or_default(); + + name_match || mail_match + }) + .unwrap_or_default(); + + Ok(msg_match || file_match || authors_match) }, )) } diff --git a/src/components/log_search_popup.rs b/src/components/log_search_popup.rs index ef13b554ec..c6beb64803 100644 --- a/src/components/log_search_popup.rs +++ b/src/components/log_search_popup.rs @@ -29,6 +29,7 @@ enum Selection { CaseOption, MessageSearch, FilenameSearch, + AuthorsSearch, } pub struct LogSearchPopupComponent { @@ -111,6 +112,13 @@ impl LogSearchPopupComponent { " " }; + let x_authors = + if self.options.0.contains(SearchFields::AUTHORS) { + "X" + } else { + " " + }; + let x_opt_fuzzy = if self.options.1.contains(SearchOptions::FUZZY_SEARCH) { "X" @@ -161,15 +169,21 @@ impl LogSearchPopupComponent { false, ), )]), + Line::from(vec![Span::styled( + format!("[{x_authors}] authors",), + self.theme.text( + matches!( + self.selection, + Selection::AuthorsSearch + ), + false, + ), + )]), // Line::from(vec![Span::styled( // "[ ] changes (soon)", // theme, // )]), // Line::from(vec![Span::styled( - // "[ ] authors (soon)", - // theme, - // )]), - // Line::from(vec![Span::styled( // "[ ] hashes (soon)", // theme, // )]), @@ -192,14 +206,21 @@ impl LogSearchPopupComponent { Selection::MessageSearch => { self.options.0.toggle(SearchFields::MESSAGE); - if !self.options.0.contains(SearchFields::MESSAGE) { + if self.options.0.is_empty() { self.options.0.set(SearchFields::FILENAMES, true); } } Selection::FilenameSearch => { self.options.0.toggle(SearchFields::FILENAMES); - if !self.options.0.contains(SearchFields::FILENAMES) { + if self.options.0.is_empty() { + self.options.0.set(SearchFields::AUTHORS, true); + } + } + Selection::AuthorsSearch => { + self.options.0.toggle(SearchFields::AUTHORS); + + if self.options.0.is_empty() { self.options.0.set(SearchFields::MESSAGE, true); } } @@ -210,11 +231,12 @@ impl LogSearchPopupComponent { if arg { //up self.selection = match self.selection { - Selection::EnterText => Selection::FilenameSearch, + Selection::EnterText => Selection::AuthorsSearch, Selection::FuzzyOption => Selection::EnterText, Selection::CaseOption => Selection::FuzzyOption, Selection::MessageSearch => Selection::CaseOption, Selection::FilenameSearch => Selection::MessageSearch, + Selection::AuthorsSearch => Selection::FilenameSearch, }; } else { self.selection = match self.selection { @@ -222,7 +244,8 @@ impl LogSearchPopupComponent { Selection::FuzzyOption => Selection::CaseOption, Selection::CaseOption => Selection::MessageSearch, Selection::MessageSearch => Selection::FilenameSearch, - Selection::FilenameSearch => Selection::EnterText, + Selection::FilenameSearch => Selection::AuthorsSearch, + Selection::AuthorsSearch => Selection::EnterText, }; } }