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> {
176
176
}
177
177
}
178
178
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
+
179
194
/// Retrieve a tree entry contained in a tree or in any of its subtrees,
180
195
/// given its relative path.
181
196
pub fn get_path ( & self , path : & Path ) -> Result < TreeEntry < ' static > , Error > {
@@ -510,6 +525,7 @@ mod tests {
510
525
let e1 = tree. get ( 0 ) . unwrap ( ) ;
511
526
assert ! ( e1 == tree. get_id( e1. id( ) ) . unwrap( ) ) ;
512
527
assert ! ( e1 == tree. get_name( "foo" ) . unwrap( ) ) ;
528
+ assert ! ( e1 == tree. get_name_bytes( b"foo" ) . unwrap( ) ) ;
513
529
assert ! ( e1 == tree. get_path( Path :: new( "foo" ) ) . unwrap( ) ) ;
514
530
assert_eq ! ( e1. name( ) , Some ( "foo" ) ) ;
515
531
e1. to_object ( & repo) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments