Showing the changes to git-object/src/commit (1 of 12 files). Show all
Unified · Split
| @@ -49,8 +49,9 @@ impl<'a> CommitRefIter<'a> { · 48 unmodified lines | ||
| 49 | 49 | /// Errors are coerced into options, hiding whether there was an error or not. The caller should assume an error if they |
| 50 | 50 | /// call the method as intended. Such a squelched error cannot be recovered unless the objects data is retrieved and parsed again. |
| 51 | 51 | /// `next()`. |
| 52 | − pub fn tree_id(&mut self) -> Option<ObjectId> { | |
| 53 | − self.next().and_then(Result::ok).and_then(Token::try_into_id) | |
| 52 | + pub fn tree_id(&mut self) -> Result<ObjectId, crate::decode::Error> { | |
| 53 | + let tree_id = self.next().ok_or_else(missing_field)??; | |
| 54 | + Token::try_into_id(tree_id).ok_or_else(missing_field) | |
| 54 | 55 | } |
| 55 | 56 | |
| 56 | 57 | /// Return all parent_ids as iterator. |
| @@ -77,32 +78,43 @@ impl<'a> CommitRefIter<'a> { · 20 unmodified lines | ||
| 77 | 78 | |
| 78 | 79 | /// Returns the committer signature if there is no decoding error. |
| 79 | 80 | /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not. |
| 80 | − pub fn committer(mut self) -> Option<git_actor::SignatureRef<'a>> { | |
| 81 | + pub fn committer(mut self) -> Result<git_actor::SignatureRef<'a>, crate::decode::Error> { | |
| 81 | 82 | self.find_map(|t| match t { |
| 82 | − Ok(Token::Committer { signature }) => Some(signature), | |
| 83 | + Ok(Token::Committer { signature }) => Some(Ok(signature)), | |
| 84 | + Err(err) => Some(Err(err)), | |
| 83 | 85 | _ => None, |
| 84 | 86 | }) |
| 87 | + .ok_or_else(missing_field)? | |
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | /// Returns the author signature if there is no decoding error. |
| 88 | 91 | /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not. |
| 89 | − pub fn author(mut self) -> Option<git_actor::SignatureRef<'a>> { | |
| 92 | + pub fn author(mut self) -> Result<git_actor::SignatureRef<'a>, crate::decode::Error> { | |
| 90 | 93 | self.find_map(|t| match t { |
| 91 | − Ok(Token::Author { signature }) => Some(signature), | |
| 94 | + Ok(Token::Author { signature }) => Some(Ok(signature)), | |
| 95 | + Err(err) => Some(Err(err)), | |
| 92 | 96 | _ => None, |
| 93 | 97 | }) |
| 98 | + .ok_or_else(missing_field)? | |
| 94 | 99 | } |
| 95 | 100 | |
| 96 | 101 | /// Returns the message if there is no decoding error. |
| 97 | 102 | /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not. |
| 98 | − pub fn message(mut self) -> Option<&'a BStr> { | |
| 103 | + pub fn message(mut self) -> Result<&'a BStr, crate::decode::Error> { | |
| 99 | 104 | self.find_map(|t| match t { |
| 100 | − Ok(Token::Message(msg)) => Some(msg), | |
| 105 | + Ok(Token::Message(msg)) => Some(Ok(msg)), | |
| 106 | + Err(err) => Some(Err(err)), | |
| 101 | 107 | _ => None, |
| 102 | 108 | }) |
| 109 | + .transpose() | |
| 110 | + .map(|msg| msg.unwrap_or_default()) | |
| 103 | 111 | } |
| 104 | 112 | } |
| 105 | 113 | |
| 114 | +fn missing_field() -> crate::decode::Error { | |
| 115 | + crate::decode::empty_error() | |
| 116 | +} | |
| 117 | + | |
| 106 | 118 | impl<'a> CommitRefIter<'a> { |
| 107 | 119 | fn next_inner(i: &'a [u8], state: &mut State) -> Result<(&'a [u8], Token<'a>), crate::decode::Error> { |
| 108 | 120 | use State::*; |