[Updated] D11959: rhg: Rename some revlog-related types and methods

SimonSapin phabricator at mercurial-scm.org
Fri Jan 7 09:53:53 UTC 2022


Closed by commit rHG20d0d896183e: rhg: Rename some revlog-related types and methods (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11959?vs=31599&id=31611

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11959/new/

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

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()?,
         ));
     }
 



To: SimonSapin, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220107/e85bb796/attachment-0002.html>


More information about the Mercurial-patches mailing list