Skip to content

Commit

Permalink
Allow find object by prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Feb 2, 2024
1 parent 0731960 commit f3cab89
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,13 @@ extern "C" {
id: *const git_oid,
kind: git_object_t,
) -> c_int;
pub fn git_object_lookup_prefix(
dest: *mut *mut git_object,
repo: *mut git_repository,
id: *const git_oid,
len: size_t,
kind: git_object_t,
) -> c_int;
pub fn git_object_type(obj: *const git_object) -> git_object_t;
pub fn git_object_peel(
peeled: *mut *mut git_object,
Expand Down
19 changes: 19 additions & 0 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,25 @@ impl Repository {
}
}

/// Lookup a reference to one of the objects by id prefix in a repository.
pub fn find_object_by_prefix(
&self,
prefix_hash: &str,
kind: Option<ObjectType>,
) -> Result<Object<'_>, Error> {
let mut raw = ptr::null_mut();
unsafe {
try_call!(raw::git_object_lookup_prefix(
&mut raw,
self.raw(),
Oid::from_str(prefix_hash)?.raw(),
prefix_hash.len(),
kind
));
Ok(Binding::from_raw(raw))
}
}

/// Create a new direct reference.
///
/// This function will return an error if a reference already exists with
Expand Down

0 comments on commit f3cab89

Please sign in to comment.