gix_traverse/commit/
mod.rs1use gix_hash::ObjectId;
5use gix_object::FindExt;
6use gix_revwalk::{PriorityQueue, graph::IdMap};
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 generation: Option<gix_revwalk::graph::Generation>,
66 pub commit_time: Option<gix_date::SecondsSinceUnixEpoch>,
69}
70
71#[derive(Clone, Copy)]
74pub enum Either<'buf, 'cache> {
75 CommitRefIter(gix_object::CommitRefIter<'buf>),
77 CachedCommit(gix_commitgraph::file::Commit<'cache>),
79}
80
81impl Either<'_, '_> {
82 pub fn tree_id(self) -> Result<ObjectId, gix_object::decode::Error> {
85 match self {
86 Self::CommitRefIter(mut commit_ref_iter) => commit_ref_iter.tree_id(),
87 Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()),
88 }
89 }
90
91 pub fn commit_time(self) -> Result<gix_date::SecondsSinceUnixEpoch, gix_object::decode::Error> {
94 match self {
95 Self::CommitRefIter(commit_ref_iter) => commit_ref_iter.committer().map(|c| c.seconds()),
96 Self::CachedCommit(commit) => Ok(commit.committer_timestamp() as gix_date::SecondsSinceUnixEpoch),
97 }
98 }
99}
100
101pub fn find<'cache, 'buf, Find>(
104 cache: Option<&'cache gix_commitgraph::Graph>,
105 objects: Find,
106 id: &gix_hash::oid,
107 buf: &'buf mut Vec<u8>,
108) -> Result<Either<'buf, 'cache>, gix_object::find::existing_iter::Error>
109where
110 Find: gix_object::Find,
111{
112 match cache.and_then(|cache| cache.commit_by_id(id).map(Either::CachedCommit)) {
113 Some(c) => Ok(c),
114 None => objects.find_commit_iter(id, buf).map(Either::CommitRefIter),
115 }
116}