Showing the changes to git-commitgraph/src/graph (2 of 3 files). Show all
Unified · Split
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | //! Operations on a complete commit graph. |
| 2 | 2 | mod access; |
| 3 | 3 | mod init; |
| 4 | +/// | |
| 4 | 5 | pub mod verify; |
| 5 | 6 | |
| 6 | 7 | use crate::file::File; |
| @@ -15,6 +16,7 @@ pub struct Graph { · 8 unmodified lines | ||
| 15 | 16 | files: Vec<File>, |
| 16 | 17 | } |
| 17 | 18 | |
| 19 | +/// A generalized position for use in [`Graph`]. | |
| 18 | 20 | #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] |
| 19 | 21 | pub struct Position(pub u32); |
| 20 | 22 | |
| @@ -50,15 +50,24 @@ pub enum Error<E: std::error::Error + 'static> { · 49 unmodified lines | ||
| 50 | 50 | TooManyFiles(usize), |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | +/// Statistics gathered while verifying the integrity of the graph as returned by [`Graph::verify_integrity()]`. | |
| 53 | 54 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 54 | 55 | #[cfg_attr(feature = "serde1", derive(serde::Deserialize, serde::Serialize))] |
| 55 | 56 | pub struct Outcome { |
| 57 | + /// The longest consecutive amount of commits in a chain of commits. | |
| 58 | + /// | |
| 59 | + /// For example, a repository with 10 commits would have 10 as value. | |
| 56 | 60 | pub longest_path_length: Option<u32>, |
| 61 | + /// The total amount traversed commits. | |
| 57 | 62 | pub num_commits: u32, |
| 63 | + /// A mapping of `parent-count -> amount of [commits][file::Commit] with that count`. | |
| 58 | 64 | pub parent_counts: BTreeMap<u32, u32>, |
| 59 | 65 | } |
| 60 | 66 | |
| 61 | 67 | impl Graph { |
| 68 | + /// Traverse all commits in the graph and call `processor(&commit) -> Result<(), E>` on it while verifying checksums. | |
| 69 | + /// | |
| 70 | + /// When `processor` returns an error, the entire verification is stopped and the error returned. | |
| 62 | 71 | pub fn verify_integrity<E>( |
| 63 | 72 | &self, |
| 64 | 73 | mut processor: impl FnMut(&file::Commit<'_>) -> Result<(), E>, |