Skip to content

Commit 625f9dd

Browse files
cruesslerByron
authored andcommitted
feat: Add commit::Either::tree_id()
1 parent c8c42b4 commit 625f9dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

gix-traverse/src/commit/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ pub enum Either<'buf, 'cache> {
7777
CachedCommit(gix_commitgraph::file::Commit<'cache>),
7878
}
7979

80+
impl Either<'_, '_> {
81+
/// Get a commits `tree_id` by either getting it from a [`gix_commitgraph::Graph`], if
82+
/// present, or a [`gix_object::CommitRefIter`] otherwise.
83+
pub fn tree_id(self) -> Result<ObjectId, gix_object::decode::Error> {
84+
match self {
85+
Self::CommitRefIter(mut commit_ref_iter) => commit_ref_iter.tree_id(),
86+
Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()),
87+
}
88+
}
89+
}
90+
8091
/// Find information about a commit by either getting it from a [`gix_commitgraph::Graph`], if
8192
/// present, or a [`gix_object::CommitRefIter`] otherwise.
8293
pub fn find<'cache, 'buf, Find>(

0 commit comments

Comments
 (0)