gix_traverse/commit/
mod.rs1use gix_hash::ObjectId;
5use gix_object::FindExt;
6use gix_revwalk::{graph::IdMap, PriorityQueue};
7use smallvec::SmallVec;
8
9pub struct Simple<Find, Predicate> {
11 objects: Find,
12 cache: Option<gix_commitgraph::Graph>,
13 predicate: Predicate,
14 state: simple::State,
15 parents: Parents,
16 sorting: simple::Sorting,
17}
18
19pub mod simple;
21
22pub struct Topo<Find, Predicate> {
27 commit_graph: Option<gix_commitgraph::Graph>,
28 find: Find,
29 predicate: Predicate,
30 indegrees: IdMap<i32>,
31 states: IdMap<topo::WalkFlags>,
32 explore_queue: PriorityQueue<topo::iter::GenAndCommitTime, ObjectId>,
33 indegree_queue: PriorityQueue<topo::iter::GenAndCommitTime, ObjectId>,
34 topo_queue: topo::iter::Queue,
35 parents: Parents,
36 min_gen: u32,
37 buf: Vec<u8>,
38}
39
40pub mod topo;
41
42#[derive(Default, Copy, Clone)]
44pub enum Parents {
45 #[default]
47 All,
48 First,
50}
51
52pub type ParentIds = SmallVec<[gix_hash::ObjectId; 1]>;
56
57#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
59pub struct Info {
60 pub id: gix_hash::ObjectId,
62 pub parent_ids: ParentIds,
64 pub commit_time: Option<gix_date::SecondsSinceUnixEpoch>,
67}
68
69#[derive(Clone, Copy)]
72pub enum Either<'buf, 'cache> {
73 CommitRefIter(gix_object::CommitRefIter<'buf>),
75 CachedCommit(gix_commitgraph::file::Commit<'cache>),
77}
78
79impl Either<'_, '_> {
80 pub fn tree_id(self) -> Result<ObjectId, gix_object::decode::Error> {
83 match self {
84 Self::CommitRefIter(mut commit_ref_iter) => commit_ref_iter.tree_id(),
85 Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()),
86 }
87 }
88
89 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 }
97}
98
99pub fn find<'cache, 'buf, Find>(
102 cache: Option<&'cache gix_commitgraph::Graph>,
103 objects: Find,
104 id: &gix_hash::oid,
105 buf: &'buf mut Vec<u8>,
106) -> Result<Either<'buf, 'cache>, gix_object::find::existing_iter::Error>
107where
108 Find: gix_object::Find,
109{
110 match cache.and_then(|cache| cache.commit_by_id(id).map(Either::CachedCommit)) {
111 Some(c) => Ok(c),
112 None => objects.find_commit_iter(id, buf).map(Either::CommitRefIter),
113 }
114}