Skip to content

Commit ded2e53

Browse files
committed
feat: add graph::LazyCommit::generation_and_timestamp()
That way, the cost for creating intermediate commit objects are cut in half.
1 parent 8cea69a commit ded2e53

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

gix-revwalk/src/graph/commit.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
3333
}
3434
}
3535

36+
/// Returns the generation of the commit and its commit-time, either from cache if available, or parsed from the object buffer.
37+
pub fn generation_and_timestamp(
38+
&self,
39+
) -> Result<(Option<Generation>, SecondsSinceUnixEpoch), gix_object::decode::Error> {
40+
Ok(match &self.backing {
41+
Either::Left(buf) => (
42+
None,
43+
gix_object::CommitRefIter::from_bytes(buf).committer()?.time.seconds,
44+
),
45+
Either::Right((cache, pos)) => {
46+
let commit = cache.commit_at(*pos);
47+
(
48+
commit.generation().into(),
49+
// a cast as we cannot represent the error and trying seems overkill
50+
cache.commit_at(*pos).committer_timestamp() as SecondsSinceUnixEpoch,
51+
)
52+
}
53+
})
54+
}
55+
3656
/// Convert ourselves into an owned version, which effectively detaches us from the underlying graph.
3757
/// Use `new_data()` to provide the `data` field for the owned `Commit`.
3858
pub fn to_owned<T>(&self, new_data: impl FnOnce() -> T) -> Result<Commit<T>, to_owned::Error> {

0 commit comments

Comments
 (0)