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 | 11 | slice::Chunks, |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | +/// The error used in the [`file::commit`][self] module. | |
| 14 | 15 | #[derive(thiserror::Error, Debug)] |
| 16 | +#[allow(missing_docs)] | |
| 15 | 17 | pub enum Error { |
| 16 | 18 | #[error("commit {0}'s extra edges overflows the commit-graph file's extra edges list")] |
| 17 | 19 | ExtraEdgesListOverflow(owned::Id), |
| @@ -28,6 +30,7 @@ pub enum Error { · 10 unmodified lines | ||
| 28 | 30 | const NO_PARENT: u32 = 0x7000_0000; |
| 29 | 31 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; |
| 30 | 32 | |
| 33 | +/// A commit as stored in a [`File`]. | |
| 31 | 34 | pub struct Commit<'a> { |
| 32 | 35 | file: &'a File, |
| 33 | 36 | pos: file::Position, |
| @@ -68,6 +71,7 @@ impl<'a> Commit<'a> { · 34 unmodified lines | ||
| 68 | 71 | self.generation |
| 69 | 72 | } |
| 70 | 73 | |
| 74 | + /// Returns an iterator over the parent positions for lookup in the owning [Graph][crate::Graph]. | |
| 71 | 75 | pub fn iter_parents(&'a self) -> impl Iterator<Item = Result<graph::Position, Error>> + 'a { |
| 72 | 76 | // I didn't find a combinator approach that a) was as strict as ParentIterator, b) supported |
| 73 | 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 | |
| 82 | − // lifetime of the parent file. | |
| 83 | − pub fn id<'b>(&'b self) -> borrowed::Id<'a> | |
| 84 | − where | |
| 85 | − 'a: 'b, | |
| 86 | − { | |
| 85 | + /// Returns the hash of this commit. | |
| 86 | + pub fn id(&self) -> borrowed::Id<'a> { | |
| 87 | 87 | self.file.id_at(self.pos) |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | + /// Returns the first parent of this commit. | |
| 90 | 91 | pub fn parent1(&self) -> Result<Option<graph::Position>, Error> { |
| 91 | 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 | 96 | pub fn position(&self) -> file::Position { |
| 95 | 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 | |
| 99 | − // lifetime of the parent file. | |
| 100 | − pub fn root_tree_id<'b>(&'b self) -> borrowed::Id<'a> | |
| 101 | − where | |
| 102 | − 'a: 'b, | |
| 103 | − { | |
| 100 | + /// Return the hash of the tree this commit points to. | |
| 101 | + pub fn root_tree_id(&self) -> borrowed::Id<'a> { | |
| 104 | 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 | 130 | pub struct ParentIterator<'a> { |
| 132 | 131 | commit_data: &'a Commit<'a>, |
| 133 | 132 | state: ParentIteratorState<'a>, |