11use crate :: rules_manager;
22
33use chrono:: prelude:: * ;
4+ use crossbeam_utils:: atomic:: AtomicCell ;
45use crossbeam_utils:: thread as crossbeam_thread;
56use crossbeam:: queue:: SegQueue ;
67use git2:: { Oid , Repository , Delta } ;
@@ -9,12 +10,11 @@ use pyo3::prelude::*;
910use std:: collections:: HashMap ;
1011use std:: path:: Path ;
1112use std:: sync:: Arc ;
12- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1313use std:: thread;
1414use std:: time;
1515
1616fn scan_commit_oid (
17- should_stop : & AtomicBool ,
17+ should_stop : & AtomicCell < bool > ,
1818 git_repo : & Repository ,
1919 oid : & Oid ,
2020 rules_manager : & rules_manager:: RulesManager ,
@@ -39,7 +39,7 @@ fn scan_commit_oid(
3939 } ;
4040
4141 for delta in commit_diff. deltas ( ) {
42- if should_stop. load ( Ordering :: Relaxed ) {
42+ if should_stop. load ( ) {
4343 break ;
4444 }
4545
@@ -80,7 +80,6 @@ fn scan_commit_oid(
8080 if let Some ( scan_matches) = scan_matches {
8181 for scan_match in scan_matches. iter ( ) {
8282 let mut match_hashmap = HashMap :: with_capacity ( 9 ) ;
83- let commit_date = Utc . timestamp ( commit. time ( ) . seconds ( ) , 0 ) ;
8483 match_hashmap. insert (
8584 "commit_id" ,
8685 commit. id ( ) . to_string ( ) ,
@@ -91,7 +90,7 @@ fn scan_commit_oid(
9190 ) ;
9291 match_hashmap. insert (
9392 "commit_time" ,
94- commit_date . format ( "%Y-%m-%dT%H:%M:%S" ) . to_string ( ) ,
93+ Utc . timestamp ( commit . time ( ) . seconds ( ) , 0 ) . format ( "%Y-%m-%dT%H:%M:%S" ) . to_string ( ) ,
9594 ) ;
9695 match_hashmap. insert (
9796 "author_name" ,
@@ -185,22 +184,19 @@ pub fn scan_repository(
185184 return Err ( pyo3:: exceptions:: PyRuntimeError :: new_err ( error. to_string ( ) ) )
186185 } ,
187186 }
187+
188188 py. check_signals ( ) ?;
189189
190190 let mut py_signal_error: PyResult < ( ) > = Ok ( ( ) ) ;
191191
192+ let should_stop = AtomicCell :: new ( false ) ;
192193 crossbeam_thread:: scope (
193194 |scope| {
194- let should_stop = Arc :: new ( AtomicBool :: new ( false ) ) ;
195-
196195 for _ in 0 ..num_cpus:: get ( ) {
197- let output_matches = output_matches. clone ( ) ;
198- let oids_queue = oids_queue. clone ( ) ;
199- let should_stop = should_stop. clone ( ) ;
200196 scope. spawn (
201- move |_| {
197+ |_| {
202198 if let Ok ( git_repo) = Repository :: open ( repository_path) {
203- while !should_stop. load ( Ordering :: Relaxed ) {
199+ while !should_stop. load ( ) {
204200 if let Some ( oid) = oids_queue. pop ( ) {
205201 scan_commit_oid (
206202 & should_stop,
@@ -221,7 +217,7 @@ pub fn scan_repository(
221217 while !oids_queue. is_empty ( ) {
222218 py_signal_error = py. check_signals ( ) ;
223219 if py_signal_error. is_err ( ) {
224- should_stop. store ( true , Ordering :: Relaxed ) ;
220+ should_stop. store ( true ) ;
225221
226222 break ;
227223 }
0 commit comments