Allocation-free parent retrieval.
Showing the changes to git-object/src/commit (1 of 3 files). Show all
Unified · Split
| @@ -17,6 +17,7 @@ pub(crate) enum SignatureKind { · 16 unmodified lines | ||
| 17 | 17 | Committer, |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | +#[derive(Copy, Clone)] | |
| 20 | 21 | pub(crate) enum State { |
| 21 | 22 | Tree, |
| 22 | 23 | Parents, |
| @@ -52,12 +53,22 @@ impl<'a> CommitRefIter<'a> { · 29 unmodified lines | ||
| 52 | 53 | self.next().and_then(Result::ok).and_then(Token::try_into_id) |
| 53 | 54 | } |
| 54 | 55 | |
| 56 | + /// Return all parent_ids as iterator. | |
| 57 | + /// | |
| 58 | + /// Parsing errors are ignored quietly. | |
| 59 | + pub fn parent_ids(self) -> impl Iterator<Item = git_hash::ObjectId> + 'a { | |
| 60 | + self.filter_map(|t| match t { | |
| 61 | + Ok(Token::Parent { id }) => Some(id), | |
| 62 | + _ => None, | |
| 63 | + }) | |
| 64 | + } | |
| 65 | + | |
| 55 | 66 | /// Returns all signatures, first the author, then the committer, if there is no decoding error. |
| 56 | 67 | /// |
| 57 | 68 | /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not |
| 58 | 69 | /// if not exactly two signatures were iterable. |
| 59 | 70 | /// Errors are not the common case - if an error needs to be detectable, use this instance as iterator. |
| 60 | − pub fn signatures(&'a mut self) -> impl Iterator<Item = git_actor::SignatureRef<'_>> + 'a { | |
| 71 | + pub fn signatures(self) -> impl Iterator<Item = git_actor::SignatureRef<'a>> + 'a { | |
| 61 | 72 | self.filter_map(|t| match t { |
| 62 | 73 | Ok(Token::Author { signature }) | Ok(Token::Committer { signature }) => Some(signature), |
| 63 | 74 | _ => None, |