Skip to content
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

Search commits by author #1822

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 23 additions & 3 deletions asyncgit/src/sync/logwalker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)
},
))
}
Expand Down
39 changes: 31 additions & 8 deletions src/components/log_search_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum Selection {
CaseOption,
MessageSearch,
FilenameSearch,
AuthorsSearch,
}

pub struct LogSearchPopupComponent {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
// )]),
Expand All @@ -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);
}
}
Expand All @@ -210,19 +231,21 @@ 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 {
Selection::EnterText => Selection::FuzzyOption,
Selection::FuzzyOption => Selection::CaseOption,
Selection::CaseOption => Selection::MessageSearch,
Selection::MessageSearch => Selection::FilenameSearch,
Selection::FilenameSearch => Selection::EnterText,
Selection::FilenameSearch => Selection::AuthorsSearch,
Selection::AuthorsSearch => Selection::EnterText,
};
}
}
Expand Down
Loading