##// END OF EJS Templates
dirstate: Move more methods to the _dirstatemapcommon base class...
dirstate: Move more methods to the _dirstatemapcommon base class This reduces duplication slightly and will help with supporting dirstate-v2 when Rust is not enabled. Differential Revision: https://phab.mercurial-scm.org/D11621

File last commit:

r48783:87e3f878 default
r49034:e7b5e8ba default
Show More
cat.rs
71 lines | 2.1 KiB | application/rls-services+xml | RustLexer
Antoine Cezar
hg-core: add a `CatRev` operation...
r46112 // list_tracked_files.rs
//
// Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 use crate::repo::Repo;
Antoine Cezar
hg-core: add a `CatRev` operation...
r46112 use crate::revlog::revlog::RevlogError;
Simon Sapin
rust: use NodePrefix::from_hex instead of hex::decode directly...
r46647 use crate::revlog::Node;
Simon Sapin
rust: Add a Filelog struct that wraps Revlog...
r48775
use crate::utils::hg_path::HgPathBuf;
Antoine Cezar
hg-core: add a `CatRev` operation...
r46112
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 pub struct CatOutput {
/// Whether any file in the manifest matched the paths given as CLI
/// arguments
pub found_any: bool,
/// The contents of matching files, in manifest order
pub concatenated: Vec<u8>,
/// Which of the CLI arguments did not match any manifest file
pub missing: Vec<HgPathBuf>,
/// The node ID that the given revset was resolved to
pub node: Node,
}
/// Output the given revision of files
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 ///
/// * `root`: Repository root
/// * `rev`: The revision to cat the files from.
/// * `files`: The files to output.
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 pub fn cat<'a>(
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 repo: &Repo,
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 revset: &str,
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 files: &'a [HgPathBuf],
) -> Result<CatOutput, RevlogError> {
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 let rev = crate::revset::resolve_single(revset, repo)?;
Simon Sapin
rhg: Reuse manifest when checking status of multiple ambiguous files...
r48778 let manifest = repo.manifest_for_rev(rev)?;
Simon Sapin
rust: Add Repo::manifest(revision)...
r48774 let node = *repo
.changelog()?
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 .node_from_rev(rev)
Simon Sapin
rust: Add Repo::manifest(revision)...
r48774 .expect("should succeed when repo.manifest did");
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 let mut bytes = vec![];
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 let mut matched = vec![false; files.len()];
let mut found_any = false;
Antoine Cezar
hg-core: add a `CatRev` operation...
r46112
Simon Sapin
rust: Add Repo::manifest(revision)...
r48774 for (manifest_file, node_bytes) in manifest.files_with_nodes() {
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 for (cat_file, is_matched) in files.iter().zip(&mut matched) {
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 if cat_file.as_bytes() == manifest_file.as_bytes() {
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 *is_matched = true;
found_any = true;
Simon Sapin
rust: Add a Filelog struct that wraps Revlog...
r48775 let file_log = repo.filelog(manifest_file)?;
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 let file_node = Node::from_hex_for_repo(node_bytes)?;
Simon Sapin
rust: Rename get_node methods to data_for_node, get_rev to data_for_rev...
r48783 let entry = file_log.data_for_node(file_node)?;
Simon Sapin
rust: Add a Filelog struct that wraps Revlog...
r48775 bytes.extend(entry.data()?)
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 }
}
Antoine Cezar
hg-core: add a `CatRev` operation...
r46112 }
Simon Sapin
rhg: `cat` command: print error messages for missing files...
r47478 let missing: Vec<_> = files
.iter()
.zip(&matched)
.filter(|pair| !*pair.1)
.map(|pair| pair.0.clone())
.collect();
Ok(CatOutput {
found_any,
concatenated: bytes,
missing,
node,
})
Antoine Cezar
hg-core: add a `CatRev` operation...
r46112 }