11use  crate :: { 
22	error:: Result , 
33	sync:: { repo,  CommitId ,  LogWalker ,  LogWalkerFilter ,  RepoPath } , 
4- 	AsyncGitNotification , 
4+ 	AsyncGitNotification ,   Error , 
55} ; 
66use  crossbeam_channel:: Sender ; 
77use  scopetime:: scope_time; 
@@ -15,7 +15,7 @@ use std::{
1515} ; 
1616
1717/// 
18- #[ derive( PartialEq ,  Eq ) ]  
18+ #[ derive( PartialEq ,  Eq ,   Debug ) ]  
1919pub  enum  FetchStatus  { 
2020	/// previous fetch still running 
2121Pending , 
@@ -40,6 +40,7 @@ pub struct AsyncLog {
4040	pending :  Arc < AtomicBool > , 
4141	background :  Arc < AtomicBool > , 
4242	filter :  Option < LogWalkerFilter > , 
43+ 	partial_extract :  AtomicBool , 
4344	repo :  RepoPath , 
4445} 
4546
@@ -65,6 +66,7 @@ impl AsyncLog {
6566			pending :  Arc :: new ( AtomicBool :: new ( false ) ) , 
6667			background :  Arc :: new ( AtomicBool :: new ( false ) ) , 
6768			filter, 
69+ 			partial_extract :  AtomicBool :: new ( false ) , 
6870		} 
6971	} 
7072
@@ -89,21 +91,26 @@ impl AsyncLog {
8991
9092	/// 
9193pub  fn  get_items ( & self )  -> Result < Vec < CommitId > >  { 
94+ 		if  self . partial_extract . load ( Ordering :: Relaxed )  { 
95+ 			return  Err ( Error :: Generic ( String :: from ( "Faulty usage of AsyncLog: Cannot partially extract items and rely on get_items slice to still work!" ) ) ) ; 
96+ 		} 
97+ 
9298		let  list = & self . current . lock ( ) ?. commits ; 
9399		Ok ( list. clone ( ) ) 
94100	} 
95101
96102	/// 
97- pub  fn  get_last_duration ( & self )  -> Result < Duration >  { 
98- 		Ok ( self . current . lock ( ) ?. duration ) 
103+ pub  fn  extract_items ( & self )  -> Result < Vec < CommitId > >  { 
104+ 		self . partial_extract . store ( true ,  Ordering :: Relaxed ) ; 
105+ 		let  list = & mut  self . current . lock ( ) ?. commits ; 
106+ 		let  result = list. clone ( ) ; 
107+ 		list. clear ( ) ; 
108+ 		Ok ( result) 
99109	} 
100110
101111	/// 
102- pub  fn  position ( & self ,  id :  CommitId )  -> Result < Option < usize > >  { 
103- 		let  list = & self . current . lock ( ) ?. commits ; 
104- 		let  position = list. iter ( ) . position ( |& x| x == id) ; 
105- 
106- 		Ok ( position) 
112+ pub  fn  get_last_duration ( & self )  -> Result < Duration >  { 
113+ 		Ok ( self . current . lock ( ) ?. duration ) 
107114	} 
108115
109116	/// 
@@ -143,6 +150,8 @@ impl AsyncLog {
143150			return  Ok ( FetchStatus :: NoChange ) ; 
144151		} 
145152
153+ 		self . pending . store ( true ,  Ordering :: Relaxed ) ; 
154+ 
146155		self . clear ( ) ?; 
147156
148157		let  arc_current = Arc :: clone ( & self . current ) ; 
@@ -152,8 +161,6 @@ impl AsyncLog {
152161		let  filter = self . filter . clone ( ) ; 
153162		let  repo_path = self . repo . clone ( ) ; 
154163
155- 		self . pending . store ( true ,  Ordering :: Relaxed ) ; 
156- 
157164		if  let  Ok ( head)  = repo ( & self . repo ) ?. head ( )  { 
158165			* self . current_head . lock ( ) ? =
159166				head. target ( ) . map ( CommitId :: new) ; 
@@ -192,17 +199,16 @@ impl AsyncLog {
192199		let  r = repo ( repo_path) ?; 
193200		let  mut  walker =
194201			LogWalker :: new ( & r,  LIMIT_COUNT ) ?. filter ( filter) ; 
202+ 
195203		loop  { 
196204			entries. clear ( ) ; 
197- 			let  res_is_err  = walker. read ( & mut  entries) . is_err ( ) ; 
205+ 			let  read  = walker. read ( & mut  entries) ? ; 
198206
199- 			if  !res_is_err { 
200- 				let  mut  current = arc_current. lock ( ) ?; 
201- 				current. commits . extend ( entries. iter ( ) ) ; 
202- 				current. duration  = start_time. elapsed ( ) ; 
203- 			} 
207+ 			let  mut  current = arc_current. lock ( ) ?; 
208+ 			current. commits . extend ( entries. iter ( ) ) ; 
209+ 			current. duration  = start_time. elapsed ( ) ; 
204210
205- 			if  res_is_err || entries . len ( )  <=  1  { 
211+ 			if  read ==  0  { 
206212				break ; 
207213			} 
208214			Self :: notify ( sender) ; 
@@ -213,15 +219,19 @@ impl AsyncLog {
213219				}  else  { 
214220					SLEEP_FOREGROUND 
215221				} ; 
222+ 
216223			thread:: sleep ( sleep_duration) ; 
217224		} 
218225
226+ 		log:: trace!( "revlog visited: {}" ,  walker. visited( ) ) ; 
227+ 
219228		Ok ( ( ) ) 
220229	} 
221230
222231	fn  clear ( & mut  self )  -> Result < ( ) >  { 
223232		self . current . lock ( ) ?. commits . clear ( ) ; 
224233		* self . current_head . lock ( ) ? = None ; 
234+ 		self . partial_extract . store ( false ,  Ordering :: Relaxed ) ; 
225235		Ok ( ( ) ) 
226236	} 
227237
0 commit comments