Mercurial > hg
changeset 46134:cc6faec62cb7
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
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 14 Dec 2020 13:47:44 +0100 |
parents | 0a4d47f4337b |
children | dca9cb99971c |
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 |
diffstat | 5 files changed, 14 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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<Self, CatRevError> {
--- 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<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,
--- 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<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 })
--- 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<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 })
--- 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<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));