History

feat: `CommitRefIter::parent_ids()` (#364)

Allocation-free parent retrieval.

Sebastian Thiel committed 4 years ago

Commit 91065cd1 parent 9c8e4493 files · +34 −3Browse files

Showing the changes to git-object/src/commit (1 of 3 files). Show all

Unified · Split

git-object/src/commit/ref_iter.rs+12−1
@@ -17,6 +17,7 @@ pub(crate) enum SignatureKind { · 16 unmodified lines
17 Committer,17 Committer,
18}18}
19 19
20#[derive(Copy, Clone)]
20pub(crate) enum State {21pub(crate) enum State {
21 Tree,22 Tree,
22 Parents,23 Parents,
@@ -52,12 +53,22 @@ impl<'a> CommitRefIter<'a> { · 29 unmodified lines
52 self.next().and_then(Result::ok).and_then(Token::try_into_id)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 /// Returns all signatures, first the author, then the committer, if there is no decoding error.66 /// Returns all signatures, first the author, then the committer, if there is no decoding error.
56 ///67 ///
57 /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not68 /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not
58 /// if not exactly two signatures were iterable.69 /// if not exactly two signatures were iterable.
59 /// Errors are not the common case - if an error needs to be detectable, use this instance as iterator.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 self.filter_map(|t| match t {72 self.filter_map(|t| match t {
62 Ok(Token::Author { signature }) | Ok(Token::Committer { signature }) => Some(signature),73 Ok(Token::Author { signature }) | Ok(Token::Committer { signature }) => Some(signature),
63 _ => None,74 _ => None,