@@ -76,30 +76,33 @@ bitflags! {
76
76
77
77
impl Default for FilterSearchOptions {
78
78
fn default ( ) -> Self {
79
- Self :: all ( )
79
+ Self :: MESSAGE
80
80
}
81
81
}
82
82
83
+ ///
84
+ #[ derive( Default , Debug ) ]
85
+ pub struct LogFilterSearchOptions {
86
+ ///
87
+ pub search_pattern : String ,
88
+ ///
89
+ pub filters : FilterSearchOptions ,
90
+ }
91
+
83
92
///
84
93
#[ derive( Default ) ]
85
94
pub struct LogFilterSearch {
86
95
///
87
96
pub matcher : fuzzy_matcher:: skim:: SkimMatcherV2 ,
88
97
///
89
- pub search_pattern : String ,
90
- ///
91
- pub options : FilterSearchOptions ,
98
+ pub options : LogFilterSearchOptions ,
92
99
}
93
100
94
101
impl LogFilterSearch {
95
102
///
96
- pub fn new (
97
- search_pattern : String ,
98
- options : FilterSearchOptions ,
99
- ) -> Self {
103
+ pub fn new ( options : LogFilterSearchOptions ) -> Self {
100
104
Self {
101
105
matcher : fuzzy_matcher:: skim:: SkimMatcherV2 :: default ( ) ,
102
- search_pattern,
103
106
options,
104
107
}
105
108
}
@@ -114,7 +117,7 @@ impl LogFilterSearch {
114
117
self . matcher
115
118
. fuzzy_match (
116
119
file,
117
- self . search_pattern . as_str ( ) ,
120
+ self . options . search_pattern . as_str ( ) ,
118
121
)
119
122
. is_some ( )
120
123
} )
@@ -131,7 +134,7 @@ impl LogFilterSearch {
131
134
self . matcher
132
135
. fuzzy_match (
133
136
file,
134
- self . search_pattern . as_str ( ) ,
137
+ self . options . search_pattern . as_str ( ) ,
135
138
)
136
139
. is_some ( )
137
140
} )
@@ -152,12 +155,13 @@ pub fn filter_commit_by_search(
152
155
153
156
let msg_match = filter
154
157
. options
158
+ . filters
155
159
. contains ( FilterSearchOptions :: MESSAGE )
156
160
. then ( || {
157
161
commit. message ( ) . and_then ( |msg| {
158
162
filter. matcher . fuzzy_match (
159
163
msg,
160
- filter. search_pattern . as_str ( ) ,
164
+ filter. options . search_pattern . as_str ( ) ,
161
165
)
162
166
} )
163
167
} )
@@ -166,6 +170,7 @@ pub fn filter_commit_by_search(
166
170
167
171
let file_match = filter
168
172
. options
173
+ . filters
169
174
. contains ( FilterSearchOptions :: FILENAMES )
170
175
. then ( || {
171
176
get_commit_diff (
@@ -263,7 +268,6 @@ mod tests {
263
268
commit, get_commits_info, stage_add_file,
264
269
tests:: repo_init_empty,
265
270
} ;
266
- use fuzzy_matcher:: skim:: SkimMatcherV2 ;
267
271
use pretty_assertions:: assert_eq;
268
272
use std:: { fs:: File , io:: Write , path:: Path } ;
269
273
@@ -389,11 +393,12 @@ mod tests {
389
393
) ;
390
394
write_commit_file ( & repo, "foo" , "b" , "commit3" ) ;
391
395
392
- let log_filter = filter_commit_by_search ( LogFilterSearch {
393
- options : FilterSearchOptions :: MESSAGE ,
394
- matcher : SkimMatcherV2 :: default ( ) ,
395
- search_pattern : String :: from ( "my msg" ) ,
396
- } ) ;
396
+ let log_filter = filter_commit_by_search (
397
+ LogFilterSearch :: new ( LogFilterSearchOptions {
398
+ filters : FilterSearchOptions :: MESSAGE ,
399
+ search_pattern : String :: from ( "my msg" ) ,
400
+ } ) ,
401
+ ) ;
397
402
398
403
let mut items = Vec :: new ( ) ;
399
404
let mut walker = LogWalker :: new ( & repo, 100 )
@@ -404,11 +409,12 @@ mod tests {
404
409
assert_eq ! ( items. len( ) , 1 ) ;
405
410
assert_eq ! ( items[ 0 ] , second_commit_id) ;
406
411
407
- let log_filter = filter_commit_by_search ( LogFilterSearch {
408
- options : FilterSearchOptions :: FILENAMES ,
409
- matcher : SkimMatcherV2 :: default ( ) ,
410
- search_pattern : String :: from ( "fo" ) ,
411
- } ) ;
412
+ let log_filter = filter_commit_by_search (
413
+ LogFilterSearch :: new ( LogFilterSearchOptions {
414
+ filters : FilterSearchOptions :: FILENAMES ,
415
+ search_pattern : String :: from ( "fo" ) ,
416
+ } ) ,
417
+ ) ;
412
418
413
419
let mut items = Vec :: new ( ) ;
414
420
let mut walker = LogWalker :: new ( & repo, 100 )
0 commit comments