gix_traverse/commit/
mod.rs1use gix_hash::ObjectId;
5use gix_object::FindExt;
6use gix_revwalk::graph::IdMap;
7use gix_revwalk::PriorityQueue;
8use smallvec::SmallVec;
9
10pub struct Simple<Find, Predicate> {
12 objects: Find,
13 cache: Option<gix_commitgraph::Graph>,
14 predicate: Predicate,
15 state: simple::State,
16 parents: Parents,
17 sorting: simple::Sorting,
18}
19
20pub mod simple;
22
23pub struct Topo<Find, Predicate> {
28 commit_graph: Option<gix_commitgraph::Graph>,
29 find: Find,
30 predicate: Predicate,
31 indegrees: IdMap<i32>,
32 states: IdMap<topo::WalkFlags>,
33 explore_queue: PriorityQueue<topo::iter::GenAndCommitTime, ObjectId>,
34 indegree_queue: PriorityQueue<topo::iter::GenAndCommitTime, ObjectId>,
35 topo_queue: topo::iter::Queue,
36 parents: Parents,
37 min_gen: u32,
38 buf: Vec<u8>,
39}
40
41pub mod topo;
42
43#[derive(Default, Copy, Clone)]
45pub enum Parents {
46 #[default]
48 All,
49 First,
51}
52
53pub type ParentIds = SmallVec<[gix_hash::ObjectId; 1]>;
57
58#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
60pub struct Info {
61 pub id: gix_hash::ObjectId,
63 pub parent_ids: ParentIds,
65 pub commit_time: Option<gix_date::SecondsSinceUnixEpoch>,
68}
69
70#[derive(Clone, Copy)]
73pub enum Either<'buf, 'cache> {
74 CommitRefIter(gix_object::CommitRefIter<'buf>),
76 CachedCommit(gix_commitgraph::file::Commit<'cache>),
78}
79
80impl Either<'_, '_> {
81 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
91pub fn find<'cache, 'buf, Find>(
94 cache: Option<&'cache gix_commitgraph::Graph>,
95 objects: Find,
96 id: &gix_hash::oid,
97 buf: &'buf mut Vec<u8>,
98) -> Result<Either<'buf, 'cache>, gix_object::find::existing_iter::Error>
99where
100 Find: gix_object::Find,
101{
102 match cache.and_then(|cache| cache.commit_by_id(id).map(Either::CachedCommit)) {
103 Some(c) => Ok(c),
104 None => objects.find_commit_iter(id, buf).map(Either::CommitRefIter),
105 }
106}