@@ -9,9 +9,7 @@ use gix::object::tree::diff::Action;
99use gix:: prelude:: ObjectIdExt ;
1010use gix:: traverse:: commit:: simple:: Sorting ;
1111use gix:: { Commit , ObjectId } ;
12- use regex:: Regex ;
1312use std:: collections:: HashMap ;
14- use std:: str:: FromStr ;
1513use std:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
1614use std:: sync:: mpsc:: { channel, Sender } ;
1715use std:: sync:: Arc ;
@@ -22,15 +20,14 @@ pub mod sig;
2220
2321pub fn traverse_commit_graph (
2422 repo : & gix:: Repository ,
25- no_bots : & Option < Option < MyRegex > > ,
23+ no_bots : Option < MyRegex > ,
2624 max_churn_pool_size : Option < usize > ,
2725 no_merges : bool ,
2826) -> Result < GitMetrics > {
2927 let mut time_of_most_recent_commit = None ;
3028 let mut time_of_first_commit = None ;
3129 let mut number_of_commits_by_signature: HashMap < Sig , usize > = HashMap :: new ( ) ;
3230 let mailmap = repo. open_mailmap ( ) ;
33- let bot_regex_pattern = get_no_bots_regex ( no_bots) ?;
3431 let has_commit_graph_traversal_ended = Arc :: new ( AtomicBool :: default ( ) ) ;
3532 let total_number_of_commits = Arc :: new ( AtomicUsize :: default ( ) ) ;
3633
@@ -57,7 +54,7 @@ pub fn traverse_commit_graph(
5754 ) ?;
5855
5956 let author_threads = can_use_author_threads
60- . then ( || get_author_channel ( repo, num_threads, & bot_regex_pattern , & mailmap) ) ;
57+ . then ( || get_author_channel ( repo, num_threads, no_bots . clone ( ) , & mailmap) ) ;
6158
6259 let mut count = 0 ;
6360 for commit in commit_iter {
@@ -73,7 +70,7 @@ pub fn traverse_commit_graph(
7370 update_signature_counts (
7471 & commit. object ( ) ?,
7572 & mailmap,
76- & bot_regex_pattern ,
73+ no_bots . as_ref ( ) ,
7774 & mut number_of_commits_by_signature,
7875 ) ?;
7976 }
@@ -127,7 +124,7 @@ type NumberOfCommitsBySignature = HashMap<Sig, usize>;
127124fn get_author_channel (
128125 repo : & gix:: Repository ,
129126 num_threads : usize ,
130- bot_regex_pattern : & Option < MyRegex > ,
127+ bot_regex_pattern : Option < MyRegex > ,
131128 mailmap : & gix:: mailmap:: Snapshot ,
132129) -> (
133130 Vec < JoinHandle < Result < NumberOfCommitsBySignature > > > ,
@@ -155,7 +152,7 @@ fn get_author_channel(
155152 update_signature_counts (
156153 & commit,
157154 & mailmap,
158- & bot_regex_pattern,
155+ bot_regex_pattern. as_ref ( ) ,
159156 & mut number_of_commits_by_signature,
160157 ) ?;
161158 }
@@ -223,7 +220,7 @@ fn should_break(
223220fn update_signature_counts (
224221 commit : & gix:: Commit ,
225222 mailmap : & gix:: mailmap:: Snapshot ,
226- bot_regex_pattern : & Option < MyRegex > ,
223+ bot_regex_pattern : Option < & MyRegex > ,
227224 number_of_commits_by_signature : & mut HashMap < Sig , usize > ,
228225) -> Result < ( ) > {
229226 let sig = mailmap. resolve ( commit. author ( ) ?) ;
@@ -275,50 +272,18 @@ fn compute_diff_with_parent(
275272 Ok ( ( ) )
276273}
277274
278- fn get_no_bots_regex ( no_bots : & Option < Option < MyRegex > > ) -> Result < Option < MyRegex > > {
279- let reg = if let Some ( r) = no_bots. clone ( ) {
280- match r {
281- Some ( p) => Some ( p) ,
282- None => Some ( MyRegex ( Regex :: from_str ( r"(?:-|\s)[Bb]ot$|\[[Bb]ot\]" ) ?) ) ,
283- }
284- } else {
285- None
286- } ;
287-
288- Ok ( reg)
289- }
290-
291- fn is_bot ( author_name : & BString , bot_regex_pattern : & Option < MyRegex > ) -> bool {
292- bot_regex_pattern. as_ref ( ) . map_or ( false , |regex| {
275+ fn is_bot ( author_name : & BString , bot_regex_pattern : Option < & MyRegex > ) -> bool {
276+ bot_regex_pattern. map_or ( false , |regex| {
293277 regex. 0 . is_match ( author_name. to_str_lossy ( ) . as_ref ( ) )
294278 } )
295279}
296280
297281#[ cfg( test) ]
298282mod tests {
299283 use super :: * ;
284+ use crate :: cli:: NO_BOTS_DEFAULT_REGEX_PATTERN ;
300285 use rstest:: rstest;
301-
302- #[ test]
303- fn test_get_no_bots_regex ( ) -> Result < ( ) > {
304- // Test case 1: no_bots is None
305- let no_bots: Option < Option < MyRegex > > = None ;
306- let result = get_no_bots_regex ( & no_bots) ?;
307- assert_eq ! ( result, None ) ;
308-
309- // Test case 2: no_bots is Some(None)
310- let no_bots: Option < Option < MyRegex > > = Some ( None ) ;
311- let result = get_no_bots_regex ( & no_bots) ?;
312- assert_eq ! ( result. unwrap( ) . 0 . as_str( ) , r"(?:-|\s)[Bb]ot$|\[[Bb]ot\]" ) ;
313-
314- // Test case 3: no_bots is Some(Some(regex))
315- let regex = MyRegex ( Regex :: new ( r"foo" ) ?) ;
316- let no_bots: Option < Option < MyRegex > > = Some ( Some ( regex) ) ;
317- let result = get_no_bots_regex ( & no_bots) ?;
318- assert_eq ! ( result. unwrap( ) . 0 . as_str( ) , "foo" ) ;
319-
320- Ok ( ( ) )
321- }
286+ use std:: str:: FromStr ;
322287
323288 #[ rstest]
324289 #[ case( "John Doe" , false ) ]
@@ -327,9 +292,9 @@ mod tests {
327292 #[ case( "foo-bot" , true ) ]
328293 #[ case( "bot" , false ) ]
329294 fn test_is_bot ( #[ case] author_name : & str , #[ case] expected : bool ) -> Result < ( ) > {
330- let no_bots : Option < Option < MyRegex > > = Some ( None ) ;
331- let regex = get_no_bots_regex ( & no_bots ) ? ;
332- assert_eq ! ( is_bot( & author_name. into( ) , & regex ) , expected) ;
295+ let from_str = MyRegex :: from_str ( NO_BOTS_DEFAULT_REGEX_PATTERN ) ;
296+ let no_bots : Option < MyRegex > = Some ( from_str? ) ;
297+ assert_eq ! ( is_bot( & author_name. into( ) , no_bots . as_ref ( ) ) , expected) ;
333298 Ok ( ( ) )
334299 }
335300
0 commit comments