@@ -600,20 +600,16 @@ impl Index {
600
600
/// Find the first position of any entries matching a prefix.
601
601
///
602
602
/// To find the first position of a path inside a given folder, suffix the prefix with a '/'.
603
- pub fn find_prefix < T : IntoCString > ( & self , prefix : T ) -> Result < Option < usize > , Error > {
603
+ pub fn find_prefix < T : IntoCString > ( & self , prefix : T ) -> Result < usize , Error > {
604
+ let mut at_pos: size_t = 0 ;
605
+ let entry_path = prefix. into_c_string ( ) ?;
604
606
unsafe {
605
- let mut at_pos: size_t = 0 ;
606
- let entry_path = prefix. into_c_string ( ) ?;
607
- let result = call ! ( raw:: git_index_find_prefix(
607
+ try_call ! ( raw:: git_index_find_prefix(
608
608
& mut at_pos,
609
609
self . raw,
610
610
entry_path
611
611
) ) ;
612
- if result == 0 {
613
- Ok ( Some ( at_pos) )
614
- } else {
615
- Ok ( None )
616
- }
612
+ Ok ( at_pos)
617
613
}
618
614
}
619
615
}
@@ -766,7 +762,7 @@ mod tests {
766
762
use std:: path:: Path ;
767
763
use tempfile:: TempDir ;
768
764
769
- use crate :: { Index , IndexEntry , IndexTime , Oid , Repository , ResetType } ;
765
+ use crate :: { ErrorCode , Index , IndexEntry , IndexTime , Oid , Repository , ResetType } ;
770
766
771
767
#[ test]
772
768
fn smoke ( ) {
@@ -891,8 +887,11 @@ mod tests {
891
887
index. get_path( Path :: new( "foo/bar" ) , 0 ) . unwrap( ) . path,
892
888
b"foo/bar"
893
889
) ;
894
- assert_eq ! ( index. find_prefix( Path :: new( "foo2/" ) ) . unwrap( ) , Some ( 1 ) ) ;
895
- assert_eq ! ( index. find_prefix( Path :: new( "empty/" ) ) . unwrap( ) , None ) ;
890
+ assert_eq ! ( index. find_prefix( Path :: new( "foo2/" ) ) , Ok ( 1 ) ) ;
891
+ assert_eq ! (
892
+ index. find_prefix( Path :: new( "empty/" ) ) . unwrap_err( ) . code( ) ,
893
+ ErrorCode :: NotFound
894
+ ) ;
896
895
}
897
896
898
897
#[ test]
0 commit comments