1
+ use gix_object:: bstr:: ByteSlice ;
2
+ use gix_path:: RelativePath ;
1
3
use std:: {
2
4
borrow:: Cow ,
3
5
cmp:: Ordering ,
@@ -6,9 +8,6 @@ use std::{
6
8
path:: { Path , PathBuf } ,
7
9
} ;
8
10
9
- use gix_object:: bstr:: ByteSlice ;
10
- use gix_path:: RelativePath ;
11
-
12
11
use crate :: {
13
12
file:: loose:: { self , iter:: SortedLoosePaths } ,
14
13
store_impl:: { file, packed} ,
@@ -85,46 +84,40 @@ impl<'p> LooseThenPacked<'p, '_> {
85
84
}
86
85
87
86
fn convert_loose ( & mut self , res : std:: io:: Result < ( PathBuf , FullName ) > ) -> Result < Reference , Error > {
88
- convert_loose ( & mut self . buf , self . git_dir , self . common_dir , self . namespace , res)
89
- }
90
- }
91
-
92
- pub ( crate ) fn convert_loose (
93
- buf : & mut Vec < u8 > ,
94
- git_dir : & Path ,
95
- common_dir : Option < & Path > ,
96
- namespace : Option < & Namespace > ,
97
- res : std:: io:: Result < ( PathBuf , FullName ) > ,
98
- ) -> Result < Reference , Error > {
99
- let ( refpath, name) = res. map_err ( Error :: Traversal ) ?;
100
- std:: fs:: File :: open ( & refpath)
101
- . and_then ( |mut f| {
102
- buf. clear ( ) ;
103
- f. read_to_end ( buf)
104
- } )
105
- . map_err ( |err| Error :: ReadFileContents {
106
- source : err,
107
- path : refpath. to_owned ( ) ,
108
- } ) ?;
109
- loose:: Reference :: try_from_path ( name, buf)
110
- . map_err ( |err| {
111
- let relative_path = refpath
112
- . strip_prefix ( git_dir)
113
- . ok ( )
114
- . or_else ( || common_dir. and_then ( |common_dir| refpath. strip_prefix ( common_dir) . ok ( ) ) )
115
- . expect ( "one of our bases contains the path" ) ;
116
- Error :: ReferenceCreation {
87
+ let buf = & mut self . buf ;
88
+ let git_dir = self . git_dir ;
89
+ let common_dir = self . common_dir ;
90
+ let namespace = self . namespace ;
91
+ let ( refpath, name) = res. map_err ( Error :: Traversal ) ?;
92
+ std:: fs:: File :: open ( & refpath)
93
+ . and_then ( |mut f| {
94
+ buf. clear ( ) ;
95
+ f. read_to_end ( buf)
96
+ } )
97
+ . map_err ( |err| Error :: ReadFileContents {
117
98
source : err,
118
- relative_path : relative_path. into ( ) ,
119
- }
120
- } )
121
- . map ( Into :: into)
122
- . map ( |mut r : Reference | {
123
- if let Some ( namespace) = namespace {
124
- r. strip_namespace ( namespace) ;
125
- }
126
- r
127
- } )
99
+ path : refpath. to_owned ( ) ,
100
+ } ) ?;
101
+ loose:: Reference :: try_from_path ( name, buf)
102
+ . map_err ( |err| {
103
+ let relative_path = refpath
104
+ . strip_prefix ( git_dir)
105
+ . ok ( )
106
+ . or_else ( || common_dir. and_then ( |common_dir| refpath. strip_prefix ( common_dir) . ok ( ) ) )
107
+ . expect ( "one of our bases contains the path" ) ;
108
+ Error :: ReferenceCreation {
109
+ source : err,
110
+ relative_path : relative_path. into ( ) ,
111
+ }
112
+ } )
113
+ . map ( Into :: into)
114
+ . map ( |mut r : Reference | {
115
+ if let Some ( namespace) = namespace {
116
+ r. strip_namespace ( namespace) ;
117
+ }
118
+ r
119
+ } )
120
+ }
128
121
}
129
122
130
123
impl Iterator for LooseThenPacked < ' _ , ' _ > {
@@ -203,9 +196,9 @@ impl Iterator for LooseThenPacked<'_, '_> {
203
196
}
204
197
205
198
impl Platform < ' _ > {
206
- /// Return an iterator over all references, loose or ` packed` , sorted by their name.
199
+ /// Return an iterator over all references, loose or packed, sorted by their name.
207
200
///
208
- /// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.
201
+ /// Errors are returned similarly to what would happen when loose and packed refs were iterated by themselves.
209
202
pub fn all ( & self ) -> std:: io:: Result < LooseThenPacked < ' _ , ' _ > > {
210
203
self . store . iter_packed ( self . packed . as_ref ( ) . map ( |b| & * * * b) )
211
204
}
@@ -224,15 +217,15 @@ impl Platform<'_> {
224
217
}
225
218
226
219
/// Return an iterator over the pseudo references
227
- pub fn psuedo_refs ( & self ) -> std:: io:: Result < LooseThenPacked < ' _ , ' _ > > {
228
- self . store . iter_pseudo_refs ( )
220
+ pub fn pseudo_refs ( & self ) -> std:: io:: Result < LooseThenPacked < ' _ , ' _ > > {
221
+ self . store . iter_pseudo ( )
229
222
}
230
223
}
231
224
232
225
impl file:: Store {
233
226
/// Return a platform to obtain iterator over all references, or prefixed ones, loose or packed, sorted by their name.
234
227
///
235
- /// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.
228
+ /// Errors are returned similarly to what would happen when loose and packed refs were iterated by themselves.
236
229
///
237
230
/// Note that since packed-refs are storing refs as precomposed unicode if [`Self::precompose_unicode`] is true, for consistency
238
231
/// we also return loose references as precomposed unicode.
@@ -271,7 +264,7 @@ pub(crate) enum IterInfo<'a> {
271
264
/// If `true`, we will convert decomposed into precomposed unicode.
272
265
precompose_unicode : bool ,
273
266
} ,
274
- PseudoRefs {
267
+ Pseudo {
275
268
base : & ' a Path ,
276
269
precompose_unicode : bool ,
277
270
} ,
@@ -284,7 +277,7 @@ impl<'a> IterInfo<'a> {
284
277
IterInfo :: PrefixAndBase { prefix, .. } => Some ( gix_path:: into_bstr ( * prefix) ) ,
285
278
IterInfo :: BaseAndIterRoot { prefix, .. } => Some ( gix_path:: into_bstr ( prefix. clone ( ) ) ) ,
286
279
IterInfo :: ComputedIterationRoot { prefix, .. } => Some ( prefix. clone ( ) ) ,
287
- IterInfo :: PseudoRefs { .. } => None ,
280
+ IterInfo :: Pseudo { .. } => None ,
288
281
}
289
282
}
290
283
@@ -293,18 +286,18 @@ impl<'a> IterInfo<'a> {
293
286
IterInfo :: Base {
294
287
base,
295
288
precompose_unicode,
296
- } => SortedLoosePaths :: at ( & base. join ( "refs" ) , base. into ( ) , None , None , false , precompose_unicode) ,
289
+ } => SortedLoosePaths :: at ( & base. join ( "refs" ) , base. into ( ) , None , None , precompose_unicode) ,
297
290
IterInfo :: BaseAndIterRoot {
298
291
base,
299
292
iter_root,
300
293
prefix : _,
301
294
precompose_unicode,
302
- } => SortedLoosePaths :: at ( & iter_root, base. into ( ) , None , None , false , precompose_unicode) ,
295
+ } => SortedLoosePaths :: at ( & iter_root, base. into ( ) , None , None , precompose_unicode) ,
303
296
IterInfo :: PrefixAndBase {
304
297
base,
305
298
prefix,
306
299
precompose_unicode,
307
- } => SortedLoosePaths :: at ( & base. join ( prefix) , base. into ( ) , None , None , false , precompose_unicode) ,
300
+ } => SortedLoosePaths :: at ( & base. join ( prefix) , base. into ( ) , None , None , precompose_unicode) ,
308
301
IterInfo :: ComputedIterationRoot {
309
302
iter_root,
310
303
base,
@@ -315,13 +308,12 @@ impl<'a> IterInfo<'a> {
315
308
base. into ( ) ,
316
309
Some ( prefix. into_owned ( ) ) ,
317
310
None ,
318
- false ,
319
311
precompose_unicode,
320
312
) ,
321
- IterInfo :: PseudoRefs {
313
+ IterInfo :: Pseudo {
322
314
base,
323
315
precompose_unicode,
324
- } => SortedLoosePaths :: at ( base, base. into ( ) , None , Some ( "HEAD" . into ( ) ) , true , precompose_unicode) ,
316
+ } => SortedLoosePaths :: at ( base, base. into ( ) , None , Some ( "HEAD" . into ( ) ) , precompose_unicode) ,
325
317
}
326
318
. peekable ( )
327
319
}
@@ -354,7 +346,7 @@ impl<'a> IterInfo<'a> {
354
346
impl file:: Store {
355
347
/// Return an iterator over all references, loose or `packed`, sorted by their name.
356
348
///
357
- /// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.
349
+ /// Errors are returned similarly to what would happen when loose and packed refs were iterated by themselves.
358
350
pub fn iter_packed < ' s , ' p > (
359
351
& ' s self ,
360
352
packed : Option < & ' p packed:: Buffer > ,
@@ -387,12 +379,12 @@ impl file::Store {
387
379
}
388
380
}
389
381
390
- /// Return an iterator over all pseudo references, loose or `packed`, sorted by their name.
382
+ /// Return an iterator over all pseudo references, sorted by their name.
391
383
///
392
- /// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.
393
- pub fn iter_pseudo_refs < ' p > ( & ' _ self ) -> std:: io:: Result < LooseThenPacked < ' p , ' _ > > {
384
+ /// Errors are returned similarly to what would happen when loose refs were iterated by themselves.
385
+ pub fn iter_pseudo < ' p > ( & ' _ self ) -> std:: io:: Result < LooseThenPacked < ' p , ' _ > > {
394
386
self . iter_from_info (
395
- IterInfo :: PseudoRefs {
387
+ IterInfo :: Pseudo {
396
388
base : self . git_dir ( ) ,
397
389
precompose_unicode : self . precompose_unicode ,
398
390
} ,
0 commit comments