1
1
use crate :: {
2
2
error:: Result ,
3
3
sync:: { repo, CommitId , LogWalker , LogWalkerFilter , RepoPath } ,
4
- AsyncGitNotification ,
4
+ AsyncGitNotification , Error ,
5
5
} ;
6
6
use crossbeam_channel:: Sender ;
7
7
use scopetime:: scope_time;
@@ -15,7 +15,7 @@ use std::{
15
15
} ;
16
16
17
17
///
18
- #[ derive( PartialEq , Eq ) ]
18
+ #[ derive( PartialEq , Eq , Debug ) ]
19
19
pub enum FetchStatus {
20
20
/// previous fetch still running
21
21
Pending ,
@@ -40,6 +40,7 @@ pub struct AsyncLog {
40
40
pending : Arc < AtomicBool > ,
41
41
background : Arc < AtomicBool > ,
42
42
filter : Option < LogWalkerFilter > ,
43
+ partial_extract : AtomicBool ,
43
44
repo : RepoPath ,
44
45
}
45
46
@@ -65,6 +66,7 @@ impl AsyncLog {
65
66
pending : Arc :: new ( AtomicBool :: new ( false ) ) ,
66
67
background : Arc :: new ( AtomicBool :: new ( false ) ) ,
67
68
filter,
69
+ partial_extract : AtomicBool :: new ( false ) ,
68
70
}
69
71
}
70
72
@@ -89,21 +91,26 @@ impl AsyncLog {
89
91
90
92
///
91
93
pub 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
+
92
98
let list = & self . current . lock ( ) ?. commits ;
93
99
Ok ( list. clone ( ) )
94
100
}
95
101
96
102
///
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)
99
109
}
100
110
101
111
///
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 )
107
114
}
108
115
109
116
///
@@ -143,6 +150,8 @@ impl AsyncLog {
143
150
return Ok ( FetchStatus :: NoChange ) ;
144
151
}
145
152
153
+ self . pending . store ( true , Ordering :: Relaxed ) ;
154
+
146
155
self . clear ( ) ?;
147
156
148
157
let arc_current = Arc :: clone ( & self . current ) ;
@@ -152,8 +161,6 @@ impl AsyncLog {
152
161
let filter = self . filter . clone ( ) ;
153
162
let repo_path = self . repo . clone ( ) ;
154
163
155
- self . pending . store ( true , Ordering :: Relaxed ) ;
156
-
157
164
if let Ok ( head) = repo ( & self . repo ) ?. head ( ) {
158
165
* self . current_head . lock ( ) ? =
159
166
head. target ( ) . map ( CommitId :: new) ;
@@ -192,17 +199,16 @@ impl AsyncLog {
192
199
let r = repo ( repo_path) ?;
193
200
let mut walker =
194
201
LogWalker :: new ( & r, LIMIT_COUNT ) ?. filter ( filter) ;
202
+
195
203
loop {
196
204
entries. clear ( ) ;
197
- let res_is_err = walker. read ( & mut entries) . is_err ( ) ;
205
+ let read = walker. read ( & mut entries) ? ;
198
206
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 ( ) ;
204
210
205
- if res_is_err || entries . len ( ) <= 1 {
211
+ if read == 0 {
206
212
break ;
207
213
}
208
214
Self :: notify ( sender) ;
@@ -213,15 +219,19 @@ impl AsyncLog {
213
219
} else {
214
220
SLEEP_FOREGROUND
215
221
} ;
222
+
216
223
thread:: sleep ( sleep_duration) ;
217
224
}
218
225
226
+ log:: trace!( "revlog visited: {}" , walker. visited( ) ) ;
227
+
219
228
Ok ( ( ) )
220
229
}
221
230
222
231
fn clear ( & mut self ) -> Result < ( ) > {
223
232
self . current . lock ( ) ?. commits . clear ( ) ;
224
233
* self . current_head . lock ( ) ? = None ;
234
+ self . partial_extract . store ( false , Ordering :: Relaxed ) ;
225
235
Ok ( ( ) )
226
236
}
227
237
0 commit comments