Skip to content

Commit d73c3f8

Browse files
committed
remove GIT_ENOTFOUND check and instead return it as an Err
1 parent 4a67c0b commit d73c3f8

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/index.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -600,20 +600,16 @@ impl Index {
600600
/// Find the first position of any entries matching a prefix.
601601
///
602602
/// 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()?;
604606
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(
608608
&mut at_pos,
609609
self.raw,
610610
entry_path
611611
));
612-
if result == 0 {
613-
Ok(Some(at_pos))
614-
} else {
615-
Ok(None)
616-
}
612+
Ok(at_pos)
617613
}
618614
}
619615
}
@@ -766,7 +762,7 @@ mod tests {
766762
use std::path::Path;
767763
use tempfile::TempDir;
768764

769-
use crate::{Index, IndexEntry, IndexTime, Oid, Repository, ResetType};
765+
use crate::{ErrorCode, Index, IndexEntry, IndexTime, Oid, Repository, ResetType};
770766

771767
#[test]
772768
fn smoke() {
@@ -891,8 +887,11 @@ mod tests {
891887
index.get_path(Path::new("foo/bar"), 0).unwrap().path,
892888
b"foo/bar"
893889
);
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+
);
896895
}
897896

898897
#[test]

0 commit comments

Comments
 (0)