History

[ref] flexible and simple support for different hash lengths

Now we can (eventually) parse more hashes as differntiated by their length.

Sebastian Thiel committed 5 years ago

Commit 9c2edd51 parent 21f187e4 files · +34 −5Browse files

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

Unified · Split

git-object/src/immutable/parse.rs+7−2
@@ -65,8 +65,13 @@ fn is_hex_digit_lc(b: u8) -> bool { · 64 unmodified lines
6565 matches!(b, b'0'..=b'9' | b'a'..=b'f')
6666 }
6767
68−pub(crate) 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()))
68+pub fn hex_sha1<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> {
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()))
7075 }
7176
7277 pub(crate) fn signature<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t