Use parse_dirstate to list the files tracked in the working directory.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
| hg-reviewers |
Use parse_dirstate to list the files tracked in the working directory.
| No Linters Available |
| No Unit Test Coverage |
| Path | Packages | |||
|---|---|---|---|---|
| M | rust/hg-core/src/operations/list_tracked_files.rs (38 lines) | |||
| M | rust/hg-core/src/operations/mod.rs (3 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| a3426b511803 | 653ce7b3a02b | Antoine Cezar | Jul 17 2020, 10:51 AM |
| use super::find_root; | |||||
| use super::Operation; | use super::Operation; | ||||
| use crate::dirstate::parsers::parse_dirstate; | |||||
| use crate::utils::hg_path::HgPathBuf; | use crate::utils::hg_path::HgPathBuf; | ||||
| use crate::DirstateParseError; | |||||
| use rayon::prelude::*; | |||||
| use std::convert::From; | |||||
| use std::fmt; | use std::fmt; | ||||
| use std::fs; | |||||
| use std::io; | |||||
| /// Kind of error encoutered by ListTrackedFiles | /// Kind of error encoutered by ListTrackedFiles | ||||
| #[derive(Debug)] | #[derive(Debug)] | ||||
| pub enum ListTrackedFilesErrorKind {} | pub enum ListTrackedFilesErrorKind { | ||||
| FindRootError(find_root::FindRootError), | |||||
| IoError(io::Error), | |||||
| ParseError(DirstateParseError), | |||||
| } | |||||
| /// A ListTrackedFiles error | /// A ListTrackedFiles error | ||||
| #[derive(Debug)] | #[derive(Debug)] | ||||
| pub struct ListTrackedFilesError { | pub struct ListTrackedFilesError { | ||||
| /// Kind of error encoutered by ListTrackedFiles | /// Kind of error encoutered by ListTrackedFiles | ||||
| pub kind: ListTrackedFilesErrorKind, | pub kind: ListTrackedFilesErrorKind, | ||||
| } | } | ||||
| impl std::error::Error for ListTrackedFilesError {} | impl std::error::Error for ListTrackedFilesError {} | ||||
| impl fmt::Display for ListTrackedFilesError { | impl fmt::Display for ListTrackedFilesError { | ||||
| fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { | fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||
| unimplemented!() | unimplemented!() | ||||
| } | } | ||||
| } | } | ||||
| impl From<ListTrackedFilesErrorKind> for ListTrackedFilesError { | |||||
| fn from(kind: ListTrackedFilesErrorKind) -> Self { | |||||
| ListTrackedFilesError { kind } | |||||
| } | |||||
| } | |||||
| /// List files under Mercurial control in the working directory | /// List files under Mercurial control in the working directory | ||||
| /// by reading the dirstate at .hg/dirstate | /// by reading the dirstate at .hg/dirstate | ||||
| pub struct ListTrackedFiles {} | pub struct ListTrackedFiles {} | ||||
| impl ListTrackedFiles { | |||||
| pub fn new() -> Self { | |||||
| ListTrackedFiles {} | |||||
| } | |||||
| } | |||||
| impl Operation<Vec<HgPathBuf>> for ListTrackedFiles { | impl Operation<Vec<HgPathBuf>> for ListTrackedFiles { | ||||
| type Error = ListTrackedFilesError; | type Error = ListTrackedFilesError; | ||||
| fn run(&self) -> Result<Vec<HgPathBuf>, Self::Error> { | fn run(&self) -> Result<Vec<HgPathBuf>, Self::Error> { | ||||
| unimplemented!() | let root = find_root::FindRoot::new() | ||||
| .run() | |||||
| .map_err(ListTrackedFilesErrorKind::FindRootError)?; | |||||
| let dirstate = &root.join(".hg/dirstate"); | |||||
| let dirstate_content = | |||||
| fs::read(&dirstate).map_err(ListTrackedFilesErrorKind::IoError)?; | |||||
| let (_, entries, _) = parse_dirstate(&dirstate_content) | |||||
| .map_err(ListTrackedFilesErrorKind::ParseError)?; | |||||
| let mut files: Vec<_> = | |||||
| entries.into_iter().map(|(path, _)| path).collect(); | |||||
| files.par_sort_unstable(); | |||||
| Ok(files) | |||||
| } | } | ||||
| } | } | ||||
| mod find_root; | mod find_root; | ||||
| mod list_tracked_files; | mod list_tracked_files; | ||||
| pub use find_root::{FindRoot, FindRootError, FindRootErrorKind}; | pub use find_root::{FindRoot, FindRootError, FindRootErrorKind}; | ||||
| pub use list_tracked_files::{ | |||||
| ListTrackedFiles, ListTrackedFilesError, ListTrackedFilesErrorKind, | |||||
| }; | |||||
| /// An interface for high-level hg operations. | /// An interface for high-level hg operations. | ||||
| /// | /// | ||||
| /// A distinction is made between operation and commands. | /// A distinction is made between operation and commands. | ||||
| /// An operation is what can be done whereas a command is what is exposed by | /// An operation is what can be done whereas a command is what is exposed by | ||||
| /// the cli. A single command can use several operations to achieve its goal. | /// the cli. A single command can use several operations to achieve its goal. | ||||
| pub trait Operation<T> { | pub trait Operation<T> { | ||||
| type Error; | type Error; | ||||
| fn run(&self) -> Result<T, Self::Error>; | fn run(&self) -> Result<T, Self::Error>; | ||||
| } | } | ||||