Skip to content

Commit 4a67c0b

Browse files
committed
use generic IntoCString instead of only path as a prefix arg for find_prefix
1 parent c1e4ae1 commit 4a67c0b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/index.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,10 @@ 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(&self, path: &Path) -> Result<Option<usize>, Error> {
603+
pub fn find_prefix<T: IntoCString>(&self, prefix: T) -> Result<Option<usize>, Error> {
604604
unsafe {
605605
let mut at_pos: size_t = 0;
606-
let entry_path = path.into_c_string()?;
606+
let entry_path = prefix.into_c_string()?;
607607
let result = call!(raw::git_index_find_prefix(
608608
&mut at_pos,
609609
self.raw,
@@ -883,12 +883,15 @@ mod tests {
883883
let mut e = entry();
884884
e.path = b"foo/bar".to_vec();
885885
index.add(&e).unwrap();
886+
let mut e = entry();
887+
e.path = b"foo2/bar".to_vec();
888+
index.add(&e).unwrap();
886889
assert_eq!(index.get(0).unwrap().path, b"foo/bar");
887890
assert_eq!(
888891
index.get_path(Path::new("foo/bar"), 0).unwrap().path,
889892
b"foo/bar"
890893
);
891-
assert_eq!(index.find_prefix(Path::new("foo/")).unwrap(), Some(0));
894+
assert_eq!(index.find_prefix(Path::new("foo2/")).unwrap(), Some(1));
892895
assert_eq!(index.find_prefix(Path::new("empty/")).unwrap(), None);
893896
}
894897

0 commit comments

Comments
 (0)