@@ -21,12 +21,9 @@ pub mod configuration {
21
21
22
22
///
23
23
pub mod to_git {
24
- use bstr:: BStr ;
25
-
26
- /// A function that writes a buffer like `fn(rela_path, &mut buf)` with by tes of an object in the index that is the one
27
- /// that should be converted.
24
+ /// A function that fills `buf` `fn(&mut buf)` with the data stored in the index of the file that should be converted.
28
25
pub type IndexObjectFn < ' a > =
29
- dyn FnMut ( & BStr , & mut Vec < u8 > ) -> Result < Option < ( ) > , Box < dyn std:: error:: Error + Send + Sync > > + ' a ;
26
+ dyn FnMut ( & mut Vec < u8 > ) -> Result < Option < ( ) > , Box < dyn std:: error:: Error + Send + Sync > > + ' a ;
30
27
31
28
/// The error returned by [Pipeline::convert_to_git()][super::Pipeline::convert_to_git()].
32
29
#[ derive( Debug , thiserror:: Error ) ]
@@ -91,7 +88,7 @@ impl Pipeline {
91
88
self . options . eol_config ,
92
89
) ?;
93
90
94
- let mut changed = false ;
91
+ let mut in_buffer = false ;
95
92
// this is just an approximation, but it's as good as it gets without reading the actual input.
96
93
let would_convert_eol = eol:: convert_to_git (
97
94
b"\r \n " ,
@@ -119,12 +116,13 @@ impl Pipeline {
119
116
}
120
117
self . bufs . clear ( ) ;
121
118
read. read_to_end ( & mut self . bufs . src ) ?;
122
- changed = true ;
119
+ in_buffer = true ;
123
120
}
124
121
}
125
- if !changed && ( apply_ident_filter || encoding. is_some ( ) || would_convert_eol) {
122
+ if !in_buffer && ( apply_ident_filter || encoding. is_some ( ) || would_convert_eol) {
126
123
self . bufs . clear ( ) ;
127
124
src. read_to_end ( & mut self . bufs . src ) ?;
125
+ in_buffer = true ;
128
126
}
129
127
130
128
if let Some ( encoding) = encoding {
@@ -139,28 +137,25 @@ impl Pipeline {
139
137
} ,
140
138
) ?;
141
139
self . bufs . swap ( ) ;
142
- changed = true ;
143
140
}
144
141
145
142
if eol:: convert_to_git (
146
143
& self . bufs . src ,
147
144
digest,
148
145
& mut self . bufs . dest ,
149
- & mut |buf| index_object ( bstr_path . as_ref ( ) , buf) ,
146
+ & mut |buf| index_object ( buf) ,
150
147
eol:: convert_to_git:: Options {
151
148
round_trip_check : self . options . crlf_roundtrip_check . to_eol_roundtrip_check ( rela_path) ,
152
149
config : self . options . eol_config ,
153
150
} ,
154
151
) ? {
155
152
self . bufs . swap ( ) ;
156
- changed = true ;
157
153
}
158
154
159
155
if apply_ident_filter && ident:: undo ( & self . bufs . src , & mut self . bufs . dest ) {
160
156
self . bufs . swap ( ) ;
161
- changed = true ;
162
157
}
163
- Ok ( if changed {
158
+ Ok ( if in_buffer {
164
159
ToGitOutcome :: Buffer ( & self . bufs . src )
165
160
} else {
166
161
ToGitOutcome :: Unchanged ( src)
@@ -325,12 +320,12 @@ where
325
320
}
326
321
}
327
322
328
- impl < R > ToGitOutcome < ' _ , R >
323
+ impl < ' a , R > ToGitOutcome < ' a , R >
329
324
where
330
325
R : std:: io:: Read ,
331
326
{
332
327
/// If we contain a buffer, and not a stream, return it.
333
- pub fn as_bytes ( & self ) -> Option < & [ u8 ] > {
328
+ pub fn as_bytes ( & self ) -> Option < & ' a [ u8 ] > {
334
329
match self {
335
330
ToGitOutcome :: Unchanged ( _) | ToGitOutcome :: Process ( _) => None ,
336
331
ToGitOutcome :: Buffer ( b) => Some ( b) ,
0 commit comments