##// END OF EJS Templates
makefile: add a install option...
makefile: add a install option This gives and easy way to install rhg that we can use in `run-test.py` in the next changesets. Differential Revision: https://phab.mercurial-scm.org/D10194

File last commit:

r47172:43d63979 default
r47487:99c0b038 default
Show More
list_tracked_files.rs
67 lines | 2.0 KiB | application/rls-services+xml | RustLexer
/ rust / hg-core / src / operations / list_tracked_files.rs
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 // 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.
use crate::dirstate::parsers::parse_dirstate;
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 use crate::errors::HgError;
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 use crate::repo::Repo;
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 use crate::revlog::changelog::Changelog;
use crate::revlog::manifest::{Manifest, ManifestEntry};
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 use crate::revlog::node::Node;
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 use crate::revlog::revlog::RevlogError;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 use crate::utils::hg_path::HgPath;
Simon Sapin
rust: Remove DirstateParseError and ListDirstateTrackedFilesError...
r47169 use crate::EntryState;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 use rayon::prelude::*;
/// List files under Mercurial control in the working directory
/// by reading the dirstate
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub struct Dirstate {
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 /// The `dirstate` content.
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 content: Vec<u8>,
}
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 impl Dirstate {
Simon Sapin
rust: Remove DirstateParseError and ListDirstateTrackedFilesError...
r47169 pub fn new(repo: &Repo) -> Result<Self, HgError> {
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 let content = repo.hg_vfs().read("dirstate")?;
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 Ok(Self { content })
}
Simon Sapin
rust: Remove DirstateParseError and ListDirstateTrackedFilesError...
r47169 pub fn tracked_files(&self) -> Result<Vec<&HgPath>, HgError> {
let (_, entries, _) = parse_dirstate(&self.content)?;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 let mut files: Vec<&HgPath> = entries
.into_iter()
.filter_map(|(path, entry)| match entry.state {
EntryState::Removed => None,
_ => Some(path),
})
.collect();
files.par_sort_unstable();
Ok(files)
}
}
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107
/// List files under Mercurial control at a given revision.
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub fn list_rev_tracked_files(
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
rust: remove three enums that were identical to `RevlogError`...
r47166 ) -> Result<FilesForRev, RevlogError> {
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 let rev = crate::revset::resolve_single(revset, repo)?;
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 let changelog = Changelog::open(repo)?;
let manifest = Manifest::open(repo)?;
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 let changelog_entry = changelog.get_rev(rev)?;
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 let manifest_node =
Node::from_hex_for_repo(&changelog_entry.manifest_node()?)?;
Simon Sapin
rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef...
r47160 let manifest_entry = manifest.get_node(manifest_node.into())?;
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 Ok(FilesForRev(manifest_entry))
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub struct FilesForRev(ManifestEntry);
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 impl FilesForRev {
pub fn iter(&self) -> impl Iterator<Item = &HgPath> {
self.0.files()
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
}