list_tracked_files.rs
45 lines
| 1.2 KiB
| application/rls-services+xml
|
RustLexer
Antoine Cezar
|
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
|
r47172 | use crate::errors::HgError; | ||
Raphaël Gomès
|
r50880 | use crate::matchers::Matcher; | ||
Simon Sapin
|
r46782 | use crate::repo::Repo; | ||
Simon Sapin
|
r48773 | use crate::revlog::manifest::Manifest; | ||
Raphaël Gomès
|
r50832 | use crate::revlog::RevlogError; | ||
Raphaël Gomès
|
r50880 | use crate::utils::filter_map_results; | ||
Antoine Cezar
|
r45918 | use crate::utils::hg_path::HgPath; | ||
Antoine Cezar
|
r46107 | |||
/// List files under Mercurial control at a given revision. | ||||
Simon Sapin
|
r46751 | pub fn list_rev_tracked_files( | ||
Simon Sapin
|
r46782 | repo: &Repo, | ||
Simon Sapin
|
r47162 | revset: &str, | ||
Raphaël Gomès
|
r50880 | narrow_matcher: Box<dyn Matcher>, | ||
Simon Sapin
|
r47166 | ) -> Result<FilesForRev, RevlogError> { | ||
Simon Sapin
|
r47162 | let rev = crate::revset::resolve_single(revset, repo)?; | ||
Raphaël Gomès
|
r50880 | Ok(FilesForRev { | ||
manifest: repo.manifest_for_rev(rev)?, | ||||
narrow_matcher, | ||||
}) | ||||
Antoine Cezar
|
r46107 | } | ||
Raphaël Gomès
|
r50880 | pub struct FilesForRev { | ||
manifest: Manifest, | ||||
narrow_matcher: Box<dyn Matcher>, | ||||
} | ||||
Antoine Cezar
|
r46107 | |||
Simon Sapin
|
r46751 | impl FilesForRev { | ||
Simon Sapin
|
r49165 | pub fn iter(&self) -> impl Iterator<Item = Result<&HgPath, HgError>> { | ||
Raphaël Gomès
|
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
|
r46107 | } | ||
} | ||||