Skip to content

Commit 5920cb1

Browse files
committed
Bind git_commit_tree
1 parent 0deb0d3 commit 5920cb1

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

libgit2-sys/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ extern {
12401240
pub fn git_commit_time(commit: *const git_commit) -> git_time_t;
12411241
pub fn git_commit_time_offset(commit: *const git_commit) -> c_int;
12421242
pub fn git_commit_tree(tree_out: *mut *mut git_tree,
1243-
commit: *const git_commit) -> c_uint;
1243+
commit: *const git_commit) -> c_int;
12441244
pub fn git_commit_tree_id(commit: *const git_commit) -> *const git_oid;
12451245
pub fn git_commit_amend(id: *mut git_oid,
12461246
commit_to_amend: *const git_commit,

src/commit.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,20 @@ impl<'a> Commit<'a> {
4949

5050
/// Get the id of the tree pointed to by this commit.
5151
///
52-
/// No attempts are made to fetch an object from the
52+
/// No attempts are made to fetch an object from the ODB.
5353
pub fn tree_id(&self) -> Oid {
5454
unsafe { Oid::from_raw(raw::git_commit_tree_id(&*self.raw)) }
5555
}
5656

57+
/// Get the tree pointed to by a commit.
58+
pub fn tree(&self) -> Result<Tree, Error> {
59+
let mut ret = 0 as *mut raw::git_tree;
60+
unsafe {
61+
try_call!(raw::git_commit_tree(&mut ret, &*self.raw));
62+
Ok(Tree::from_raw(ret))
63+
}
64+
}
65+
5766
/// Get access to the underlying raw pointer.
5867
pub fn raw(&self) -> *mut raw::git_commit { self.raw }
5968

@@ -298,6 +307,7 @@ mod tests {
298307
commit.message_encoding();
299308
commit.summary().unwrap();
300309
commit.tree_id();
310+
commit.tree().unwrap();
301311
assert_eq!(commit.parents().count(), 0);
302312

303313
assert_eq!(commit.author().name(), Some("name"));

src/repo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl Repository {
783783
let mut raw = 0 as *mut raw::git_tree;
784784
unsafe {
785785
try_call!(raw::git_tree_lookup(&mut raw, self.raw(), oid.raw()));
786-
Ok(Tree::from_raw(self, raw))
786+
Ok(Tree::from_raw(raw))
787787
}
788788
}
789789

src/tree.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ impl<'repo> Tree<'repo> {
3030
///
3131
/// This method is unsafe as there is no guarantee that `raw` is a valid
3232
/// pointer.
33-
pub unsafe fn from_raw(_repo: &Repository,
34-
raw: *mut raw::git_tree) -> Tree {
33+
pub unsafe fn from_raw(raw: *mut raw::git_tree) -> Tree<'repo> {
3534
Tree {
3635
raw: raw,
3736
marker1: marker::ContravariantLifetime,

0 commit comments

Comments
 (0)