@@ -195,9 +195,16 @@ impl Platform<'_> {
195195 self . store . iter_packed ( self . packed . as_ref ( ) . map ( |b| & * * * b) )
196196 }
197197
198- /// As [`iter(…)`][ file::Store::iter()] , but filters by `prefix`, i.e. "refs/heads/" or
198+ /// As [`iter(…)`]( file::Store::iter()) , but filters by `prefix`, i.e. "refs/heads/" or
199199 /// "refs/heads/feature-".
200- pub fn prefixed < ' a > ( & self , prefix : impl Into < Cow < ' a , BStr > > ) -> std:: io:: Result < LooseThenPacked < ' _ , ' _ > > {
200+ ///
201+ /// Note that if a prefix isn't using a trailing `/`, like in `refs/heads/foo`, it will effectively
202+ /// start the traversal in the parent directory, e.g. `refs/heads/` and list everything inside that
203+ /// starts with `foo`, like `refs/heads/foo` and `refs/heads/foobar`.
204+ ///
205+ /// Prefixes are relative paths with slash-separated components.
206+ // TODO: use `RelativePath` type instead (see #1921), or a trait that helps convert into it.
207+ pub fn prefixed < ' a > ( & self , prefix : impl Into < & ' a BStr > ) -> std:: io:: Result < LooseThenPacked < ' _ , ' _ > > {
201208 self . store
202209 . iter_prefixed_packed ( prefix. into ( ) , self . packed . as_ref ( ) . map ( |b| & * * * b) )
203210 }
@@ -227,7 +234,7 @@ pub(crate) enum IterInfo<'a> {
227234 BaseAndIterRoot {
228235 base : & ' a Path ,
229236 iter_root : PathBuf ,
230- prefix : Cow < ' a , Path > ,
237+ prefix : PathBuf ,
231238 precompose_unicode : bool ,
232239 } ,
233240 PrefixAndBase {
@@ -238,9 +245,9 @@ pub(crate) enum IterInfo<'a> {
238245 ComputedIterationRoot {
239246 /// The root to iterate over
240247 iter_root : PathBuf ,
241- /// The top-level directory as boundary of all references, used to create their short-names after iteration
248+ /// The top-level directory as boundary of all references, used to create their short-names after iteration.
242249 base : & ' a Path ,
243- /// The original prefix
250+ /// The original prefix.
244251 prefix : Cow < ' a , BStr > ,
245252 /// If `true`, we will convert decomposed into precomposed unicode.
246253 precompose_unicode : bool ,
@@ -290,7 +297,7 @@ impl<'a> IterInfo<'a> {
290297 precompose_unicode : bool ,
291298 ) -> std:: io:: Result < Self > {
292299 let prefix = prefix. into ( ) ;
293- let prefix_path = gix_path:: from_bstring ( prefix. clone ( ) . into_owned ( ) ) ;
300+ let prefix_path = gix_path:: from_bstr ( prefix. as_ref ( ) ) ;
294301 if prefix_path. is_absolute ( ) {
295302 return Err ( std:: io:: Error :: new (
296303 std:: io:: ErrorKind :: InvalidInput ,
@@ -309,7 +316,7 @@ impl<'a> IterInfo<'a> {
309316 Ok ( IterInfo :: BaseAndIterRoot {
310317 base,
311318 iter_root,
312- prefix : prefix_path. into ( ) ,
319+ prefix : prefix_path. into_owned ( ) ,
313320 precompose_unicode,
314321 } )
315322 } else {
@@ -363,24 +370,31 @@ impl file::Store {
363370 }
364371 }
365372
366- /// As [`iter(…)`][file::Store::iter()], but filters by `prefix`, i.e. "refs/heads/" or
367- /// "refs/heads/feature-".
368- pub fn iter_prefixed_packed < ' s , ' p > (
373+ /// As [`iter(…)`](file::Store::iter()), but filters by `prefix`, i.e. `refs/heads/` or
374+ /// `refs/heads/feature-`.
375+ /// Note that if a prefix isn't using a trailing `/`, like in `refs/heads/foo`, it will effectively
376+ /// start the traversal in the parent directory, e.g. `refs/heads/` and list everything inside that
377+ /// starts with `foo`, like `refs/heads/foo` and `refs/heads/foobar`.
378+ ///
379+ /// Prefixes are relative paths with slash-separated components.
380+ // TODO: use `RelativePath` type instead (see #1921), or a trait that helps convert into it.
381+ pub fn iter_prefixed_packed < ' a , ' s , ' p > (
369382 & ' s self ,
370- prefix : Cow < ' _ , BStr > ,
383+ prefix : impl Into < & ' a BStr > ,
371384 packed : Option < & ' p packed:: Buffer > ,
372385 ) -> std:: io:: Result < LooseThenPacked < ' p , ' s > > {
386+ let prefix = prefix. into ( ) ;
373387 match self . namespace . as_ref ( ) {
374388 None => {
375- let git_dir_info = IterInfo :: from_prefix ( self . git_dir ( ) , prefix. clone ( ) , self . precompose_unicode ) ?;
389+ let git_dir_info = IterInfo :: from_prefix ( self . git_dir ( ) , prefix, self . precompose_unicode ) ?;
376390 let common_dir_info = self
377391 . common_dir ( )
378392 . map ( |base| IterInfo :: from_prefix ( base, prefix, self . precompose_unicode ) )
379393 . transpose ( ) ?;
380394 self . iter_from_info ( git_dir_info, common_dir_info, packed)
381395 }
382396 Some ( namespace) => {
383- let prefix = namespace. to_owned ( ) . into_namespaced_prefix ( & prefix) ;
397+ let prefix = namespace. to_owned ( ) . into_namespaced_prefix ( prefix) ;
384398 let git_dir_info = IterInfo :: from_prefix ( self . git_dir ( ) , prefix. clone ( ) , self . precompose_unicode ) ?;
385399 let common_dir_info = self
386400 . common_dir ( )
0 commit comments