1
1
use crate :: {
2
2
borrowed:: { Band , Text } ,
3
- Reader , RemoteProgress , MAX_DATA_LEN ,
3
+ Reader , MAX_DATA_LEN ,
4
4
} ;
5
- use bstr:: ByteSlice ;
6
- use git_features:: { progress, progress:: Progress } ;
7
5
use std:: io;
8
6
9
- type ProgressAndParser < P > = ( P , fn ( & [ u8 ] ) -> Option < RemoteProgress > ) ;
10
-
11
- pub struct ReadWithProgress < ' a , T , P >
7
+ pub struct ReadWithSidebands < ' a , T , F >
12
8
where
13
9
T : io:: Read ,
14
10
{
15
11
parent : & ' a mut Reader < T > ,
16
- progress_and_parse : Option < ProgressAndParser < P > > ,
12
+ handle_progress : Option < F > ,
17
13
buf : Vec < u8 > ,
18
14
pos : usize ,
19
15
cap : usize ,
20
16
}
21
17
22
- impl < ' a , T , P > Drop for ReadWithProgress < ' a , T , P >
18
+ impl < ' a , T , F > Drop for ReadWithSidebands < ' a , T , F >
23
19
where
24
20
T : io:: Read ,
25
21
{
@@ -28,45 +24,41 @@ where
28
24
}
29
25
}
30
26
31
- impl < ' a , T > ReadWithProgress < ' a , T , progress :: Discard >
27
+ impl < ' a , T > ReadWithSidebands < ' a , T , fn ( bool , & [ u8 ] ) >
32
28
where
33
29
T : io:: Read ,
34
30
{
35
31
pub fn new ( parent : & ' a mut Reader < T > ) -> Self {
36
- ReadWithProgress {
32
+ ReadWithSidebands {
37
33
parent,
38
- progress_and_parse : None ,
34
+ handle_progress : None ,
39
35
buf : vec ! [ 0 ; MAX_DATA_LEN ] ,
40
36
pos : 0 ,
41
37
cap : 0 ,
42
38
}
43
39
}
44
40
}
45
41
46
- impl < ' a , T , P > ReadWithProgress < ' a , T , P >
42
+ impl < ' a , T , F > ReadWithSidebands < ' a , T , F >
47
43
where
48
44
T : io:: Read ,
49
- P : Progress ,
45
+ F : FnMut ( bool , & [ u8 ] ) ,
50
46
{
51
- pub fn with_progress (
52
- parent : & ' a mut Reader < T > ,
53
- progress : P ,
54
- parse_progress : fn ( & [ u8 ] ) -> Option < RemoteProgress > ,
55
- ) -> Self {
56
- ReadWithProgress {
47
+ pub fn with_progress_handler ( parent : & ' a mut Reader < T > , handle_progress : F ) -> Self {
48
+ ReadWithSidebands {
57
49
parent,
58
- progress_and_parse : Some ( ( progress , parse_progress ) ) ,
50
+ handle_progress : Some ( handle_progress ) ,
59
51
buf : vec ! [ 0 ; MAX_DATA_LEN ] ,
60
52
pos : 0 ,
61
53
cap : 0 ,
62
54
}
63
55
}
64
56
}
65
57
66
- impl < ' a , T , P > io:: BufRead for ReadWithProgress < ' a , T , P >
58
+ impl < ' a , T , F > io:: BufRead for ReadWithSidebands < ' a , T , F >
67
59
where
68
60
T : io:: Read ,
69
- P : Progress ,
61
+ F : FnMut ( bool , & [ u8 ] ) ,
70
62
{
71
63
fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > {
72
64
use io:: Read ;
@@ -77,38 +69,21 @@ where
77
69
Some ( line) => line?. map_err ( |err| io:: Error :: new ( io:: ErrorKind :: Other , err) ) ?,
78
70
None => break 0 ,
79
71
} ;
80
- match self . progress_and_parse . as_mut ( ) {
81
- Some ( ( progress , parse_progress ) ) => {
72
+ match self . handle_progress . as_mut ( ) {
73
+ Some ( handle_progress ) => {
82
74
let mut band = line
83
75
. decode_band ( )
84
76
. map_err ( |err| io:: Error :: new ( io:: ErrorKind :: Other , err) ) ?;
85
- fn progress_name ( current : Option < String > , action : & [ u8 ] ) -> String {
86
- match current {
87
- Some ( current) => format ! ( "{}: {}" , current, action. as_bstr( ) ) ,
88
- None => action. as_bstr ( ) . to_string ( ) ,
89
- }
90
- }
91
77
match band {
92
78
Band :: Data ( ref mut d) => break d. read ( & mut self . buf ) ?,
93
79
Band :: Progress ( d) => {
94
80
let text = Text :: from ( d) . 0 ;
95
- match ( parse_progress) ( text) {
96
- Some ( RemoteProgress {
97
- action,
98
- percent : _,
99
- step,
100
- max,
101
- } ) => {
102
- progress. set_name ( progress_name ( progress. name ( ) , action) ) ;
103
- progress. init ( max, git_features:: progress:: count ( "objects" ) ) ;
104
- if let Some ( step) = step {
105
- progress. set ( step) ;
106
- }
107
- }
108
- None => progress. set_name ( progress_name ( progress. name ( ) , text) ) ,
109
- } ;
81
+ ( handle_progress) ( false , text) ;
82
+ }
83
+ Band :: Error ( d) => {
84
+ let text = Text :: from ( d) . 0 ;
85
+ ( handle_progress) ( true , text) ;
110
86
}
111
- Band :: Error ( d) => progress. fail ( progress_name ( None , Text :: from ( d) . as_slice ( ) ) ) ,
112
87
} ;
113
88
}
114
89
None => {
@@ -134,10 +109,10 @@ where
134
109
}
135
110
}
136
111
137
- impl < ' a , T , P > io:: Read for ReadWithProgress < ' a , T , P >
112
+ impl < ' a , T , F > io:: Read for ReadWithSidebands < ' a , T , F >
138
113
where
139
114
T : io:: Read ,
140
- P : Progress ,
115
+ F : FnMut ( bool , & [ u8 ] ) ,
141
116
{
142
117
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
143
118
use std:: io:: BufRead ;
0 commit comments