Skip to content

Commit b40ba17

Browse files
committed
feat: Add commit::Either::commit_time()
1 parent de13b16 commit b40ba17

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

gix-traverse/src/commit/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,23 @@ pub enum Either<'buf, 'cache> {
7777
}
7878

7979
impl Either<'_, '_> {
80-
/// Get a commits `tree_id` by either getting it from a [`gix_commitgraph::Graph`], if
80+
/// Get a commit’s `tree_id` by either getting it from a [`gix_commitgraph::Graph`], if
8181
/// present, or a [`gix_object::CommitRefIter`] otherwise.
8282
pub fn tree_id(self) -> Result<ObjectId, gix_object::decode::Error> {
8383
match self {
8484
Self::CommitRefIter(mut commit_ref_iter) => commit_ref_iter.tree_id(),
8585
Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()),
8686
}
8787
}
88+
89+
/// Get a commit’s `commit_time` by either getting it from a [`gix_commitgraph::Graph`], if
90+
/// present, or a [`gix_object::CommitRefIter`] otherwise.
91+
pub fn commit_time(self) -> Result<gix_date::SecondsSinceUnixEpoch, gix_object::decode::Error> {
92+
match self {
93+
Self::CommitRefIter(commit_ref_iter) => commit_ref_iter.committer().map(|c| c.seconds()),
94+
Self::CachedCommit(commit) => Ok(commit.committer_timestamp() as gix_date::SecondsSinceUnixEpoch),
95+
}
96+
}
8897
}
8998

9099
/// Find information about a commit by either getting it from a [`gix_commitgraph::Graph`], if

0 commit comments

Comments
 (0)