Changeset View
Changeset View
Standalone View
Standalone View
rust/hg-core/src/operations/list_tracked_files.rs
Show All 16 Lines | |||||
use crate::DirstateError; | use crate::DirstateError; | ||||
use rayon::prelude::*; | use rayon::prelude::*; | ||||
/// List files under Mercurial control in the working directory | /// List files under Mercurial control in the working directory | ||||
/// by reading the dirstate | /// by reading the dirstate | ||||
pub struct Dirstate { | pub struct Dirstate { | ||||
/// The `dirstate` content. | /// The `dirstate` content. | ||||
content: Vec<u8>, | content: Vec<u8>, | ||||
dirstate_v2: bool, | v2_metadata: Option<Vec<u8>>, | ||||
} | } | ||||
impl Dirstate { | impl Dirstate { | ||||
pub fn new(repo: &Repo) -> Result<Self, HgError> { | pub fn new(repo: &Repo) -> Result<Self, HgError> { | ||||
let mut content = repo.hg_vfs().read("dirstate")?; | let mut content = repo.hg_vfs().read("dirstate")?; | ||||
if repo.has_dirstate_v2() { | let v2_metadata = if repo.has_dirstate_v2() { | ||||
let docket = read_docket(&content)?; | let docket = read_docket(&content)?; | ||||
let meta = docket.tree_metadata().to_vec(); | |||||
content = repo.hg_vfs().read(docket.data_filename())?; | content = repo.hg_vfs().read(docket.data_filename())?; | ||||
} | Some(meta) | ||||
} else { | |||||
None | |||||
}; | |||||
Ok(Self { | Ok(Self { | ||||
content, | content, | ||||
dirstate_v2: repo.has_dirstate_v2(), | v2_metadata, | ||||
}) | }) | ||||
} | } | ||||
pub fn tracked_files(&self) -> Result<Vec<&HgPath>, DirstateError> { | pub fn tracked_files(&self) -> Result<Vec<&HgPath>, DirstateError> { | ||||
let mut files = Vec::new(); | let mut files = Vec::new(); | ||||
if !self.content.is_empty() { | if !self.content.is_empty() { | ||||
if self.dirstate_v2 { | if let Some(meta) = &self.v2_metadata { | ||||
for_each_tracked_path(&self.content, |path| files.push(path))? | for_each_tracked_path(&self.content, meta, |path| { | ||||
files.push(path) | |||||
})? | |||||
} else { | } else { | ||||
let _parents = parse_dirstate_entries( | let _parents = parse_dirstate_entries( | ||||
&self.content, | &self.content, | ||||
|path, entry, _copy_source| { | |path, entry, _copy_source| { | ||||
if entry.state.is_tracked() { | if entry.state.is_tracked() { | ||||
files.push(path) | files.push(path) | ||||
} | } | ||||
Ok(()) | Ok(()) | ||||
Show All 31 Lines |