# HG changeset patch # User Simon Sapin # Date 1607950064 -3600 # Node ID cc6faec62cb77e30d54a1a387f6058067e5c8f96 # Parent 0a4d47f4337b39819994e5f404c61a55cc600d97 rust: change &PathBuf parameters to &Path This is just as useful in function bodies, and a less strict requirement for callers. Differential Revision: https://phab.mercurial-scm.org/D9594 diff -r 0a4d47f4337b -r cc6faec62cb7 rust/hg-core/src/operations/cat.rs --- a/rust/hg-core/src/operations/cat.rs Wed Dec 16 21:06:29 2020 -0800 +++ b/rust/hg-core/src/operations/cat.rs Mon Dec 14 13:47:44 2020 +0100 @@ -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 { diff -r 0a4d47f4337b -r cc6faec62cb7 rust/hg-core/src/operations/list_tracked_files.rs --- a/rust/hg-core/src/operations/list_tracked_files.rs Wed Dec 16 21:06:29 2020 -0800 +++ b/rust/hg-core/src/operations/list_tracked_files.rs Mon Dec 14 13:47:44 2020 +0100 @@ -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 { + pub fn new(root: &Path) -> Result { 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 { - let changelog = Changelog::open(&root)?; - let manifest = Manifest::open(&root)?; + let changelog = Changelog::open(root)?; + let manifest = Manifest::open(root)?; Ok(Self { rev, diff -r 0a4d47f4337b -r cc6faec62cb7 rust/hg-core/src/revlog/changelog.rs --- a/rust/hg-core/src/revlog/changelog.rs Wed Dec 16 21:06:29 2020 -0800 +++ b/rust/hg-core/src/revlog/changelog.rs Mon Dec 14 13:47:44 2020 +0100 @@ -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 { + pub fn open(root: &Path) -> Result { let index_file = root.join(".hg/store/00changelog.i"); let revlog = Revlog::open(&index_file, None)?; Ok(Self { revlog }) diff -r 0a4d47f4337b -r cc6faec62cb7 rust/hg-core/src/revlog/manifest.rs --- a/rust/hg-core/src/revlog/manifest.rs Wed Dec 16 21:06:29 2020 -0800 +++ b/rust/hg-core/src/revlog/manifest.rs Mon Dec 14 13:47:44 2020 +0100 @@ -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 { + pub fn open(root: &Path) -> Result { let index_file = root.join(".hg/store/00manifest.i"); let revlog = Revlog::open(&index_file, None)?; Ok(Self { revlog }) diff -r 0a4d47f4337b -r cc6faec62cb7 rust/rhg/src/commands/files.rs --- a/rust/rhg/src/commands/files.rs Wed Dec 16 21:06:29 2020 -0800 +++ b/rust/rhg/src/commands/files.rs Mon Dec 14 13:47:44 2020 +0100 @@ -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, ) -> 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));