1
1
use crate :: {
2
- error:: Result , hash, sync, sync:: status:: StatusType ,
3
- AsyncNotification , StatusItem , CWD ,
2
+ error:: Result , hash, sync, AsyncNotification , StatusItem , CWD ,
4
3
} ;
5
4
use crossbeam_channel:: Sender ;
6
5
use log:: trace;
@@ -10,12 +9,42 @@ use std::{
10
9
atomic:: { AtomicUsize , Ordering } ,
11
10
Arc , Mutex ,
12
11
} ,
12
+ time:: { SystemTime , UNIX_EPOCH } ,
13
13
} ;
14
+ use sync:: status:: StatusType ;
15
+
16
+ fn current_tick ( ) -> u64 {
17
+ SystemTime :: now ( )
18
+ . duration_since ( UNIX_EPOCH )
19
+ . unwrap ( )
20
+ . as_millis ( ) as u64
21
+ }
14
22
15
23
#[ derive( Default , Hash , Clone ) ]
16
24
pub struct Status {
17
- pub work_dir : Vec < StatusItem > ,
18
- pub stage : Vec < StatusItem > ,
25
+ pub items : Vec < StatusItem > ,
26
+ }
27
+
28
+ ///
29
+ #[ derive( Default , Hash , Clone , PartialEq ) ]
30
+ pub struct StatusParams {
31
+ tick : u64 ,
32
+ status_type : StatusType ,
33
+ include_untracked : bool ,
34
+ }
35
+
36
+ impl StatusParams {
37
+ ///
38
+ pub fn new (
39
+ status_type : StatusType ,
40
+ include_untracked : bool ,
41
+ ) -> Self {
42
+ Self {
43
+ tick : current_tick ( ) ,
44
+ status_type,
45
+ include_untracked,
46
+ }
47
+ }
19
48
}
20
49
21
50
struct Request < R , A > ( R , Option < A > ) ;
@@ -51,10 +80,13 @@ impl AsyncStatus {
51
80
}
52
81
53
82
///
54
- pub fn fetch ( & mut self , request : u64 ) -> Result < Option < Status > > {
55
- let hash_request = hash ( & request) ;
83
+ pub fn fetch (
84
+ & mut self ,
85
+ params : StatusParams ,
86
+ ) -> Result < Option < Status > > {
87
+ let hash_request = hash ( & params) ;
56
88
57
- trace ! ( "request: {} [hash: {}]" , request , hash_request) ;
89
+ trace ! ( "request: [hash: {}]" , hash_request) ;
58
90
59
91
{
60
92
let mut current = self . current . lock ( ) ?;
@@ -71,10 +103,14 @@ impl AsyncStatus {
71
103
let arc_last = Arc :: clone ( & self . last ) ;
72
104
let sender = self . sender . clone ( ) ;
73
105
let arc_pending = Arc :: clone ( & self . pending ) ;
106
+ let status_type = params. status_type ;
107
+ let include_untracked = params. include_untracked ;
74
108
rayon_core:: spawn ( move || {
75
109
arc_pending. fetch_add ( 1 , Ordering :: Relaxed ) ;
76
110
77
- AsyncStatus :: fetch_helper (
111
+ Self :: fetch_helper (
112
+ status_type,
113
+ include_untracked,
78
114
hash_request,
79
115
arc_current,
80
116
arc_last,
@@ -92,11 +128,13 @@ impl AsyncStatus {
92
128
}
93
129
94
130
fn fetch_helper (
131
+ status_type : StatusType ,
132
+ include_untracked : bool ,
95
133
hash_request : u64 ,
96
134
arc_current : Arc < Mutex < Request < u64 , Status > > > ,
97
135
arc_last : Arc < Mutex < Status > > ,
98
136
) -> Result < ( ) > {
99
- let res = Self :: get_status ( ) ?;
137
+ let res = Self :: get_status ( status_type , include_untracked ) ?;
100
138
trace ! ( "status fetched: {}" , hash( & res) ) ;
101
139
102
140
{
@@ -114,11 +152,16 @@ impl AsyncStatus {
114
152
Ok ( ( ) )
115
153
}
116
154
117
- fn get_status ( ) -> Result < Status > {
118
- let work_dir =
119
- sync:: status:: get_status ( CWD , StatusType :: WorkingDir ) ?;
120
- let stage = sync:: status:: get_status ( CWD , StatusType :: Stage ) ?;
121
-
122
- Ok ( Status { stage, work_dir } )
155
+ fn get_status (
156
+ status_type : StatusType ,
157
+ include_untracked : bool ,
158
+ ) -> Result < Status > {
159
+ Ok ( Status {
160
+ items : sync:: status:: get_status_new (
161
+ CWD ,
162
+ status_type,
163
+ include_untracked,
164
+ ) ?,
165
+ } )
123
166
}
124
167
}
0 commit comments