Patchwork D9108: hg-core: use `.or(Err(Error))` not `.map_err(|_| Error)` (D9100#inline-15067)

login
register
mail settings
Submitter phabricator
Date Sept. 28, 2020, 2:49 p.m.
Message ID <differential-rev-PHID-DREV-hd2wi2vdgqbzdzpjfjrm-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47323/
State Superseded
Headers show

Comments

phabricator - Sept. 28, 2020, 2:49 p.m.
acezar created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/operations/list_tracked_files.rs
  rust/hg-core/src/revlog/revlog.rs

CHANGE DETAILS




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

Patch

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
@@ -111,9 +111,8 @@ 
         let mut delta_chain = vec![];
         while let Some(base_rev) = entry.base_rev {
             delta_chain.push(entry);
-            entry = self
-                .get_entry(base_rev)
-                .map_err(|_| RevlogError::Corrupted)?;
+            entry =
+                self.get_entry(base_rev).or(Err(RevlogError::Corrupted))?;
         }
 
         // TODO do not look twice in the index
diff --git a/rust/hg-core/src/operations/list_tracked_files.rs b/rust/hg-core/src/operations/list_tracked_files.rs
--- a/rust/hg-core/src/operations/list_tracked_files.rs
+++ b/rust/hg-core/src/operations/list_tracked_files.rs
@@ -166,14 +166,13 @@ 
         let changelog_entry = match self.rev.parse::<Revision>() {
             Ok(rev) => self.changelog.get_rev(rev)?,
             _ => {
-                let changelog_node = hex::decode(&self.rev).map_err(|_| {
-                    ListRevTrackedFilesErrorKind::InvalidRevision
-                })?;
+                let changelog_node = hex::decode(&self.rev)
+                    .or(Err(ListRevTrackedFilesErrorKind::InvalidRevision))?;
                 self.changelog.get_node(&changelog_node)?
             }
         };
         let manifest_node = hex::decode(&changelog_entry.manifest_node()?)
-            .map_err(|_| ListRevTrackedFilesErrorKind::CorruptedRevlog)?;
+            .or(Err(ListRevTrackedFilesErrorKind::CorruptedRevlog))?;
 
         self.manifest_entry = Some(self.manifest.get_node(&manifest_node)?);