Mercurial > hg-stable
changeset 48260:e9faae0f445c
rhg: simplify split_metadata
It turns out that it's possible to implement `FilelogEntry.into_data`
on top of `split`, as proposed by @spectral.
Differential Revision: https://phab.mercurial-scm.org/D11689
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Tue, 19 Oct 2021 10:52:13 +0100 |
parents | 7f23a472068f |
children | 1730b2fceaa1 |
files | rust/hg-core/src/revlog/filelog.rs |
diffstat | 1 files changed, 3 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/filelog.rs Fri Aug 27 14:40:09 2021 +0200 +++ b/rust/hg-core/src/revlog/filelog.rs Tue Oct 19 10:52:13 2021 +0100 @@ -54,28 +54,18 @@ impl FilelogEntry { /// Split into metadata and data - /// Returns None if there is no metadata, so the entire entry is data. - fn split_metadata(&self) -> Result<Option<(&[u8], &[u8])>, HgError> { + pub fn split(&self) -> Result<(Option<&[u8]>, &[u8]), HgError> { const DELIMITER: &[u8; 2] = &[b'\x01', b'\n']; if let Some(rest) = self.0.drop_prefix(DELIMITER) { if let Some((metadata, data)) = rest.split_2_by_slice(DELIMITER) { - Ok(Some((metadata, data))) + Ok((Some(metadata), data)) } else { Err(HgError::corrupted( "Missing metadata end delimiter in filelog entry", )) } } else { - Ok(None) - } - } - - /// Split into metadata and data - pub fn split(&self) -> Result<(Option<&[u8]>, &[u8]), HgError> { - if let Some((metadata, data)) = self.split_metadata()? { - Ok((Some(metadata), data)) - } else { Ok((None, &self.0)) } } @@ -89,7 +79,7 @@ /// Consume the entry, and convert it into data, discarding any metadata, /// if present. pub fn into_data(self) -> Result<Vec<u8>, HgError> { - if let Some((_metadata, data)) = self.split_metadata()? { + if let (Some(_metadata), data) = self.split()? { Ok(data.to_owned()) } else { Ok(self.0)