Patchwork D11959: rhg: Rename some revlog-related types and methods

login
register
mail settings
Submitter phabricator
Date Jan. 6, 2022, 6:57 p.m.
Message ID <differential-rev-PHID-DREV-sm23ilqo7oonczwkeuij-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50287/
State New
Headers show

Comments

phabricator - Jan. 6, 2022, 6:57 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11959

AFFECTED 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

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -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.
diff --git a/rust/hg-core/src/revlog/revlog.rs b/rust/hg-core/src/revlog/revlog.rs
--- a/rust/hg-core/src/revlog/revlog.rs
+++ b/rust/hg-core/src/revlog/revlog.rs
@@ -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(&[]));
         }
diff --git a/rust/hg-core/src/revlog/filelog.rs b/rust/hg-core/src/revlog/filelog.rs
--- a/rust/hg-core/src/revlog/filelog.rs
+++ b/rust/hg-core/src/revlog/filelog.rs
@@ -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 {
diff --git a/rust/hg-core/src/revlog/changelog.rs b/rust/hg-core/src/revlog/changelog.rs
--- a/rust/hg-core/src/revlog/changelog.rs
+++ b/rust/hg-core/src/revlog/changelog.rs
@@ -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
diff --git a/rust/hg-core/src/operations/cat.rs b/rust/hg-core/src/operations/cat.rs
--- a/rust/hg-core/src/operations/cat.rs
+++ b/rust/hg-core/src/operations/cat.rs
@@ -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()?,
         ));
     }