@@ -3,7 +3,7 @@ use super::CommitId;
3
3
use crate :: { error:: Result , sync:: commit_files:: get_commit_diff} ;
4
4
use bitflags:: bitflags;
5
5
use fuzzy_matcher:: FuzzyMatcher ;
6
- use git2:: { Commit , Oid , Repository } ;
6
+ use git2:: { Commit , Diff , Oid , Repository } ;
7
7
use std:: {
8
8
cmp:: Ordering ,
9
9
collections:: { BinaryHeap , HashSet } ,
@@ -81,6 +81,43 @@ pub struct LogFilterSearch {
81
81
pub options : FilterSearchOptions ,
82
82
}
83
83
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
+
84
121
///
85
122
pub fn filter_commit_by_search (
86
123
filter : LogFilterSearch ,
@@ -115,48 +152,7 @@ pub fn filter_commit_by_search(
115
152
. ok ( )
116
153
} )
117
154
. 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) )
160
156
. unwrap_or_default ( ) ;
161
157
162
158
Ok ( msg_match || file_match)
0 commit comments