File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,21 @@ impl<'repo> Tree<'repo> {
176176 }
177177 }
178178
179+ /// Lookup a tree entry by its filename, specified as bytes.
180+ ///
181+ /// This allows for non-UTF-8 filenames.
182+ pub fn get_name_bytes ( & self , filename : & [ u8 ] ) -> Option < TreeEntry < ' _ > > {
183+ let filename = CString :: new ( filename) . unwrap ( ) ;
184+ unsafe {
185+ let ptr = call ! ( raw:: git_tree_entry_byname( & * self . raw( ) , filename) ) ;
186+ if ptr. is_null ( ) {
187+ None
188+ } else {
189+ Some ( entry_from_raw_const ( ptr) )
190+ }
191+ }
192+ }
193+
179194 /// Retrieve a tree entry contained in a tree or in any of its subtrees,
180195 /// given its relative path.
181196 pub fn get_path ( & self , path : & Path ) -> Result < TreeEntry < ' static > , Error > {
@@ -510,6 +525,7 @@ mod tests {
510525 let e1 = tree. get ( 0 ) . unwrap ( ) ;
511526 assert ! ( e1 == tree. get_id( e1. id( ) ) . unwrap( ) ) ;
512527 assert ! ( e1 == tree. get_name( "foo" ) . unwrap( ) ) ;
528+ assert ! ( e1 == tree. get_name_bytes( b"foo" ) . unwrap( ) ) ;
513529 assert ! ( e1 == tree. get_path( Path :: new( "foo" ) ) . unwrap( ) ) ;
514530 assert_eq ! ( e1. name( ) , Some ( "foo" ) ) ;
515531 e1. to_object ( & repo) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments