Mercurial > hg
annotate rust/hg-core/src/dirstate/status.rs @ 44537:5f6a504dc0bd
rust-status: refactor handling of unknown files
Differential Revision: https://phab.mercurial-scm.org/D8249
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Fri, 06 Mar 2020 17:48:30 +0100 |
parents | f8a9922a02cb |
children | b8ba46c97cdd |
rev | line source |
---|---|
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 // status.rs |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 // |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 // |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 //! Rust implementation of dirstate.status (dirstate.py). |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 //! It is currently missing a lot of functionality compared to the Python one |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 //! and will only be triggered in narrow cases. |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
12 use crate::{ |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
13 dirstate::SIZE_FROM_OTHER_PARENT, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
14 filepatterns::PatternFileWarning, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
15 matchers::{get_ignore_function, Matcher, VisitChildrenSet}, |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
16 utils::{ |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
17 files::{find_dirs, HgMetadata}, |
44523
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
18 hg_path::{ |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
19 hg_path_to_path_buf, os_string_to_hg_path_buf, HgPath, HgPathBuf, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
20 HgPathError, |
44523
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
21 }, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
22 path_auditor::PathAuditor, |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
23 }, |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
24 CopyMap, DirstateEntry, DirstateMap, EntryState, FastHashMap, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
25 PatternError, |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
26 }; |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
27 use lazy_static::lazy_static; |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 use rayon::prelude::*; |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
29 use std::{ |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
30 borrow::Cow, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
31 collections::HashSet, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
32 fs::{read_dir, DirEntry}, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
33 io::ErrorKind, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
34 ops::Deref, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
35 path::Path, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
36 }; |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
38 /// Wrong type of file from a `BadMatch` |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
39 /// Note: a lot of those don't exist on all platforms. |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
40 #[derive(Debug, Copy, Clone)] |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
41 pub enum BadType { |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
42 CharacterDevice, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
43 BlockDevice, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
44 FIFO, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
45 Socket, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
46 Directory, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
47 Unknown, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
48 } |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
49 |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
50 impl ToString for BadType { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
51 fn to_string(&self) -> String { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
52 match self { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
53 BadType::CharacterDevice => "character device", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
54 BadType::BlockDevice => "block device", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
55 BadType::FIFO => "fifo", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
56 BadType::Socket => "socket", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
57 BadType::Directory => "directory", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
58 BadType::Unknown => "unknown", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
59 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
60 .to_string() |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
61 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
62 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44528
diff
changeset
|
63 |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
64 /// Was explicitly matched but cannot be found/accessed |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
65 #[derive(Debug, Copy, Clone)] |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
66 pub enum BadMatch { |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
67 OsError(i32), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
68 BadType(BadType), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
69 } |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
70 |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
71 /// Marker enum used to dispatch new status entries into the right collections. |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
72 /// Is similar to `crate::EntryState`, but represents the transient state of |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
73 /// entries during the lifetime of a command. |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
74 #[derive(Debug, Copy, Clone)] |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
75 enum Dispatch { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
76 Unsure, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
77 Modified, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
78 Added, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
79 Removed, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
80 Deleted, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
81 Clean, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
82 Unknown, |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
83 Ignored, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
84 /// Empty dispatch, the file is not worth listing |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
85 None, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
86 /// Was explicitly matched but cannot be found/accessed |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
87 Bad(BadMatch), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
88 Directory { |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
89 /// True if the directory used to be a file in the dmap so we can say |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
90 /// that it's been removed. |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
91 was_file: bool, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
92 }, |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
93 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
94 |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
95 type IoResult<T> = std::io::Result<T>; |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
96 |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
97 /// Dates and times that are outside the 31-bit signed range are compared |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
98 /// modulo 2^31. This should prevent hg from behaving badly with very large |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
99 /// files or corrupt dates while still having a high probability of detecting |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
100 /// changes. (issue2608) |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
101 /// TODO I haven't found a way of having `b` be `Into<i32>`, since `From<u64>` |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
102 /// is not defined for `i32`, and there is no `As` trait. This forces the |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
103 /// caller to cast `b` as `i32`. |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
104 fn mod_compare(a: i32, b: i32) -> bool { |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
105 a & i32::max_value() != b & i32::max_value() |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
106 } |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
107 |
44523
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
108 /// Return a sorted list containing information about the entries |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
109 /// in the directory. |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
110 /// |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
111 /// * `skip_dot_hg` - Return an empty vec if `path` contains a `.hg` directory |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
112 fn list_directory( |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
113 path: impl AsRef<Path>, |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
114 skip_dot_hg: bool, |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
115 ) -> std::io::Result<Vec<(HgPathBuf, DirEntry)>> { |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
116 let mut results = vec![]; |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
117 let entries = read_dir(path.as_ref())?; |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
118 |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
119 for entry in entries { |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
120 let entry = entry?; |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
121 let filename = os_string_to_hg_path_buf(entry.file_name())?; |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
122 let file_type = entry.file_type()?; |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
123 if skip_dot_hg && filename.as_bytes() == b".hg" && file_type.is_dir() { |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
124 return Ok(vec![]); |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
125 } else { |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
126 results.push((HgPathBuf::from(filename), entry)) |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
127 } |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
128 } |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
129 |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
130 results.sort_unstable_by_key(|e| e.0.clone()); |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
131 Ok(results) |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
132 } |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
133 |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
134 /// The file corresponding to the dirstate entry was found on the filesystem. |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
135 fn dispatch_found( |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
136 filename: impl AsRef<HgPath>, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
137 entry: DirstateEntry, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
138 metadata: HgMetadata, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
139 copy_map: &CopyMap, |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
140 options: StatusOptions, |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
141 ) -> Dispatch { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
142 let DirstateEntry { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
143 state, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
144 mode, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
145 mtime, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
146 size, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
147 } = entry; |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
148 |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
149 let HgMetadata { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
150 st_mode, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
151 st_size, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
152 st_mtime, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
153 .. |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
154 } = metadata; |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
155 |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
156 match state { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
157 EntryState::Normal => { |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
158 let size_changed = mod_compare(size, st_size as i32); |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
159 let mode_changed = |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
160 (mode ^ st_mode as i32) & 0o100 != 0o000 && options.check_exec; |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
161 let metadata_changed = size >= 0 && (size_changed || mode_changed); |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
162 let other_parent = size == SIZE_FROM_OTHER_PARENT; |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
163 if metadata_changed |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
164 || other_parent |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
165 || copy_map.contains_key(filename.as_ref()) |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
166 { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
167 Dispatch::Modified |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
168 } else if mod_compare(mtime, st_mtime as i32) { |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
169 Dispatch::Unsure |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
170 } else if st_mtime == options.last_normal_time { |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
171 // the file may have just been marked as normal and |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
172 // it may have changed in the same second without |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
173 // changing its size. This can happen if we quickly |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
174 // do multiple commits. Force lookup, so we don't |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
175 // miss such a racy file change. |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
176 Dispatch::Unsure |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
177 } else if options.list_clean { |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
178 Dispatch::Clean |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
179 } else { |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
180 Dispatch::None |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
181 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
182 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
183 EntryState::Merged => Dispatch::Modified, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
184 EntryState::Added => Dispatch::Added, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
185 EntryState::Removed => Dispatch::Removed, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
186 EntryState::Unknown => Dispatch::Unknown, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
187 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
188 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
189 |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
190 /// The file corresponding to this Dirstate entry is missing. |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
191 fn dispatch_missing(state: EntryState) -> Dispatch { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
192 match state { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
193 // File was removed from the filesystem during commands |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
194 EntryState::Normal | EntryState::Merged | EntryState::Added => { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
195 Dispatch::Deleted |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
196 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
197 // File was removed, everything is normal |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
198 EntryState::Removed => Dispatch::Removed, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
199 // File is unknown to Mercurial, everything is normal |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
200 EntryState::Unknown => Dispatch::Unknown, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
201 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
202 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
203 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
204 lazy_static! { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
205 static ref DEFAULT_WORK: HashSet<&'static HgPath> = { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
206 let mut h = HashSet::new(); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
207 h.insert(HgPath::new(b"")); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
208 h |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
209 }; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
210 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
211 |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
212 /// Get stat data about the files explicitly specified by match. |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
213 /// TODO subrepos |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
214 fn walk_explicit<'a>( |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
215 files: Option<&'a HashSet<&HgPath>>, |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
216 dmap: &'a DirstateMap, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
217 root_dir: impl AsRef<Path> + Sync + Send + 'a, |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
218 options: StatusOptions, |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
219 ) -> impl ParallelIterator<Item = IoResult<(&'a HgPath, Dispatch)>> { |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
220 files |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
221 .unwrap_or(&DEFAULT_WORK) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
222 .par_iter() |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
223 .map(move |filename| { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
224 // TODO normalization |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
225 let normalized = filename.as_ref(); |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
226 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
227 let buf = match hg_path_to_path_buf(normalized) { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
228 Ok(x) => x, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
229 Err(e) => return Some(Err(e.into())), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
230 }; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
231 let target = root_dir.as_ref().join(buf); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
232 let st = target.symlink_metadata(); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
233 let in_dmap = dmap.get(normalized); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
234 match st { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
235 Ok(meta) => { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
236 let file_type = meta.file_type(); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
237 return if file_type.is_file() || file_type.is_symlink() { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
238 if let Some(entry) = in_dmap { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
239 return Some(Ok(( |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
240 normalized, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
241 dispatch_found( |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
242 &normalized, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
243 *entry, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
244 HgMetadata::from_metadata(meta), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
245 &dmap.copy_map, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
246 options, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
247 ), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
248 ))); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
249 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
250 Some(Ok((normalized, Dispatch::Unknown))) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
251 } else { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
252 if file_type.is_dir() { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
253 Some(Ok(( |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
254 normalized, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
255 Dispatch::Directory { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
256 was_file: in_dmap.is_some(), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
257 }, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
258 ))) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
259 } else { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
260 Some(Ok(( |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
261 normalized, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
262 Dispatch::Bad(BadMatch::BadType( |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
263 // TODO do more than unknown |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
264 // Support for all `BadType` variant |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
265 // varies greatly between platforms. |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
266 // So far, no tests check the type and |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
267 // this should be good enough for most |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
268 // users. |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
269 BadType::Unknown, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
270 )), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
271 ))) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
272 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
273 }; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
274 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
275 Err(_) => { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
276 if let Some(entry) = in_dmap { |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
277 return Some(Ok(( |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
278 normalized, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
279 dispatch_missing(entry.state), |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
280 ))); |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
281 } |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
282 } |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
283 }; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
284 None |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
285 }) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
286 .flatten() |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
287 } |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
288 |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
289 #[derive(Debug, Copy, Clone)] |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
290 pub struct StatusOptions { |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
291 /// Remember the most recent modification timeslot for status, to make |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
292 /// sure we won't miss future size-preserving file content modifications |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
293 /// that happen within the same timeslot. |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
294 pub last_normal_time: i64, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
295 /// Whether we are on a filesystem with UNIX-like exec flags |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
296 pub check_exec: bool, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
297 pub list_clean: bool, |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
298 pub list_unknown: bool, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
299 pub list_ignored: bool, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
300 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
301 |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
302 /// Dispatch a single entry (file, folder, symlink...) found during `traverse`. |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
303 /// If the entry is a folder that needs to be traversed, it will be pushed into |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
304 /// `work`. |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
305 fn handle_traversed_entry<'a>( |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
306 dir_entry: &DirEntry, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
307 matcher: &(impl Matcher + Sync), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
308 root_dir: impl AsRef<Path>, |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
309 dmap: &DirstateMap, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
310 filename: impl AsRef<HgPath>, |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
311 old_results: &FastHashMap<Cow<'a, HgPath>, Dispatch>, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
312 ignore_fn: &(impl for<'r> Fn(&'r HgPath) -> bool + Sync), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
313 dir_ignore_fn: &(impl for<'r> Fn(&'r HgPath) -> bool + Sync), |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
314 options: StatusOptions, |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
315 ) -> IoResult<Vec<(Cow<'a, HgPath>, Dispatch)>> { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
316 let file_type = dir_entry.file_type()?; |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
317 let filename = filename.as_ref(); |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
318 let entry_option = dmap.get(filename); |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
319 |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
320 if file_type.is_dir() { |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
321 // Do we need to traverse it? |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
322 if !ignore_fn(&filename) || options.list_ignored { |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
323 return traverse_dir( |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
324 matcher, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
325 root_dir, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
326 dmap, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
327 filename.to_owned(), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
328 &old_results, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
329 ignore_fn, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
330 dir_ignore_fn, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
331 options, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
332 ); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
333 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
334 // Nested `if` until `rust-lang/rust#53668` is stable |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
335 if let Some(entry) = entry_option { |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
336 // Used to be a file, is now a folder |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
337 if matcher.matches_everything() || matcher.matches(&filename) { |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
338 return Ok(vec![( |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
339 Cow::Owned(filename.to_owned()), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
340 dispatch_missing(entry.state), |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
341 )]); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
342 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
343 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
344 } else if file_type.is_file() || file_type.is_symlink() { |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
345 if let Some(entry) = entry_option { |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
346 if matcher.matches_everything() || matcher.matches(&filename) { |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
347 let metadata = dir_entry.metadata()?; |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
348 return Ok(vec![( |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
349 Cow::Owned(filename.to_owned()), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
350 dispatch_found( |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
351 &filename, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
352 *entry, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
353 HgMetadata::from_metadata(metadata), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
354 &dmap.copy_map, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
355 options, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
356 ), |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
357 )]); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
358 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
359 } else if (matcher.matches_everything() || matcher.matches(&filename)) |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
360 && !ignore_fn(&filename) |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
361 { |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
362 if (options.list_ignored || matcher.exact_match(&filename)) |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
363 && dir_ignore_fn(&filename) |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
364 { |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
365 if options.list_ignored { |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
366 return Ok(vec![( |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
367 Cow::Owned(filename.to_owned()), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
368 Dispatch::Ignored, |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
369 )]); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
370 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
371 } else { |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
372 return Ok(vec![( |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
373 Cow::Owned(filename.to_owned()), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
374 Dispatch::Unknown, |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
375 )]); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
376 } |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
377 } else if ignore_fn(&filename) && options.list_ignored { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
378 return Ok(vec![( |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
379 Cow::Owned(filename.to_owned()), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
380 Dispatch::Ignored, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
381 )]); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
382 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
383 } else if let Some(entry) = entry_option { |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
384 // Used to be a file or a folder, now something else. |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
385 if matcher.matches_everything() || matcher.matches(&filename) { |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
386 return Ok(vec![( |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
387 Cow::Owned(filename.to_owned()), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
388 dispatch_missing(entry.state), |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
389 )]); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
390 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
391 } |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
392 return Ok(vec![]); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
393 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
394 |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
395 /// Decides whether the directory needs to be listed, and if so dispatches its |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
396 /// entries |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
397 fn traverse_dir<'a>( |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
398 matcher: &(impl Matcher + Sync), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
399 root_dir: impl AsRef<Path>, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
400 dmap: &DirstateMap, |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
401 path: impl AsRef<HgPath>, |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
402 old_results: &FastHashMap<Cow<'a, HgPath>, Dispatch>, |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
403 ignore_fn: &(impl for<'r> Fn(&'r HgPath) -> bool + Sync), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
404 dir_ignore_fn: &(impl for<'r> Fn(&'r HgPath) -> bool + Sync), |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
405 options: StatusOptions, |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
406 ) -> IoResult<Vec<(Cow<'a, HgPath>, Dispatch)>> { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
407 let directory = path.as_ref(); |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
408 if directory.as_bytes() == b".hg" { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
409 return Ok(vec![]); |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
410 } |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
411 let visit_entries = match matcher.visit_children_set(directory) { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
412 VisitChildrenSet::Empty => return Ok(vec![]), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
413 VisitChildrenSet::This | VisitChildrenSet::Recursive => None, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
414 VisitChildrenSet::Set(set) => Some(set), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
415 }; |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
416 let buf = hg_path_to_path_buf(directory)?; |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
417 let dir_path = root_dir.as_ref().join(buf); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
418 |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
419 let skip_dot_hg = !directory.as_bytes().is_empty(); |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
420 let entries = match list_directory(dir_path, skip_dot_hg) { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
421 Err(e) => match e.kind() { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
422 ErrorKind::NotFound | ErrorKind::PermissionDenied => { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
423 return Ok(vec![( |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
424 Cow::Owned(directory.to_owned()), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
425 Dispatch::Bad(BadMatch::OsError( |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
426 // Unwrapping here is OK because the error always |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
427 // is a real os error |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
428 e.raw_os_error().unwrap(), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
429 )), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
430 )]); |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
431 } |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
432 _ => return Err(e), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
433 }, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
434 Ok(entries) => entries, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
435 }; |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
436 |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
437 let mut new_results = vec![]; |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
438 for (filename, dir_entry) in entries { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
439 if let Some(ref set) = visit_entries { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
440 if !set.contains(filename.deref()) { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
441 continue; |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
442 } |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
443 } |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
444 // TODO normalize |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
445 let filename = if directory.is_empty() { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
446 filename.to_owned() |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
447 } else { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
448 directory.join(&filename) |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
449 }; |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
450 |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
451 if !old_results.contains_key(filename.deref()) { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
452 new_results.extend(handle_traversed_entry( |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
453 &dir_entry, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
454 matcher, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
455 root_dir.as_ref(), |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
456 &dmap, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
457 &filename, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
458 old_results, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
459 ignore_fn, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
460 dir_ignore_fn, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
461 options, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
462 )?); |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
463 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
464 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
465 Ok(new_results) |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
466 } |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
467 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
468 /// Stat all entries in the `DirstateMap` and mark them for dispatch. |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
469 fn stat_dmap_entries( |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
470 dmap: &DirstateMap, |
43603
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
471 root_dir: impl AsRef<Path> + Sync + Send, |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
472 options: StatusOptions, |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
473 ) -> impl ParallelIterator<Item = IoResult<(&HgPath, Dispatch)>> { |
43603
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
474 dmap.par_iter().map(move |(filename, entry)| { |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
475 let filename: &HgPath = filename; |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
476 let filename_as_path = hg_path_to_path_buf(filename)?; |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
477 let meta = root_dir.as_ref().join(filename_as_path).symlink_metadata(); |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
478 |
43603
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
479 match meta { |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
480 Ok(ref m) |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
481 if !(m.file_type().is_file() |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
482 || m.file_type().is_symlink()) => |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
483 { |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
484 Ok((filename, dispatch_missing(entry.state))) |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
485 } |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
486 Ok(m) => Ok(( |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
487 filename, |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
488 dispatch_found( |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
489 filename, |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
490 *entry, |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
491 HgMetadata::from_metadata(m), |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
492 &dmap.copy_map, |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
493 options, |
43603
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
494 ), |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
495 )), |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
496 Err(ref e) |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
497 if e.kind() == ErrorKind::NotFound |
43603
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
498 || e.raw_os_error() == Some(20) => |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
499 { |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
500 // Rust does not yet have an `ErrorKind` for |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
501 // `NotADirectory` (errno 20) |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
502 // It happens if the dirstate contains `foo/bar` and |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
503 // foo is not a directory |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
504 Ok((filename, dispatch_missing(entry.state))) |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
505 } |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
506 Err(e) => Err(e), |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
507 } |
75fe6e71ddb8
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries
Raphaël Gomès <rgomes@octobus.net>
parents:
43602
diff
changeset
|
508 }) |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
509 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
510 |
44525
f13d19549efd
rust-status: rename `StatusResult` to `DirstateStatus`
Raphaël Gomès <rgomes@octobus.net>
parents:
44524
diff
changeset
|
511 pub struct DirstateStatus<'a> { |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
512 pub modified: Vec<Cow<'a, HgPath>>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
513 pub added: Vec<Cow<'a, HgPath>>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
514 pub removed: Vec<Cow<'a, HgPath>>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
515 pub deleted: Vec<Cow<'a, HgPath>>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
516 pub clean: Vec<Cow<'a, HgPath>>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
517 pub ignored: Vec<Cow<'a, HgPath>>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
518 pub unknown: Vec<Cow<'a, HgPath>>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
519 pub bad: Vec<(Cow<'a, HgPath>, BadMatch)>, |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
520 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
521 |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
522 fn build_response<'a>( |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
523 results: impl IntoIterator<Item = (Cow<'a, HgPath>, Dispatch)>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
524 ) -> (Vec<Cow<'a, HgPath>>, DirstateStatus<'a>) { |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
525 let mut lookup = vec![]; |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
526 let mut modified = vec![]; |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
527 let mut added = vec![]; |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
528 let mut removed = vec![]; |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
529 let mut deleted = vec![]; |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
530 let mut clean = vec![]; |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
531 let mut ignored = vec![]; |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
532 let mut unknown = vec![]; |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
533 let mut bad = vec![]; |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
534 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
535 for (filename, dispatch) in results.into_iter() { |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
536 match dispatch { |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
537 Dispatch::Unknown => unknown.push(filename), |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
538 Dispatch::Unsure => lookup.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
539 Dispatch::Modified => modified.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
540 Dispatch::Added => added.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
541 Dispatch::Removed => removed.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
542 Dispatch::Deleted => deleted.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
543 Dispatch::Clean => clean.push(filename), |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
544 Dispatch::Ignored => ignored.push(filename), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
545 Dispatch::None => {} |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
546 Dispatch::Bad(reason) => bad.push((filename, reason)), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
547 Dispatch::Directory { .. } => {} |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
548 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
549 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
550 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
551 ( |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
552 lookup, |
44525
f13d19549efd
rust-status: rename `StatusResult` to `DirstateStatus`
Raphaël Gomès <rgomes@octobus.net>
parents:
44524
diff
changeset
|
553 DirstateStatus { |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
554 modified, |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
555 added, |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
556 removed, |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
557 deleted, |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
558 clean, |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
559 ignored, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
560 unknown, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
561 bad, |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
562 }, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
563 ) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
564 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
565 |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
566 pub enum StatusError { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
567 IO(std::io::Error), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
568 Path(HgPathError), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
569 Pattern(PatternError), |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
570 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
571 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
572 pub type StatusResult<T> = Result<T, StatusError>; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
573 |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
574 impl From<PatternError> for StatusError { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
575 fn from(e: PatternError) -> Self { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
576 StatusError::Pattern(e) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
577 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
578 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
579 impl From<HgPathError> for StatusError { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
580 fn from(e: HgPathError) -> Self { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
581 StatusError::Path(e) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
582 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
583 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
584 impl From<std::io::Error> for StatusError { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
585 fn from(e: std::io::Error) -> Self { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
586 StatusError::IO(e) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
587 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
588 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
589 |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
590 impl ToString for StatusError { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
591 fn to_string(&self) -> String { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
592 match self { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
593 StatusError::IO(e) => e.to_string(), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
594 StatusError::Path(e) => e.to_string(), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
595 StatusError::Pattern(e) => e.to_string(), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
596 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
597 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
598 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
599 |
44537
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
600 /// This takes a mutable reference to the results to account for the `extend` |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
601 /// in timings |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
602 fn handle_unknowns<'a>( |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
603 dmap: &'a DirstateMap, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
604 matcher: &(impl Matcher + Sync), |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
605 root_dir: impl AsRef<Path> + Sync + Send + Copy, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
606 options: StatusOptions, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
607 results: &mut Vec<(Cow<'a, HgPath>, Dispatch)>, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
608 ) -> IoResult<()> { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
609 let to_visit: Vec<(&HgPath, &DirstateEntry)> = if results.is_empty() |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
610 && matcher.matches_everything() |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
611 { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
612 dmap.iter().map(|(f, e)| (f.deref(), e)).collect() |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
613 } else { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
614 // Only convert to a hashmap if needed. |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
615 let old_results: FastHashMap<_, _> = results.iter().cloned().collect(); |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
616 dmap.iter() |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
617 .filter_map(move |(f, e)| { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
618 if !old_results.contains_key(f.deref()) && matcher.matches(f) { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
619 Some((f.deref(), e)) |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
620 } else { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
621 None |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
622 } |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
623 }) |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
624 .collect() |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
625 }; |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
626 |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
627 // We walked all dirs under the roots that weren't ignored, and |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
628 // everything that matched was stat'ed and is already in results. |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
629 // The rest must thus be ignored or under a symlink. |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
630 let path_auditor = PathAuditor::new(root_dir); |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
631 |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
632 // TODO don't collect. Find a way of replicating the behavior of |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
633 // `itertools::process_results`, but for `rayon::ParallelIterator` |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
634 let new_results: IoResult<Vec<_>> = to_visit |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
635 .into_par_iter() |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
636 .filter_map(|(filename, entry)| -> Option<IoResult<_>> { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
637 // Report ignored items in the dmap as long as they are not |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
638 // under a symlink directory. |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
639 if path_auditor.check(filename) { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
640 // TODO normalize for case-insensitive filesystems |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
641 let buf = match hg_path_to_path_buf(filename) { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
642 Ok(x) => x, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
643 Err(e) => return Some(Err(e.into())), |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
644 }; |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
645 Some(Ok(( |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
646 Cow::Borrowed(filename), |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
647 match root_dir.as_ref().join(&buf).symlink_metadata() { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
648 // File was just ignored, no links, and exists |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
649 Ok(meta) => { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
650 let metadata = HgMetadata::from_metadata(meta); |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
651 dispatch_found( |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
652 filename, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
653 *entry, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
654 metadata, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
655 &dmap.copy_map, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
656 options, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
657 ) |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
658 } |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
659 // File doesn't exist |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
660 Err(_) => dispatch_missing(entry.state), |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
661 }, |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
662 ))) |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
663 } else { |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
664 // It's either missing or under a symlink directory which |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
665 // we, in this case, report as missing. |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
666 Some(Ok(( |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
667 Cow::Borrowed(filename), |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
668 dispatch_missing(entry.state), |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
669 ))) |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
670 } |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
671 }) |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
672 .collect(); |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
673 |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
674 results.par_extend(new_results?); |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
675 |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
676 Ok(()) |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
677 } |
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
678 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
679 /// Get the status of files in the working directory. |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
680 /// |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
681 /// This is the current entry-point for `hg-core` and is realistically unusable |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
682 /// outside of a Python context because its arguments need to provide a lot of |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
683 /// information that will not be necessary in the future. |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
684 pub fn status<'a: 'c, 'b: 'c, 'c>( |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
685 dmap: &'a DirstateMap, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
686 matcher: &'b (impl Matcher + Sync), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
687 root_dir: impl AsRef<Path> + Sync + Send + Copy + 'c, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
688 ignore_files: &[impl AsRef<Path> + 'c], |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
689 options: StatusOptions, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
690 ) -> StatusResult<( |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
691 (Vec<Cow<'c, HgPath>>, DirstateStatus<'c>), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
692 Vec<PatternFileWarning>, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
693 )> { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
694 let (ignore_fn, warnings) = get_ignore_function(&ignore_files, root_dir)?; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
695 |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
696 // Is the path or one of its ancestors ignored? |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
697 let dir_ignore_fn = |dir: &_| { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
698 if ignore_fn(dir) { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
699 true |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
700 } else { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
701 for p in find_dirs(dir) { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
702 if ignore_fn(p) { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
703 return true; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
704 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
705 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
706 false |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
707 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
708 }; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
709 |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
710 let files = matcher.file_set(); |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
711 |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
712 // Step 1: check the files explicitly mentioned by the user |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
713 let explicit = walk_explicit(files, &dmap, root_dir, options); |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
714 |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
715 // Collect results into a `Vec` because we do very few lookups in most |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
716 // cases. |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
717 let (work, mut results): (Vec<_>, Vec<_>) = explicit |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
718 .filter_map(Result::ok) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
719 .map(|(filename, dispatch)| (Cow::Borrowed(filename), dispatch)) |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
720 .partition(|(_, dispatch)| match dispatch { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
721 Dispatch::Directory { .. } => true, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
722 _ => false, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
723 }); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
724 |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
725 if !work.is_empty() { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
726 // Hashmaps are quite a bit slower to build than vecs, so only build it |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
727 // if needed. |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
728 let old_results = results.iter().cloned().collect(); |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
729 |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
730 // Step 2: recursively check the working directory for changes if |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
731 // needed |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
732 for (dir, dispatch) in work { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
733 match dispatch { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
734 Dispatch::Directory { was_file } => { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
735 if was_file { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
736 results.push((dir.to_owned(), Dispatch::Removed)); |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
737 } |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
738 if options.list_ignored |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
739 || options.list_unknown && !dir_ignore_fn(&dir) |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
740 { |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
741 results.par_extend(traverse_dir( |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
742 matcher, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
743 root_dir, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
744 &dmap, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
745 &dir, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
746 &old_results, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
747 &ignore_fn, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
748 &dir_ignore_fn, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
749 options, |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
750 )?); |
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
751 } |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
752 } |
44536
f8a9922a02cb
rust-status: move to recursive traversal to prepare for parallel traversal
Raphaël Gomès <rgomes@octobus.net>
parents:
44535
diff
changeset
|
753 _ => unreachable!("There can only be directories in `work`"), |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
754 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
755 } |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
756 } |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
757 |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
758 if !matcher.is_exact() { |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
759 // Step 3: Check the remaining files from the dmap. |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
760 // If a dmap file is not in results yet, it was either |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
761 // a) not matched b) ignored, c) missing, or d) under a |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
762 // symlink directory. |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
763 |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
764 if options.list_unknown { |
44537
5f6a504dc0bd
rust-status: refactor handling of unknown files
Raphaël Gomès <rgomes@octobus.net>
parents:
44536
diff
changeset
|
765 handle_unknowns(dmap, matcher, root_dir, options, &mut results)?; |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
766 } else { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
767 // We may not have walked the full directory tree above, so stat |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
768 // and check everything we missed. |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
769 let stat_results = stat_dmap_entries(&dmap, root_dir, options); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
770 results.par_extend(stat_results.flatten().map( |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
771 |(filename, dispatch)| (Cow::Borrowed(filename), dispatch), |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
772 )); |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
773 } |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
774 } |
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
775 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
776 Ok((build_response(results), warnings)) |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
777 } |