Showing the changes to git-commitgraph/src/file/commit.rs (1 of 6 files). Show all
Unified · Split
| @@ -11,7 +11,9 @@ use std::{ · 10 unmodified lines | |||
| 11 | slice::Chunks, | 11 | slice::Chunks, |
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | /// The error used in the [`file::commit`][self] module. | ||
| 14 | #[derive(thiserror::Error, Debug)] | 15 | #[derive(thiserror::Error, Debug)] |
| 16 | #[allow(missing_docs)] | ||
| 15 | pub enum Error { | 17 | pub enum Error { |
| 16 | #[error("commit {0}'s extra edges overflows the commit-graph file's extra edges list")] | 18 | #[error("commit {0}'s extra edges overflows the commit-graph file's extra edges list")] |
| 17 | ExtraEdgesListOverflow(owned::Id), | 19 | ExtraEdgesListOverflow(owned::Id), |
| @@ -28,6 +30,7 @@ pub enum Error { · 10 unmodified lines | |||
| 28 | const NO_PARENT: u32 = 0x7000_0000; | 30 | const NO_PARENT: u32 = 0x7000_0000; |
| 29 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; | 31 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; |
| 30 | 32 | ||
| 33 | /// A commit as stored in a [`File`]. | ||
| 31 | pub struct Commit<'a> { | 34 | pub struct Commit<'a> { |
| 32 | file: &'a File, | 35 | file: &'a File, |
| 33 | pos: file::Position, | 36 | pos: file::Position, |
| @@ -68,6 +71,7 @@ impl<'a> Commit<'a> { · 34 unmodified lines | |||
| 68 | self.generation | 71 | self.generation |
| 69 | } | 72 | } |
| 70 | 73 | ||
| 74 | /// Returns an iterator over the parent positions for lookup in the owning [Graph][crate::Graph]. | ||
| 71 | pub fn iter_parents(&'a self) -> impl Iterator<Item = Result<graph::Position, Error>> + 'a { | 75 | pub fn iter_parents(&'a self) -> impl Iterator<Item = Result<graph::Position, Error>> + 'a { |
| 72 | // I didn't find a combinator approach that a) was as strict as ParentIterator, b) supported | 76 | // I didn't find a combinator approach that a) was as strict as ParentIterator, b) supported |
| 73 | // fuse-after-first-error behavior, and b) was significantly shorter or more understandable | 77 | // fuse-after-first-error behavior, and b) was significantly shorter or more understandable |
| @@ -78,29 +82,23 @@ impl<'a> Commit<'a> { · 4 unmodified lines | |||
| 78 | } | 82 | } |
| 79 | } | 83 | } |
| 80 | 84 | ||
| 81 | // Allow the return value to outlive this Commit object, as it only needs to be bound by the | 85 | /// Returns the hash of this commit. |
| 82 | // lifetime of the parent file. | 86 | pub fn id(&self) -> borrowed::Id<'a> { |
| 83 | pub fn id<'b>(&'b self) -> borrowed::Id<'a> | ||
| 84 | where | ||
| 85 | 'a: 'b, | ||
| 86 | { | ||
| 87 | self.file.id_at(self.pos) | 87 | self.file.id_at(self.pos) |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | /// Returns the first parent of this commit. | ||
| 90 | pub fn parent1(&self) -> Result<Option<graph::Position>, Error> { | 91 | pub fn parent1(&self) -> Result<Option<graph::Position>, Error> { |
| 91 | self.iter_parents().next().transpose() | 92 | self.iter_parents().next().transpose() |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 95 | /// Returns the position at which this commit is stored in the parent [File]. | ||
| 94 | pub fn position(&self) -> file::Position { | 96 | pub fn position(&self) -> file::Position { |
| 95 | self.pos | 97 | self.pos |
| 96 | } | 98 | } |
| 97 | 99 | ||
| 98 | // Allow the return value to outlive this Commit object, as it only needs to be bound by the | 100 | /// Return the hash of the tree this commit points to. |
| 99 | // lifetime of the parent file. | 101 | pub fn root_tree_id(&self) -> borrowed::Id<'a> { |
| 100 | pub fn root_tree_id<'b>(&'b self) -> borrowed::Id<'a> | ||
| 101 | where | ||
| 102 | 'a: 'b, | ||
| 103 | { | ||
| 104 | self.root_tree_id | 102 | self.root_tree_id |
| 105 | } | 103 | } |
| 106 | } | 104 | } |
| @@ -128,6 +126,7 @@ impl<'a> PartialEq for Commit<'a> { · 21 unmodified lines | |||
| 128 | } | 126 | } |
| 129 | } | 127 | } |
| 130 | 128 | ||
| 129 | /// An iterator over parents of a [`Commit`]. | ||
| 131 | pub struct ParentIterator<'a> { | 130 | pub struct ParentIterator<'a> { |
| 132 | commit_data: &'a Commit<'a>, | 131 | commit_data: &'a Commit<'a>, |
| 133 | state: ParentIteratorState<'a>, | 132 | state: ParentIteratorState<'a>, |