Patchwork D11416: rust: Rename get_node methods to data_for_node, get_rev to data_for_rev

login
register
mail settings
Submitter phabricator
Date Sept. 14, 2021, 4:46 p.m.
Message ID <differential-rev-PHID-DREV-arygrbtqg7pcbyykwaz2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49720/
State Superseded
Headers show

Comments

phabricator - Sept. 14, 2021, 4:46 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  These are respective methods of Changelog, Manifestlog, and Filelog;
  three Rust structs that that wrap a Revlog struct.
  
  This rename clarifies that node IDs or revision numbers are parameters,
  not return values.
  
  Also reword doc-comments in Manifestlog and Filelog to separate node IDs
  and revision numbers that are local to a given (non-changelog) revlog
  from those of a changeset.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/operations/cat.rs
  rust/hg-core/src/repo.rs
  rust/hg-core/src/revlog/changelog.rs
  rust/hg-core/src/revlog/filelog.rs
  rust/hg-core/src/revlog/manifest.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
@@ -270,7 +270,7 @@ 
         .find_file(hg_path)?
         .expect("ambgious file not in p1");
     let filelog = repo.filelog(hg_path)?;
-    let filelog_entry = filelog.get_node(file_node).map_err(|_| {
+    let filelog_entry = filelog.data_for_node(file_node).map_err(|_| {
         HgError::corrupted("filelog missing node from manifest")
     })?;
     let contents_in_p1 = filelog_entry.data()?;
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
@@ -119,12 +119,14 @@ 
         self.index.is_empty()
     }
 
-    /// Returns the node ID for the given revision number, if it exists in this revlog
+    /// Returns the node ID for the given revision number, if it exists in this
+    /// revlog
     pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> {
         Some(self.index.get_entry(rev)?.hash())
     }
 
-    /// Return the revision number for the given node ID, if it exists in this revlog
+    /// Return the revision number for the given node ID, if it exists in this
+    /// revlog
     #[timed]
     pub fn rev_from_node(
         &self,
diff --git a/rust/hg-core/src/revlog/manifest.rs b/rust/hg-core/src/revlog/manifest.rs
--- a/rust/hg-core/src/revlog/manifest.rs
+++ b/rust/hg-core/src/revlog/manifest.rs
@@ -18,14 +18,31 @@ 
         Ok(Self { revlog })
     }
 
-    /// Return the `ManifestEntry` of a given node id.
-    pub fn get_node(&self, node: NodePrefix) -> Result<Manifest, RevlogError> {
+    /// Return the `Manifest` for the given node ID.
+    ///
+    /// Note: this is a node ID in the manifestlog, typically found through
+    /// `ChangelogEntry::manifest_node`. It is *not* the node ID of any
+    /// changeset.
+    ///
+    /// See also `Repo::manifest_for_node`
+    pub fn data_for_node(
+        &self,
+        node: NodePrefix,
+    ) -> Result<Manifest, RevlogError> {
         let rev = self.revlog.rev_from_node(node)?;
-        self.get_rev(rev)
+        self.data_for_rev(rev)
     }
 
-    /// Return the `ManifestEntry` of a given node revision.
-    pub fn get_rev(&self, rev: Revision) -> Result<Manifest, RevlogError> {
+    /// Return the `Manifest` of a given revision number.
+    ///
+    /// Note: this is a revision number in the manifestlog, *not* of any
+    /// changeset.
+    ///
+    /// See also `Repo::manifest_for_rev`
+    pub fn data_for_rev(
+        &self,
+        rev: Revision,
+    ) -> Result<Manifest, RevlogError> {
         let bytes = self.revlog.get_rev_data(rev)?;
         Ok(Manifest { bytes })
     }
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
@@ -26,17 +26,17 @@ 
 
     /// The given node ID is that of the file as found in a manifest, not of a
     /// changeset.
-    pub fn get_node(
+    pub fn data_for_node(
         &self,
         file_node: impl Into<NodePrefix>,
     ) -> Result<FilelogEntry, RevlogError> {
         let file_rev = self.revlog.rev_from_node(file_node.into())?;
-        self.get_rev(file_rev)
+        self.data_for_rev(file_rev)
     }
 
     /// The given revision is that of the file as found in a manifest, not of a
     /// changeset.
-    pub fn get_rev(
+    pub fn data_for_rev(
         &self,
         file_rev: Revision,
     ) -> Result<FilelogEntry, RevlogError> {
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
@@ -17,17 +17,17 @@ 
         Ok(Self { revlog })
     }
 
-    /// Return the `ChangelogEntry` a given node id.
-    pub fn get_node(
+    /// Return the `ChangelogEntry` for the given node ID.
+    pub fn data_for_node(
         &self,
         node: NodePrefix,
     ) -> Result<ChangelogEntry, RevlogError> {
         let rev = self.revlog.rev_from_node(node)?;
-        self.get_rev(rev)
+        self.data_for_rev(rev)
     }
 
-    /// Return the `ChangelogEntry` of a given node revision.
-    pub fn get_rev(
+    /// Return the `ChangelogEntry` of the given revision number.
+    pub fn data_for_rev(
         &self,
         rev: Revision,
     ) -> Result<ChangelogEntry, RevlogError> {
diff --git a/rust/hg-core/src/repo.rs b/rust/hg-core/src/repo.rs
--- a/rust/hg-core/src/repo.rs
+++ b/rust/hg-core/src/repo.rs
@@ -336,26 +336,29 @@ 
         self.manifestlog.get_mut_or_init(self)
     }
 
-    /// Returns the manifest of the given node ID
+    /// Returns the manifest of the *changeset* with the given node ID
     pub fn manifest_for_node(
         &self,
         node: impl Into<NodePrefix>,
     ) -> Result<Manifest, RevlogError> {
-        self.manifestlog()?.get_node(
+        self.manifestlog()?.data_for_node(
             self.changelog()?
-                .get_node(node.into())?
+                .data_for_node(node.into())?
                 .manifest_node()?
                 .into(),
         )
     }
 
-    /// Returns the manifest of the given revision
+    /// Returns the manifest of the *changeset* with the given revision number
     pub fn manifest_for_rev(
         &self,
         revision: Revision,
     ) -> Result<Manifest, RevlogError> {
-        self.manifestlog()?.get_node(
-            self.changelog()?.get_rev(revision)?.manifest_node()?.into(),
+        self.manifestlog()?.data_for_node(
+            self.changelog()?
+                .data_for_rev(revision)?
+                .manifest_node()?
+                .into(),
         )
     }
 
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
@@ -50,7 +50,7 @@ 
                 found_any = true;
                 let file_log = repo.filelog(manifest_file)?;
                 let file_node = Node::from_hex_for_repo(node_bytes)?;
-                let entry = file_log.get_node(file_node)?;
+                let entry = file_log.data_for_node(file_node)?;
                 bytes.extend(entry.data()?)
             }
         }