Patchwork D9594: rust: change &PathBuf parameters to &Path

login
register
mail settings
Submitter phabricator
Date Dec. 14, 2020, 4:27 p.m.
Message ID <differential-rev-PHID-DREV-xbjr6a4kcdnpde65rfc2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47892/
State Superseded
Headers show

Comments

phabricator - Dec. 14, 2020, 4:27 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is just as useful in function bodies, and a less strict requirement for callers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/operations/cat.rs
  rust/hg-core/src/operations/list_tracked_files.rs
  rust/hg-core/src/revlog/changelog.rs
  rust/hg-core/src/revlog/manifest.rs
  rust/rhg/src/commands/files.rs

CHANGE DETAILS




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

Patch

diff --git a/rust/rhg/src/commands/files.rs b/rust/rhg/src/commands/files.rs
--- a/rust/rhg/src/commands/files.rs
+++ b/rust/rhg/src/commands/files.rs
@@ -14,7 +14,7 @@ 
 use hg::requirements;
 use hg::utils::files::{get_bytes_from_path, relativize_path};
 use hg::utils::hg_path::{HgPath, HgPathBuf};
-use std::path::PathBuf;
+use std::path::Path;
 
 pub const HELP_TEXT: &str = "
 List tracked files.
@@ -34,13 +34,13 @@ 
     fn display_files(
         &self,
         ui: &Ui,
-        root: &PathBuf,
+        root: &Path,
         files: impl IntoIterator<Item = &'a HgPath>,
     ) -> Result<(), CommandError> {
         let cwd = std::env::current_dir()
             .or_else(|e| Err(CommandErrorKind::CurrentDirNotFound(e)))?;
         let rooted_cwd = cwd
-            .strip_prefix(&root)
+            .strip_prefix(root)
             .expect("cwd was already checked within the repository");
         let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd));
 
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
@@ -2,7 +2,7 @@ 
 use crate::revlog::NodePrefixRef;
 use crate::revlog::Revision;
 use crate::utils::hg_path::HgPath;
-use std::path::PathBuf;
+use std::path::Path;
 
 /// A specialized `Revlog` to work with `manifest` data format.
 pub struct Manifest {
@@ -12,7 +12,7 @@ 
 
 impl Manifest {
     /// Open the `manifest` of a repository given by its root.
-    pub fn open(root: &PathBuf) -> Result<Self, RevlogError> {
+    pub fn open(root: &Path) -> Result<Self, RevlogError> {
         let index_file = root.join(".hg/store/00manifest.i");
         let revlog = Revlog::open(&index_file, None)?;
         Ok(Self { revlog })
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
@@ -1,7 +1,7 @@ 
 use crate::revlog::revlog::{Revlog, RevlogError};
 use crate::revlog::NodePrefixRef;
 use crate::revlog::Revision;
-use std::path::PathBuf;
+use std::path::Path;
 
 /// A specialized `Revlog` to work with `changelog` data format.
 pub struct Changelog {
@@ -11,7 +11,7 @@ 
 
 impl Changelog {
     /// Open the `changelog` of a repository given by its root.
-    pub fn open(root: &PathBuf) -> Result<Self, RevlogError> {
+    pub fn open(root: &Path) -> Result<Self, RevlogError> {
         let index_file = root.join(".hg/store/00changelog.i");
         let revlog = Revlog::open(&index_file, None)?;
         Ok(Self { revlog })
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
@@ -16,7 +16,7 @@ 
 use rayon::prelude::*;
 use std::convert::From;
 use std::fs;
-use std::path::PathBuf;
+use std::path::Path;
 
 /// Kind of error encountered by `ListDirstateTrackedFiles`
 #[derive(Debug)]
@@ -57,7 +57,7 @@ 
 }
 
 impl ListDirstateTrackedFiles {
-    pub fn new(root: &PathBuf) -> Result<Self, ListDirstateTrackedFilesError> {
+    pub fn new(root: &Path) -> Result<Self, ListDirstateTrackedFilesError> {
         let dirstate = root.join(".hg/dirstate");
         let content = fs::read(&dirstate)?;
         Ok(Self { content })
@@ -152,11 +152,11 @@ 
 
 impl<'a> ListRevTrackedFiles<'a> {
     pub fn new(
-        root: &PathBuf,
+        root: &Path,
         rev: &'a str,
     ) -> Result<Self, ListRevTrackedFilesError> {
-        let changelog = Changelog::open(&root)?;
-        let manifest = Manifest::open(&root)?;
+        let changelog = Changelog::open(root)?;
+        let manifest = Manifest::open(root)?;
 
         Ok(Self {
             rev,
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
@@ -71,7 +71,7 @@ 
 
 /// List files under Mercurial control at a given revision.
 pub struct CatRev<'a> {
-    root: &'a PathBuf,
+    root: &'a Path,
     /// The revision to cat the files from.
     rev: &'a str,
     /// The files to output.
@@ -88,7 +88,7 @@ 
 
 impl<'a> CatRev<'a> {
     pub fn new(
-        root: &'a PathBuf,
+        root: &'a Path,
         rev: &'a str,
         files: &'a [HgPathBuf],
     ) -> Result<Self, CatRevError> {