##// END OF EJS Templates
rust: make `Revision` a newtype...
rust: make `Revision` a newtype This change is the one we've been building towards during this series. The aim is to make `Revision` mean more than a simple integer, holding the information that it is valid for a given revlog index. While this still allows for programmer error, since creating a revision directly and querying a different index with a "checked" revision are still possible, the friction created by the newtype will hopefully make us think twice about which type to use. Enough of the Rust ecosystem relies on the newtype pattern to be efficiently optimized away (even compiler in codegen tests¹), so I'm not worried about this being a fundamental problem. [1] https://github.com/rust-lang/rust/blob/7a70647f195f6b0a0f1ebd72b1542ba91a32f43a/tests/codegen/vec-in-place.rs#L47

File last commit:

r51870:1928b770 default
r51872:4c5f6e95 default
Show More
list_tracked_files.rs
45 lines | 1.2 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
rust: use HgError in RevlogError and Vfs...
r47172 use crate::errors::HgError;
Raphaël Gomès
rhg-files: add support for narrow when specifying a revision...
r50880 use crate::matchers::Matcher;
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;
Raphaël Gomès
rust-clippy: merge "revlog" module definition and struct implementation...
r50832 use crate::revlog::RevlogError;
Raphaël Gomès
rhg-files: add support for narrow when specifying a revision...
r50880 use crate::utils::filter_map_results;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 use crate::utils::hg_path::HgPath;
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,
Raphaël Gomès
rhg-files: add support for narrow when specifying a revision...
r50880 narrow_matcher: Box<dyn Matcher>,
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)?;
Raphaël Gomès
rhg-files: add support for narrow when specifying a revision...
r50880 Ok(FilesForRev {
Raphaël Gomès
rust: use the new `UncheckedRevision` everywhere applicable...
r51870 manifest: repo.manifest_for_rev(rev.into())?,
Raphaël Gomès
rhg-files: add support for narrow when specifying a revision...
r50880 narrow_matcher,
})
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
Raphaël Gomès
rhg-files: add support for narrow when specifying a revision...
r50880 pub struct FilesForRev {
manifest: Manifest,
narrow_matcher: Box<dyn Matcher>,
}
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 impl FilesForRev {
Simon Sapin
rhg: Propogate manifest parse errors instead of panicking...
r49165 pub fn iter(&self) -> impl Iterator<Item = Result<&HgPath, HgError>> {
Raphaël Gomès
rhg-files: add support for narrow when specifying a revision...
r50880 filter_map_results(self.manifest.iter(), |entry| {
let path = entry.path;
Ok(if self.narrow_matcher.matches(path) {
Some(path)
} else {
None
})
})
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
}