gix_traverse/commit/topo/mod.rs
1//! Topological commit traversal, similar to `git log --topo-order`, which keeps track of graph state.
2
3use bitflags::bitflags;
4
5/// The errors that can occur during creation and iteration.
6#[derive(thiserror::Error, Debug)]
7#[allow(missing_docs)]
8pub enum Error {
9 #[error("Indegree information is missing")]
10 MissingIndegreeUnexpected,
11 #[error("Internal state (bitflags) not found")]
12 MissingStateUnexpected,
13 #[error(transparent)]
14 ObjectDecode(#[from] gix_object::decode::Error),
15 #[error(transparent)]
16 Find(#[from] gix_object::find::existing_iter::Error),
17}
18
19bitflags! {
20 /// Set of flags to describe the state of a particular commit while iterating.
21 // NOTE: The names correspond to the names of the flags in revision.h
22 #[repr(transparent)]
23 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24 pub(super) struct WalkFlags: u8 {
25 /// Commit has been seen
26 const Seen = 0b000001;
27 /// Commit has been processed by the Explore walk
28 const Explored = 0b000010;
29 /// Commit has been processed by the Indegree walk
30 const InDegree = 0b000100;
31 /// Commit is deemed uninteresting for whatever reason
32 const Uninteresting = 0b001000;
33 /// Commit marks the end of a walk, like `foo` in `git rev-list foo..bar`
34 const Bottom = 0b010000;
35 /// Parents have been processed
36 const Added = 0b100000;
37 }
38}
39
40/// Sorting to use for the topological walk.
41///
42/// ### Sample History
43///
44/// The following history will be referred to for explaining how the sort order works, with the number denoting the commit timestamp
45/// (*their X-alignment doesn't matter*).
46///
47/// ```text
48/// ---1----2----4----7 <- second parent of 8
49/// \ \
50/// 3----5----6----8---
51/// ```
52#[derive(Clone, Copy, Debug, Default)]
53pub enum Sorting {
54 /// Show no parents before all of its children are shown, but otherwise show
55 /// commits in the commit timestamp order.
56 ///
57 /// This is equivalent to `git rev-list --date-order`.
58 #[default]
59 DateOrder,
60 /// Show no parents before all of its children are shown, and avoid
61 /// showing commits on multiple lines of history intermixed.
62 ///
63 /// In the *sample history* the order would be `8, 6, 5, 3, 7, 4, 2, 1`.
64 /// This is equivalent to `git rev-list --topo-order`.
65 TopoOrder,
66}
67
68mod init;
69pub use init::Builder;
70
71pub(super) mod iter;