Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/operations/cat.rs @ 46167:8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
This is similar to the corresponding Python classes.
Repo represents a repository and knows the path to the `.hg` directory,
the `store` directory, and the working directory.
Separating these will enable supporting the share extension.
A Vfs is created from a Repo for one of these three directories.
It has filesystem access APIs that take a relative std::path::Path
as a parameter.
Differential Revision: https://phab.mercurial-scm.org/D9596
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 14 Dec 2020 16:33:15 +0100 |
parents | dca9cb99971c |
children | 645ee7225fab |
line wrap: on
line diff
--- a/rust/hg-core/src/operations/cat.rs Sat Dec 19 15:56:54 2020 +0100 +++ b/rust/hg-core/src/operations/cat.rs Mon Dec 14 16:33:15 2020 +0100 @@ -6,8 +6,9 @@ // GNU General Public License version 2 or any later version. use std::convert::From; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; +use crate::repo::Repo; use crate::revlog::changelog::Changelog; use crate::revlog::manifest::Manifest; use crate::revlog::path_encode::path_encode; @@ -75,12 +76,12 @@ /// * `rev`: The revision to cat the files from. /// * `files`: The files to output. pub fn cat( - root: &Path, + repo: &Repo, rev: &str, files: &[HgPathBuf], ) -> Result<Vec<u8>, CatRevError> { - let changelog = Changelog::open(&root)?; - let manifest = Manifest::open(&root)?; + let changelog = Changelog::open(repo)?; + let manifest = Manifest::open(repo)?; let changelog_entry = match rev.parse::<Revision>() { Ok(rev) => changelog.get_rev(rev)?, @@ -99,10 +100,11 @@ for (manifest_file, node_bytes) in manifest_entry.files_with_nodes() { for cat_file in files.iter() { if cat_file.as_bytes() == manifest_file.as_bytes() { - let index_path = store_path(root, manifest_file, b".i"); - let data_path = store_path(root, manifest_file, b".d"); + let index_path = store_path(manifest_file, b".i"); + let data_path = store_path(manifest_file, b".d"); - let file_log = Revlog::open(&index_path, Some(&data_path))?; + let file_log = + Revlog::open(repo, &index_path, Some(&data_path))?; let file_node = Node::from_hex(node_bytes) .map_err(|_| CatRevErrorKind::CorruptedRevlog)?; let file_rev = file_log.get_node_rev((&file_node).into())?; @@ -126,14 +128,8 @@ Ok(bytes) } -fn store_path(root: &Path, hg_path: &HgPath, suffix: &[u8]) -> PathBuf { +fn store_path(hg_path: &HgPath, suffix: &[u8]) -> PathBuf { let encoded_bytes = path_encode(&[b"data/", hg_path.as_bytes(), suffix].concat()); - [ - root, - &Path::new(".hg/store/"), - get_path_from_bytes(&encoded_bytes), - ] - .iter() - .collect() + get_path_from_bytes(&encoded_bytes).into() }