4 // |
4 // |
5 // This software may be used and distributed according to the terms of the |
5 // This software may be used and distributed according to the terms of the |
6 // GNU General Public License version 2 or any later version. |
6 // GNU General Public License version 2 or any later version. |
7 |
7 |
8 use crate::dirstate::parsers::parse_dirstate_entries; |
8 use crate::dirstate::parsers::parse_dirstate_entries; |
|
9 use crate::dirstate_tree::on_disk::for_each_tracked_path; |
9 use crate::errors::HgError; |
10 use crate::errors::HgError; |
10 use crate::repo::Repo; |
11 use crate::repo::Repo; |
11 use crate::revlog::changelog::Changelog; |
12 use crate::revlog::changelog::Changelog; |
12 use crate::revlog::manifest::{Manifest, ManifestEntry}; |
13 use crate::revlog::manifest::{Manifest, ManifestEntry}; |
13 use crate::revlog::node::Node; |
14 use crate::revlog::node::Node; |
14 use crate::revlog::revlog::RevlogError; |
15 use crate::revlog::revlog::RevlogError; |
15 use crate::utils::hg_path::HgPath; |
16 use crate::utils::hg_path::HgPath; |
|
17 use crate::DirstateError; |
16 use rayon::prelude::*; |
18 use rayon::prelude::*; |
17 |
19 |
18 /// List files under Mercurial control in the working directory |
20 /// List files under Mercurial control in the working directory |
19 /// by reading the dirstate |
21 /// by reading the dirstate |
20 pub struct Dirstate { |
22 pub struct Dirstate { |
21 /// The `dirstate` content. |
23 /// The `dirstate` content. |
22 content: Vec<u8>, |
24 content: Vec<u8>, |
|
25 dirstate_v2: bool, |
23 } |
26 } |
24 |
27 |
25 impl Dirstate { |
28 impl Dirstate { |
26 pub fn new(repo: &Repo) -> Result<Self, HgError> { |
29 pub fn new(repo: &Repo) -> Result<Self, HgError> { |
27 let content = repo.hg_vfs().read("dirstate")?; |
30 Ok(Self { |
28 Ok(Self { content }) |
31 content: repo.hg_vfs().read("dirstate")?, |
|
32 dirstate_v2: repo.has_dirstate_v2(), |
|
33 }) |
29 } |
34 } |
30 |
35 |
31 pub fn tracked_files(&self) -> Result<Vec<&HgPath>, HgError> { |
36 pub fn tracked_files(&self) -> Result<Vec<&HgPath>, DirstateError> { |
32 let mut files = Vec::new(); |
37 let mut files = Vec::new(); |
33 let _parents = parse_dirstate_entries( |
38 if !self.content.is_empty() { |
34 &self.content, |
39 if self.dirstate_v2 { |
35 |path, entry, _copy_source| { |
40 for_each_tracked_path(&self.content, |path| files.push(path))? |
36 if entry.state.is_tracked() { |
41 } else { |
37 files.push(path) |
42 let _parents = parse_dirstate_entries( |
38 } |
43 &self.content, |
39 Ok(()) |
44 |path, entry, _copy_source| { |
40 }, |
45 if entry.state.is_tracked() { |
41 )?; |
46 files.push(path) |
|
47 } |
|
48 Ok(()) |
|
49 }, |
|
50 )?; |
|
51 } |
|
52 } |
42 files.par_sort_unstable(); |
53 files.par_sort_unstable(); |
43 Ok(files) |
54 Ok(files) |
44 } |
55 } |
45 } |
56 } |
46 |
57 |