Skip to content

Commit 6ba6e79

Browse files
committed
improve readability
1 parent 6bd559d commit 6ba6e79

File tree

1 file changed

+39
-43
lines changed

1 file changed

+39
-43
lines changed

asyncgit/src/sync/logwalker.rs

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::CommitId;
33
use crate::{error::Result, sync::commit_files::get_commit_diff};
44
use bitflags::bitflags;
55
use fuzzy_matcher::FuzzyMatcher;
6-
use git2::{Commit, Oid, Repository};
6+
use git2::{Commit, Diff, Oid, Repository};
77
use std::{
88
cmp::Ordering,
99
collections::{BinaryHeap, HashSet},
@@ -81,6 +81,43 @@ pub struct LogFilterSearch {
8181
pub options: FilterSearchOptions,
8282
}
8383

84+
impl LogFilterSearch {
85+
fn match_diff(&self, diff: &Diff<'_>) -> bool {
86+
diff.deltas().any(|delta| {
87+
if delta
88+
.new_file()
89+
.path()
90+
.and_then(|file| file.as_os_str().to_str())
91+
.map(|file| {
92+
self.matcher
93+
.fuzzy_match(
94+
file,
95+
self.search_pattern.as_str(),
96+
)
97+
.is_some()
98+
})
99+
.unwrap_or_default()
100+
{
101+
return true;
102+
}
103+
104+
delta
105+
.old_file()
106+
.path()
107+
.and_then(|file| file.as_os_str().to_str())
108+
.map(|file| {
109+
self.matcher
110+
.fuzzy_match(
111+
file,
112+
self.search_pattern.as_str(),
113+
)
114+
.is_some()
115+
})
116+
.unwrap_or_default()
117+
})
118+
}
119+
}
120+
84121
///
85122
pub fn filter_commit_by_search(
86123
filter: LogFilterSearch,
@@ -115,48 +152,7 @@ pub fn filter_commit_by_search(
115152
.ok()
116153
})
117154
.flatten()
118-
.map(|diff| {
119-
diff.deltas().any(|delta| {
120-
let new_file_match = delta
121-
.new_file()
122-
.path()
123-
.and_then(|file| {
124-
file.as_os_str().to_str()
125-
})
126-
.map(|file| {
127-
filter
128-
.matcher
129-
.fuzzy_match(
130-
file,
131-
filter
132-
.search_pattern
133-
.as_str(),
134-
)
135-
.is_some()
136-
})
137-
.unwrap_or_default();
138-
let old_file_match = delta
139-
.old_file()
140-
.path()
141-
.and_then(|file| {
142-
file.as_os_str().to_str()
143-
})
144-
.map(|file| {
145-
filter
146-
.matcher
147-
.fuzzy_match(
148-
file,
149-
filter
150-
.search_pattern
151-
.as_str(),
152-
)
153-
.is_some()
154-
})
155-
.unwrap_or_default();
156-
157-
old_file_match || new_file_match
158-
})
159-
})
155+
.map(|diff| filter.match_diff(&diff))
160156
.unwrap_or_default();
161157

162158
Ok(msg_match || file_match)

0 commit comments

Comments
 (0)