##// END OF EJS Templates
dirstate-v2: initial Python parser...
dirstate-v2: initial Python parser The dirstate-v2 file format should be supported even if Rust extensions are not enabled. This changeset adds parsing code that is not used yet. Differential Revision: https://phab.mercurial-scm.org/D11518

File last commit:

r48834:f2a9db29 default
r49035:a32a9607 default
Show More
list_tracked_files.rs
82 lines | 2.4 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.
Simon Sapin
rhg: Remove some intermediate Vecs in `rhg files`...
r48164 use crate::dirstate::parsers::parse_dirstate_entries;
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 use crate::dirstate_tree::on_disk::{for_each_tracked_path, read_docket};
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;
Simon Sapin
rust: Keep lazily-initialized Changelog and Manifest log on the Repo object...
r48773 use crate::revlog::manifest::Manifest;
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
rhg: Add support for dirstate-v2...
r48165 use crate::DirstateError;
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
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 v2_metadata: Option<Vec<u8>>,
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 }
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
dirstate-v2: Introduce a docket file...
r48474 let mut content = repo.hg_vfs().read("dirstate")?;
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 let v2_metadata = if repo.has_dirstate_v2() {
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 let docket = read_docket(&content)?;
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 let meta = docket.tree_metadata().to_vec();
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 content = repo.hg_vfs().read(docket.data_filename())?;
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 Some(meta)
} else {
None
};
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 Ok(Self {
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 content,
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 v2_metadata,
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 })
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 }
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 pub fn tracked_files(&self) -> Result<Vec<&HgPath>, DirstateError> {
Simon Sapin
rhg: Remove some intermediate Vecs in `rhg files`...
r48164 let mut files = Vec::new();
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 if !self.content.is_empty() {
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 if let Some(meta) = &self.v2_metadata {
for_each_tracked_path(&self.content, meta, |path| {
files.push(path)
})?
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 } else {
let _parents = parse_dirstate_entries(
&self.content,
|path, entry, _copy_source| {
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 if entry.state().is_tracked() {
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 files.push(path)
}
Ok(())
},
)?;
}
}
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 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
rhg: Reuse manifest when checking status of multiple ambiguous files...
r48778 Ok(FilesForRev(repo.manifest_for_rev(rev)?))
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
Simon Sapin
rust: Rename Manifest to Manifestlog, ManifestEntry to Manifest...
r48771 pub struct FilesForRev(Manifest);
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 }
}