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
70enum Either<'buf, 'cache> {
71 CommitRefIter(gix_object::CommitRefIter<'buf>),
72 CachedCommit(gix_commitgraph::file::Commit<'cache>),
73}
74
75fn find<'cache, 'buf, Find>(
76 cache: Option<&'cache gix_commitgraph::Graph>,
77 objects: Find,
78 id: &gix_hash::oid,
79 buf: &'buf mut Vec<u8>,
80) -> Result<Either<'buf, 'cache>, gix_object::find::existing_iter::Error>
81where
82 Find: gix_object::Find,
83{
84 match cache.and_then(|cache| cache.commit_by_id(id).map(Either::CachedCommit)) {
85 Some(c) => Ok(c),
86 None => objects.find_commit_iter(id, buf).map(Either::CommitRefIter),
87 }
88}