##// END OF EJS Templates
dirstate-tree: Remove DirstateMap::iter_node_data_mut...
dirstate-tree: Remove DirstateMap::iter_node_data_mut In an upcoming changeset we want DirstateMap to be able to work directly with nodes in their "on disk" representation, without always allocating corresponding in-memory data structures. Nodes would have two possible representations: one immutable "on disk" refering to the bytes buffer of the contents of the .hg/dirstate file, and one mutable with HashMap like the curren data structure. These nodes would have copy-on-write semantics: when an immutable node would need to be mutated, instead we allocate new mutable node for it and its ancestors. A mutable iterator of the entire tree would still be possible, but it would become much more expensive since we’d need to allocate mutable nodes for everything. Instead, remove this iterator. It was only used to clear ambiguous mtimes while serializing the `DirstateMap`. Instead clearing and serialization are now two separate passes. Clearing first uses an immutable iterator to collect the paths of nodes that need to be cleared, then accesses only those nodes mutably. Differential Revision: https://phab.mercurial-scm.org/D10744

File last commit:

r47172:43d63979 default
r48121:73f23e76 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 }
}