Mercurial > hg
changeset 48540:20d0d896183e
rhg: Rename some revlog-related types and methods
Use "data chunck" and "data" for a revlog entry’s data before and after
resolving deltas (if any), repsectively.
The former `FilelogEntry` actually only contains data, rename it to
`FilelogRevisionData` accordingly. This leaves room to later have a
`FilelogEntry` type that wraps `RevlogEntry`.
Differential Revision: https://phab.mercurial-scm.org/D11959
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 21 Dec 2021 15:57:30 +0100 |
parents | b9d5ad7146a3 |
children | f2f57724d4eb |
files | rust/hg-core/src/operations/cat.rs rust/hg-core/src/revlog/changelog.rs rust/hg-core/src/revlog/filelog.rs rust/hg-core/src/revlog/revlog.rs rust/rhg/src/commands/status.rs |
diffstat | 5 files changed, 20 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/operations/cat.rs Wed Jan 05 13:36:05 2022 -0500 +++ b/rust/hg-core/src/operations/cat.rs Tue Dec 21 15:57:30 2021 +0100 @@ -101,7 +101,7 @@ let file_log = repo.filelog(file_path)?; results.push(( file_path, - file_log.data_for_node(file_node)?.into_data()?, + file_log.data_for_node(file_node)?.into_file_data()?, )); }
--- a/rust/hg-core/src/revlog/changelog.rs Wed Jan 05 13:36:05 2022 -0500 +++ b/rust/hg-core/src/revlog/changelog.rs Tue Dec 21 15:57:30 2021 +0100 @@ -22,7 +22,7 @@ pub fn data_for_node( &self, node: NodePrefix, - ) -> Result<ChangelogEntry, RevlogError> { + ) -> Result<ChangelogRevisionData, RevlogError> { let rev = self.revlog.rev_from_node(node)?; self.data_for_rev(rev) } @@ -31,9 +31,9 @@ pub fn data_for_rev( &self, rev: Revision, - ) -> Result<ChangelogEntry, RevlogError> { + ) -> Result<ChangelogRevisionData, RevlogError> { let bytes = self.revlog.get_rev_data(rev)?; - Ok(ChangelogEntry { bytes }) + Ok(ChangelogRevisionData { bytes }) } pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> { @@ -43,12 +43,12 @@ /// `Changelog` entry which knows how to interpret the `changelog` data bytes. #[derive(Debug)] -pub struct ChangelogEntry { +pub struct ChangelogRevisionData { /// The data bytes of the `changelog` entry. bytes: Vec<u8>, } -impl ChangelogEntry { +impl ChangelogRevisionData { /// Return an iterator over the lines of the entry. pub fn lines(&self) -> impl Iterator<Item = &[u8]> { self.bytes
--- a/rust/hg-core/src/revlog/filelog.rs Wed Jan 05 13:36:05 2022 -0500 +++ b/rust/hg-core/src/revlog/filelog.rs Tue Dec 21 15:57:30 2021 +0100 @@ -28,7 +28,7 @@ pub fn data_for_node( &self, file_node: impl Into<NodePrefix>, - ) -> Result<FilelogEntry, RevlogError> { + ) -> Result<FilelogRevisionData, RevlogError> { let file_rev = self.revlog.rev_from_node(file_node.into())?; self.data_for_rev(file_rev) } @@ -38,9 +38,9 @@ pub fn data_for_rev( &self, file_rev: Revision, - ) -> Result<FilelogEntry, RevlogError> { + ) -> Result<FilelogRevisionData, RevlogError> { let data: Vec<u8> = self.revlog.get_rev_data(file_rev)?; - Ok(FilelogEntry(data.into())) + Ok(FilelogRevisionData(data.into())) } } @@ -50,9 +50,10 @@ get_path_from_bytes(&encoded_bytes).into() } -pub struct FilelogEntry(Vec<u8>); +/// The data for one revision in a filelog, uncompressed and delta-resolved. +pub struct FilelogRevisionData(Vec<u8>); -impl FilelogEntry { +impl FilelogRevisionData { /// Split into metadata and data pub fn split(&self) -> Result<(Option<&[u8]>, &[u8]), HgError> { const DELIMITER: &[u8; 2] = &[b'\x01', b'\n']; @@ -71,14 +72,14 @@ } /// Returns the file contents at this revision, stripped of any metadata - pub fn data(&self) -> Result<&[u8], HgError> { + pub fn file_data(&self) -> Result<&[u8], HgError> { let (_metadata, data) = self.split()?; Ok(data) } /// Consume the entry, and convert it into data, discarding any metadata, /// if present. - pub fn into_data(self) -> Result<Vec<u8>, HgError> { + pub fn into_file_data(self) -> Result<Vec<u8>, HgError> { if let (Some(_metadata), data) = self.split()? { Ok(data.to_owned()) } else {
--- a/rust/hg-core/src/revlog/revlog.rs Wed Jan 05 13:36:05 2022 -0500 +++ b/rust/hg-core/src/revlog/revlog.rs Tue Dec 21 15:57:30 2021 +0100 @@ -214,7 +214,7 @@ .ok_or(RevlogError::InvalidRevision)?; let data: Vec<u8> = if delta_chain.is_empty() { - entry.data()?.into() + entry.data_chunk()?.into() } else { Revlog::build_data_from_deltas(entry, &delta_chain)? }; @@ -260,11 +260,11 @@ snapshot: RevlogEntry, deltas: &[RevlogEntry], ) -> Result<Vec<u8>, RevlogError> { - let snapshot = snapshot.data()?; + let snapshot = snapshot.data_chunk()?; let deltas = deltas .iter() .rev() - .map(RevlogEntry::data) + .map(RevlogEntry::data_chunk) .collect::<Result<Vec<Cow<'_, [u8]>>, RevlogError>>()?; let patches: Vec<_> = deltas.iter().map(|d| patch::PatchList::new(d)).collect(); @@ -339,7 +339,8 @@ } /// Extract the data contained in the entry. - pub fn data(&self) -> Result<Cow<'_, [u8]>, RevlogError> { + /// This may be a delta. (See `is_delta`.) + fn data_chunk(&self) -> Result<Cow<'_, [u8]>, RevlogError> { if self.bytes.is_empty() { return Ok(Cow::Borrowed(&[])); }
--- a/rust/rhg/src/commands/status.rs Wed Jan 05 13:36:05 2022 -0500 +++ b/rust/rhg/src/commands/status.rs Tue Dec 21 15:57:30 2021 +0100 @@ -522,7 +522,7 @@ filelog.data_for_node(entry.node_id()?).map_err(|_| { HgError::corrupted("filelog missing node from manifest") })?; - let contents_in_p1 = filelog_entry.data()?; + let contents_in_p1 = filelog_entry.file_data()?; if contents_in_p1.len() as u64 != fs_len { // No need to read the file contents: // it cannot be equal if it has a different length.