Skip to content

Commit 253a18f

Browse files
committed
search message body/summary separately
closes #1875
1 parent 0e1d83f commit 253a18f

File tree

4 files changed

+77
-29
lines changed

4 files changed

+77
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111
* parallelise log search - performance gain ~100% ([#1869](https://github.com/extrawurst/gitui/issues/1869))
12+
* search message body/summary separately ([#1875](https://github.com/extrawurst/gitui/issues/1875))
13+
1214

1315
## [0.24.2] - 2023-09-03
1416

asyncgit/src/sync/commit_filter.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ bitflags! {
3535
///
3636
pub struct SearchFields: u32 {
3737
///
38-
const MESSAGE = 1 << 0;
38+
const MESSAGE_SUMMARY = 1 << 0;
3939
///
40-
const FILENAMES = 1 << 1;
40+
const MESSAGE_BODY = 1 << 1;
4141
///
42-
const AUTHORS = 1 << 2;
42+
const FILENAMES = 1 << 2;
43+
///
44+
const AUTHORS = 1 << 3;
4345
//TODO:
4446
// const COMMIT_HASHES = 1 << 3;
4547
// ///
@@ -51,7 +53,7 @@ bitflags! {
5153

5254
impl Default for SearchFields {
5355
fn default() -> Self {
54-
Self::MESSAGE
56+
Self::MESSAGE_SUMMARY
5557
}
5658
}
5759

@@ -159,12 +161,22 @@ pub fn filter_commit_by_search(
159161
-> Result<bool> {
160162
let commit = repo.find_commit((*commit_id).into())?;
161163

162-
let msg_match = filter
164+
let msg_summary_match = filter
165+
.options
166+
.fields
167+
.contains(SearchFields::MESSAGE_SUMMARY)
168+
.then(|| {
169+
commit.summary().map(|msg| filter.match_text(msg))
170+
})
171+
.flatten()
172+
.unwrap_or_default();
173+
174+
let msg_body_match = filter
163175
.options
164176
.fields
165-
.contains(SearchFields::MESSAGE)
177+
.contains(SearchFields::MESSAGE_BODY)
166178
.then(|| {
167-
commit.message().map(|msg| filter.match_text(msg))
179+
commit.body().map(|msg| filter.match_text(msg))
168180
})
169181
.flatten()
170182
.unwrap_or_default();
@@ -203,7 +215,9 @@ pub fn filter_commit_by_search(
203215
})
204216
.unwrap_or_default();
205217

206-
Ok(msg_match || file_match || authors_match)
218+
Ok(msg_summary_match
219+
|| msg_body_match
220+
|| file_match || authors_match)
207221
},
208222
))
209223
}

asyncgit/src/sync/logwalker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ mod tests {
249249

250250
let log_filter = filter_commit_by_search(
251251
LogFilterSearch::new(LogFilterSearchOptions {
252-
fields: SearchFields::MESSAGE,
252+
fields: SearchFields::MESSAGE_SUMMARY,
253253
options: SearchOptions::FUZZY_SEARCH,
254254
search_pattern: String::from("my msg"),
255255
}),

src/components/log_search_popup.rs

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ enum Selection {
2929
EnterText,
3030
FuzzyOption,
3131
CaseOption,
32-
MessageSearch,
32+
SummarySearch,
33+
MessageBodySearch,
3334
FilenameSearch,
3435
AuthorsSearch,
3536
}
@@ -173,8 +174,16 @@ impl LogSearchPopupComponent {
173174
}
174175

175176
fn get_text_options(&self) -> Vec<Line> {
176-
let x_message =
177-
if self.options.0.contains(SearchFields::MESSAGE) {
177+
let x_summary =
178+
if self.options.0.contains(SearchFields::MESSAGE_SUMMARY)
179+
{
180+
"X"
181+
} else {
182+
" "
183+
};
184+
185+
let x_body =
186+
if self.options.0.contains(SearchFields::MESSAGE_BODY) {
178187
"X"
179188
} else {
180189
" "
@@ -225,11 +234,21 @@ impl LogSearchPopupComponent {
225234
),
226235
)]),
227236
Line::from(vec![Span::styled(
228-
format!("[{x_message}] messages",),
237+
format!("[{x_summary}] summary",),
238+
self.theme.text(
239+
matches!(
240+
self.selection,
241+
Selection::SummarySearch
242+
),
243+
false,
244+
),
245+
)]),
246+
Line::from(vec![Span::styled(
247+
format!("[{x_body}] message body",),
229248
self.theme.text(
230249
matches!(
231250
self.selection,
232-
Selection::MessageSearch
251+
Selection::MessageBodySearch
233252
),
234253
false,
235254
),
@@ -254,14 +273,6 @@ impl LogSearchPopupComponent {
254273
false,
255274
),
256275
)]),
257-
// Line::from(vec![Span::styled(
258-
// "[ ] changes (soon)",
259-
// theme,
260-
// )]),
261-
// Line::from(vec![Span::styled(
262-
// "[ ] hashes (soon)",
263-
// theme,
264-
// )]),
265276
]
266277
}
267278

@@ -278,8 +289,17 @@ impl LogSearchPopupComponent {
278289
Selection::CaseOption => {
279290
self.options.1.toggle(SearchOptions::CASE_SENSITIVE);
280291
}
281-
Selection::MessageSearch => {
282-
self.options.0.toggle(SearchFields::MESSAGE);
292+
Selection::SummarySearch => {
293+
self.options.0.toggle(SearchFields::MESSAGE_SUMMARY);
294+
295+
if self.options.0.is_empty() {
296+
self.options
297+
.0
298+
.set(SearchFields::MESSAGE_BODY, true);
299+
}
300+
}
301+
Selection::MessageBodySearch => {
302+
self.options.0.toggle(SearchFields::MESSAGE_BODY);
283303

284304
if self.options.0.is_empty() {
285305
self.options.0.set(SearchFields::FILENAMES, true);
@@ -296,7 +316,9 @@ impl LogSearchPopupComponent {
296316
self.options.0.toggle(SearchFields::AUTHORS);
297317

298318
if self.options.0.is_empty() {
299-
self.options.0.set(SearchFields::MESSAGE, true);
319+
self.options
320+
.0
321+
.set(SearchFields::MESSAGE_SUMMARY, true);
300322
}
301323
}
302324
}
@@ -309,16 +331,26 @@ impl LogSearchPopupComponent {
309331
Selection::EnterText => Selection::AuthorsSearch,
310332
Selection::FuzzyOption => Selection::EnterText,
311333
Selection::CaseOption => Selection::FuzzyOption,
312-
Selection::MessageSearch => Selection::CaseOption,
313-
Selection::FilenameSearch => Selection::MessageSearch,
334+
Selection::SummarySearch => Selection::CaseOption,
335+
Selection::MessageBodySearch => {
336+
Selection::SummarySearch
337+
}
338+
Selection::FilenameSearch => {
339+
Selection::MessageBodySearch
340+
}
314341
Selection::AuthorsSearch => Selection::FilenameSearch,
315342
};
316343
} else {
317344
self.selection = match self.selection {
318345
Selection::EnterText => Selection::FuzzyOption,
319346
Selection::FuzzyOption => Selection::CaseOption,
320-
Selection::CaseOption => Selection::MessageSearch,
321-
Selection::MessageSearch => Selection::FilenameSearch,
347+
Selection::CaseOption => Selection::SummarySearch,
348+
Selection::SummarySearch => {
349+
Selection::MessageBodySearch
350+
}
351+
Selection::MessageBodySearch => {
352+
Selection::FilenameSearch
353+
}
322354
Selection::FilenameSearch => Selection::AuthorsSearch,
323355
Selection::AuthorsSearch => Selection::EnterText,
324356
};

0 commit comments

Comments
 (0)