Skip to content

Commit cde1c7f

Browse files
authored
Search commits by author (#1822)
1 parent d253022 commit cde1c7f

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

asyncgit/src/sync/logwalker.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ bitflags! {
6565
const MESSAGE = 0b0000_0001;
6666
///
6767
const FILENAMES = 0b0000_0010;
68+
///
69+
const AUTHORS = 0b0000_0100;
6870
//TODO:
6971
// const COMMIT_HASHES = 0b0000_0100;
7072
// ///
7173
// const DATES = 0b0000_1000;
7274
// ///
73-
// const AUTHORS = 0b0001_0000;
74-
// ///
7575
// const DIFFS = 0b0010_0000;
7676
}
7777
}
@@ -210,7 +210,27 @@ pub fn filter_commit_by_search(
210210
.map(|diff| filter.match_diff(&diff))
211211
.unwrap_or_default();
212212

213-
Ok(msg_match || file_match)
213+
let authors_match = filter
214+
.options
215+
.fields
216+
.contains(SearchFields::AUTHORS)
217+
.then(|| {
218+
let name_match = commit
219+
.author()
220+
.name()
221+
.map(|name| filter.match_text(name))
222+
.unwrap_or_default();
223+
let mail_match = commit
224+
.author()
225+
.email()
226+
.map(|name| filter.match_text(name))
227+
.unwrap_or_default();
228+
229+
name_match || mail_match
230+
})
231+
.unwrap_or_default();
232+
233+
Ok(msg_match || file_match || authors_match)
214234
},
215235
))
216236
}

src/components/log_search_popup.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum Selection {
2929
CaseOption,
3030
MessageSearch,
3131
FilenameSearch,
32+
AuthorsSearch,
3233
}
3334

3435
pub struct LogSearchPopupComponent {
@@ -111,6 +112,13 @@ impl LogSearchPopupComponent {
111112
" "
112113
};
113114

115+
let x_authors =
116+
if self.options.0.contains(SearchFields::AUTHORS) {
117+
"X"
118+
} else {
119+
" "
120+
};
121+
114122
let x_opt_fuzzy =
115123
if self.options.1.contains(SearchOptions::FUZZY_SEARCH) {
116124
"X"
@@ -161,15 +169,21 @@ impl LogSearchPopupComponent {
161169
false,
162170
),
163171
)]),
172+
Line::from(vec![Span::styled(
173+
format!("[{x_authors}] authors",),
174+
self.theme.text(
175+
matches!(
176+
self.selection,
177+
Selection::AuthorsSearch
178+
),
179+
false,
180+
),
181+
)]),
164182
// Line::from(vec![Span::styled(
165183
// "[ ] changes (soon)",
166184
// theme,
167185
// )]),
168186
// Line::from(vec![Span::styled(
169-
// "[ ] authors (soon)",
170-
// theme,
171-
// )]),
172-
// Line::from(vec![Span::styled(
173187
// "[ ] hashes (soon)",
174188
// theme,
175189
// )]),
@@ -192,14 +206,21 @@ impl LogSearchPopupComponent {
192206
Selection::MessageSearch => {
193207
self.options.0.toggle(SearchFields::MESSAGE);
194208

195-
if !self.options.0.contains(SearchFields::MESSAGE) {
209+
if self.options.0.is_empty() {
196210
self.options.0.set(SearchFields::FILENAMES, true);
197211
}
198212
}
199213
Selection::FilenameSearch => {
200214
self.options.0.toggle(SearchFields::FILENAMES);
201215

202-
if !self.options.0.contains(SearchFields::FILENAMES) {
216+
if self.options.0.is_empty() {
217+
self.options.0.set(SearchFields::AUTHORS, true);
218+
}
219+
}
220+
Selection::AuthorsSearch => {
221+
self.options.0.toggle(SearchFields::AUTHORS);
222+
223+
if self.options.0.is_empty() {
203224
self.options.0.set(SearchFields::MESSAGE, true);
204225
}
205226
}
@@ -210,19 +231,21 @@ impl LogSearchPopupComponent {
210231
if arg {
211232
//up
212233
self.selection = match self.selection {
213-
Selection::EnterText => Selection::FilenameSearch,
234+
Selection::EnterText => Selection::AuthorsSearch,
214235
Selection::FuzzyOption => Selection::EnterText,
215236
Selection::CaseOption => Selection::FuzzyOption,
216237
Selection::MessageSearch => Selection::CaseOption,
217238
Selection::FilenameSearch => Selection::MessageSearch,
239+
Selection::AuthorsSearch => Selection::FilenameSearch,
218240
};
219241
} else {
220242
self.selection = match self.selection {
221243
Selection::EnterText => Selection::FuzzyOption,
222244
Selection::FuzzyOption => Selection::CaseOption,
223245
Selection::CaseOption => Selection::MessageSearch,
224246
Selection::MessageSearch => Selection::FilenameSearch,
225-
Selection::FilenameSearch => Selection::EnterText,
247+
Selection::FilenameSearch => Selection::AuthorsSearch,
248+
Selection::AuthorsSearch => Selection::EnterText,
226249
};
227250
}
228251
}

0 commit comments

Comments
 (0)