Now we can (eventually) parse more hashes as differntiated by their length.
Showing the changes to git-object/src/immutable (1 of 4 files). Show all
Unified · Split
| @@ -65,8 +65,13 @@ fn is_hex_digit_lc(b: u8) -> bool { · 64 unmodified lines | |||
| 65 | matches!(b, b'0'..=b'9' | b'a'..=b'f') | 65 | matches!(b, b'0'..=b'9' | b'a'..=b'f') |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | pub(crate) fn hex_sha1<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> { | 68 | pub fn hex_sha1<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> { |
| 69 | take_while_m_n(40usize, 40, is_hex_digit_lc)(i).map(|(i, o)| (i, o.as_bstr())) | 69 | take_while_m_n( |
| 70 | git_hash::Kind::shortest().len_in_hex(), | ||
| 71 | git_hash::Kind::longest().len_in_hex(), | ||
| 72 | is_hex_digit_lc, | ||
| 73 | )(i) | ||
| 74 | .map(|(i, hex)| (i, hex.as_bstr())) | ||
| 70 | } | 75 | } |
| 71 | 76 | ||
| 72 | pub(crate) fn signature<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( | 77 | pub(crate) fn signature<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( |