Skip to content

Commit 502099a

Browse files
authored
Merge pull request #1011 from Brooooooklyn/master
Allow find commit by short hash prefix
2 parents 2d03f7e + ed5ac5f commit 502099a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: libgit2-sys/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,12 @@ extern "C" {
28272827
repo: *mut git_repository,
28282828
id: *const git_oid,
28292829
) -> c_int;
2830+
pub fn git_commit_lookup_prefix(
2831+
commit: *mut *mut git_commit,
2832+
repo: *mut git_repository,
2833+
id: *const git_oid,
2834+
len: size_t,
2835+
) -> c_int;
28302836
pub fn git_commit_message(commit: *const git_commit) -> *const c_char;
28312837
pub fn git_commit_message_encoding(commit: *const git_commit) -> *const c_char;
28322838
pub fn git_commit_message_raw(commit: *const git_commit) -> *const c_char;

Diff for: src/repo.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,20 @@ impl Repository {
14181418
}
14191419
}
14201420

1421+
/// Lookup a reference to one of the commits in a repository by short hash.
1422+
pub fn find_commit_by_prefix(&self, prefix_hash: &str) -> Result<Commit<'_>, Error> {
1423+
let mut raw = ptr::null_mut();
1424+
unsafe {
1425+
try_call!(raw::git_commit_lookup_prefix(
1426+
&mut raw,
1427+
self.raw(),
1428+
Oid::from_str(prefix_hash)?.raw(),
1429+
prefix_hash.len()
1430+
));
1431+
Ok(Binding::from_raw(raw))
1432+
}
1433+
}
1434+
14211435
/// Creates an `AnnotatedCommit` from the given commit id.
14221436
pub fn find_annotated_commit(&self, id: Oid) -> Result<AnnotatedCommit<'_>, Error> {
14231437
unsafe {

0 commit comments

Comments
 (0)