Mercurial > hg
annotate rust/hg-core/src/dirstate/status.rs @ 48066:7a2de2bd9fcd
dirstate: inline the `from_p2_removed` logic
It is used internally for compatibilty with size used in the `v1` format, but
this is the only use. So we can simply inline it.
Differential Revision: https://phab.mercurial-scm.org/D11514
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 28 Sep 2021 19:29:44 +0200 |
parents | 1b2ee68e85f9 |
children | bf8837e3d7ce |
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 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47329
diff
changeset
|
12 use crate::dirstate_tree::on_disk::DirstateV2ParseError; |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
13 use crate::utils::path_auditor::PathAuditor; |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
14 use crate::{ |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
15 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
|
16 filepatterns::PatternFileWarning, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
17 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
|
18 utils::{ |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
19 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
|
20 hg_path::{ |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
21 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
|
22 HgPathError, |
44523
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
23 }, |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
24 }, |
44527
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
25 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
|
26 PatternError, |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43604
diff
changeset
|
27 }; |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
28 use lazy_static::lazy_static; |
44541
d880805d5442
hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents:
44539
diff
changeset
|
29 use micro_timer::timed; |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 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
|
31 use std::{ |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
32 borrow::Cow, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
33 collections::HashSet, |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
34 fmt, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
35 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
|
36 io::ErrorKind, |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
37 ops::Deref, |
44597
e62052d0f377
rust-status: only involve ignore mechanism when needed
Raphaël Gomès <rgomes@octobus.net>
parents:
44562
diff
changeset
|
38 path::{Path, PathBuf}, |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
39 }; |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
41 /// 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
|
42 /// 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
|
43 #[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
|
44 pub enum BadType { |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
45 CharacterDevice, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
46 BlockDevice, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
47 FIFO, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
48 Socket, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
49 Directory, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
50 Unknown, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
51 } |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
52 |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
53 impl fmt::Display for BadType { |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
54 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
55 f.write_str(match self { |
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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 BadType::Unknown => "unknown", |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
62 }) |
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
|
63 } |
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
|
64 } |
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
|
65 |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
66 /// 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
|
67 #[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
|
68 pub enum BadMatch { |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
69 OsError(i32), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
70 BadType(BadType), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
71 } |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
72 |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
73 /// Enum used to dispatch new status entries into the right collections. |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
74 /// 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
|
75 /// 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
|
76 #[derive(Debug, Copy, Clone)] |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
77 pub enum Dispatch { |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
78 Unsure, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
79 Modified, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
80 Added, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
81 Removed, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
82 Deleted, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
83 Clean, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
84 Unknown, |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
85 Ignored, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
86 /// 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
|
87 None, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
88 /// 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
|
89 Bad(BadMatch), |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
90 Directory { |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
91 /// 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
|
92 /// 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
|
93 was_file: bool, |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
94 }, |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
95 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
96 |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
97 type IoResult<T> = std::io::Result<T>; |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
98 |
47113
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
99 /// `Box<dyn Trait>` is syntactic sugar for `Box<dyn Trait + 'static>`, so add |
44597
e62052d0f377
rust-status: only involve ignore mechanism when needed
Raphaël Gomès <rgomes@octobus.net>
parents:
44562
diff
changeset
|
100 /// an explicit lifetime here to not fight `'static` bounds "out of nowhere". |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47111
diff
changeset
|
101 pub type IgnoreFnType<'a> = |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47111
diff
changeset
|
102 Box<dyn for<'r> Fn(&'r HgPath) -> bool + Sync + 'a>; |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
103 |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
104 /// We have a good mix of owned (from directory traversal) and borrowed (from |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
105 /// the dirstate/explicit) paths, this comes up a lot. |
45113
98817e5daca7
hg-core: define a `dirstate_status` `Operation`
Raphaël Gomès <rgomes@octobus.net>
parents:
45112
diff
changeset
|
106 pub type HgPathCow<'a> = Cow<'a, HgPath>; |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
107 |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
108 /// A path with its computed ``Dispatch`` information |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
109 type DispatchedPath<'a> = (HgPathCow<'a>, Dispatch); |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
110 |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
111 /// The conversion from `HgPath` to a real fs path failed. |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
112 /// `22` is the error code for "Invalid argument" |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
113 const INVALID_PATH_DISPATCH: Dispatch = Dispatch::Bad(BadMatch::OsError(22)); |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
114 |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
115 /// 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
|
116 /// 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
|
117 /// 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
|
118 /// changes. (issue2608) |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
119 /// 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
|
120 /// 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
|
121 /// 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
|
122 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
|
123 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
|
124 } |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
125 |
44523
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
126 /// 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
|
127 /// in the directory. |
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 /// * `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
|
130 fn list_directory( |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
131 path: impl AsRef<Path>, |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
132 skip_dot_hg: bool, |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
133 ) -> 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
|
134 let mut results = vec![]; |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
135 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
|
136 |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
137 for entry in entries { |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
138 let entry = entry?; |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 return Ok(vec![]); |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
143 } else { |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44926
diff
changeset
|
144 results.push((filename, entry)) |
44523
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
145 } |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
146 } |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
147 |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
148 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
|
149 Ok(results) |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
150 } |
0d97bcb3cee9
rust-status: add util for listing a directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44193
diff
changeset
|
151 |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
152 /// 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
|
153 fn dispatch_found( |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
154 filename: impl AsRef<HgPath>, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
155 entry: DirstateEntry, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
156 metadata: HgMetadata, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
157 copy_map: &CopyMap, |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
158 options: StatusOptions, |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
159 ) -> Dispatch { |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
160 match entry.state() { |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
161 EntryState::Normal => { |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
162 let mode = entry.mode(); |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
163 let size = entry.size(); |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
164 let mtime = entry.mtime(); |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
165 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
166 let HgMetadata { |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
167 st_mode, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
168 st_size, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
169 st_mtime, |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
170 .. |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
171 } = metadata; |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
172 |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
173 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
|
174 let mode_changed = |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
175 (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
|
176 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
|
177 let other_parent = size == SIZE_FROM_OTHER_PARENT; |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44926
diff
changeset
|
178 |
43604
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
179 if metadata_changed |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
180 || other_parent |
51cd86735608
rust-status: refactor dispatch case for normal files
Raphaël Gomès <rgomes@octobus.net>
parents:
43603
diff
changeset
|
181 || 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
|
182 { |
46757
3c9ddb1986a9
rust-status: fix issue6456 for the Rust implementation also
Raphaël Gomès <rgomes@octobus.net>
parents:
46494
diff
changeset
|
183 if metadata.is_symlink() && size_changed { |
3c9ddb1986a9
rust-status: fix issue6456 for the Rust implementation also
Raphaël Gomès <rgomes@octobus.net>
parents:
46494
diff
changeset
|
184 // issue6456: Size returned may be longer due to encryption |
3c9ddb1986a9
rust-status: fix issue6456 for the Rust implementation also
Raphaël Gomès <rgomes@octobus.net>
parents:
46494
diff
changeset
|
185 // on EXT-4 fscrypt. TODO maybe only do it on EXT4? |
3c9ddb1986a9
rust-status: fix issue6456 for the Rust implementation also
Raphaël Gomès <rgomes@octobus.net>
parents:
46494
diff
changeset
|
186 Dispatch::Unsure |
3c9ddb1986a9
rust-status: fix issue6456 for the Rust implementation also
Raphaël Gomès <rgomes@octobus.net>
parents:
46494
diff
changeset
|
187 } else { |
3c9ddb1986a9
rust-status: fix issue6456 for the Rust implementation also
Raphaël Gomès <rgomes@octobus.net>
parents:
46494
diff
changeset
|
188 Dispatch::Modified |
3c9ddb1986a9
rust-status: fix issue6456 for the Rust implementation also
Raphaël Gomès <rgomes@octobus.net>
parents:
46494
diff
changeset
|
189 } |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44926
diff
changeset
|
190 } else if mod_compare(mtime, st_mtime as i32) |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44926
diff
changeset
|
191 || st_mtime == options.last_normal_time |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44926
diff
changeset
|
192 { |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
193 // 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
|
194 // 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
|
195 // 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
|
196 // 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
|
197 // miss such a racy file change. |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
198 Dispatch::Unsure |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
199 } else if options.list_clean { |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
200 Dispatch::Clean |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
201 } else { |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
202 Dispatch::None |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
203 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
204 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
205 EntryState::Merged => Dispatch::Modified, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
206 EntryState::Added => Dispatch::Added, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
207 EntryState::Removed => Dispatch::Removed, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
208 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
209 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
210 |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
211 /// 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
|
212 fn dispatch_missing(state: EntryState) -> Dispatch { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
213 match state { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
214 // 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
|
215 EntryState::Normal | EntryState::Merged | EntryState::Added => { |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
216 Dispatch::Deleted |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
217 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
218 // File was removed, everything is normal |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
219 EntryState::Removed => Dispatch::Removed, |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
220 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
221 } |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
222 |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
223 fn dispatch_os_error(e: &std::io::Error) -> Dispatch { |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
224 Dispatch::Bad(BadMatch::OsError( |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
225 e.raw_os_error().expect("expected real OS error"), |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
226 )) |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
227 } |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
228 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
229 lazy_static! { |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 h |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
234 }; |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
235 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
236 |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
237 #[derive(Debug, Copy, Clone)] |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
238 pub struct StatusOptions { |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
239 /// 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
|
240 /// 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
|
241 /// 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
|
242 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
|
243 /// 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
|
244 pub check_exec: bool, |
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
245 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
|
246 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
|
247 pub list_ignored: bool, |
44838
c802ec4f7196
rust-status: collect traversed directories if required
Raphaël Gomès <rgomes@octobus.net>
parents:
44837
diff
changeset
|
248 /// Whether to collect traversed dirs for applying a callback later. |
c802ec4f7196
rust-status: collect traversed directories if required
Raphaël Gomès <rgomes@octobus.net>
parents:
44837
diff
changeset
|
249 /// Used by `hg purge` for example. |
c802ec4f7196
rust-status: collect traversed directories if required
Raphaël Gomès <rgomes@octobus.net>
parents:
44837
diff
changeset
|
250 pub collect_traversed_dirs: 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
|
251 } |
1debb5894b39
rust-status: add function for sequential traversal of the working directory
Raphaël Gomès <rgomes@octobus.net>
parents:
44526
diff
changeset
|
252 |
47113
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
253 #[derive(Debug, Default)] |
44525
f13d19549efd
rust-status: rename `StatusResult` to `DirstateStatus`
Raphaël Gomès <rgomes@octobus.net>
parents:
44524
diff
changeset
|
254 pub struct DirstateStatus<'a> { |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
255 /// Tracked files whose contents have changed since the parent revision |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
256 pub modified: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
257 |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
258 /// Newly-tracked files that were not present in the parent |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
259 pub added: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
260 |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
261 /// Previously-tracked files that have been (re)moved with an hg command |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
262 pub removed: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
263 |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
264 /// (Still) tracked files that are missing, (re)moved with an non-hg |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
265 /// command |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
266 pub deleted: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
267 |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
268 /// Tracked files that are up to date with the parent. |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
269 /// Only pupulated if `StatusOptions::list_clean` is true. |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
270 pub clean: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
271 |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
272 /// Files in the working directory that are ignored with `.hgignore`. |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
273 /// Only pupulated if `StatusOptions::list_ignored` is true. |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
274 pub ignored: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
275 |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
276 /// Files in the working directory that are neither tracked nor ignored. |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
277 /// Only pupulated if `StatusOptions::list_unknown` is true. |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
278 pub unknown: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
279 |
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
280 /// Was explicitly matched but cannot be found/accessed |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
281 pub bad: Vec<(HgPathCow<'a>, BadMatch)>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
282 |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
283 /// Either clean or modified, but we can’t tell from filesystem metadata |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
284 /// alone. The file contents need to be read and compared with that in |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
285 /// the parent. |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
286 pub unsure: Vec<HgPathCow<'a>>, |
47111
623c8e4ddc6d
rust: Add doc-comments to DirstateStatus fields
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
287 |
44838
c802ec4f7196
rust-status: collect traversed directories if required
Raphaël Gomès <rgomes@octobus.net>
parents:
44837
diff
changeset
|
288 /// Only filled if `collect_traversed_dirs` is `true` |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
289 pub traversed: Vec<HgPathCow<'a>>, |
47350
04d1f17f49e7
dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
290 |
04d1f17f49e7
dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
291 /// Whether `status()` made changed to the `DirstateMap` that should be |
04d1f17f49e7
dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
292 /// written back to disk |
04d1f17f49e7
dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
293 pub dirty: bool, |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 |
46435
2e2033081274
rust: replace trivial `impl From …` with `#[derive(derive_more::From)]`
Simon Sapin <simon.sapin@octobus.net>
parents:
46054
diff
changeset
|
296 #[derive(Debug, derive_more::From)] |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
297 pub enum StatusError { |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
298 /// Generic IO error |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
299 IO(std::io::Error), |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
300 /// An invalid path that cannot be represented in Mercurial was found |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
301 Path(HgPathError), |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
302 /// An invalid "ignore" pattern was found |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
303 Pattern(PatternError), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47329
diff
changeset
|
304 /// Corrupted dirstate |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47329
diff
changeset
|
305 DirstateV2ParseError(DirstateV2ParseError), |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
306 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
307 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
308 pub type StatusResult<T> = Result<T, StatusError>; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
309 |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
310 impl fmt::Display for StatusError { |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
311 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
312 match self { |
46444
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
313 StatusError::IO(error) => error.fmt(f), |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
314 StatusError::Path(error) => error.fmt(f), |
6c778d20c8c2
rust: replace ToString impls with Display
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
315 StatusError::Pattern(error) => error.fmt(f), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47329
diff
changeset
|
316 StatusError::DirstateV2ParseError(_) => { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47329
diff
changeset
|
317 f.write_str("dirstate-v2 parse error") |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47329
diff
changeset
|
318 } |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
319 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
320 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
321 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
322 |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
323 /// Gives information about which files are changed in the working directory |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
324 /// and how, compared to the revision we're based on |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
325 pub struct Status<'a, M: ?Sized + Matcher + Sync> { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
326 dmap: &'a DirstateMap, |
45113
98817e5daca7
hg-core: define a `dirstate_status` `Operation`
Raphaël Gomès <rgomes@octobus.net>
parents:
45112
diff
changeset
|
327 pub(crate) matcher: &'a M, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
328 root_dir: PathBuf, |
45113
98817e5daca7
hg-core: define a `dirstate_status` `Operation`
Raphaël Gomès <rgomes@octobus.net>
parents:
45112
diff
changeset
|
329 pub(crate) options: StatusOptions, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
330 ignore_fn: IgnoreFnType<'a>, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
331 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
332 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
333 impl<'a, M> Status<'a, M> |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
334 where |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
335 M: ?Sized + Matcher + Sync, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
336 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
337 pub fn new( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
338 dmap: &'a DirstateMap, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
339 matcher: &'a M, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
340 root_dir: PathBuf, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
341 ignore_files: Vec<PathBuf>, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
342 options: StatusOptions, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
343 ) -> StatusResult<(Self, Vec<PatternFileWarning>)> { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
344 // Needs to outlive `dir_ignore_fn` since it's captured. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
345 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
346 let (ignore_fn, warnings): (IgnoreFnType, _) = |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
347 if options.list_ignored || options.list_unknown { |
47409
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47350
diff
changeset
|
348 get_ignore_function(ignore_files, &root_dir, &mut |_| {})? |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
349 } else { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
350 (Box::new(|&_| true), vec![]) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
351 }; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
352 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
353 Ok(( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
354 Self { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
355 dmap, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
356 matcher, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
357 root_dir, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
358 options, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
359 ignore_fn, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
360 }, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
361 warnings, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
362 )) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
363 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
364 |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
365 /// Is the path ignored? |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
366 pub fn is_ignored(&self, path: impl AsRef<HgPath>) -> bool { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
367 (self.ignore_fn)(path.as_ref()) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
368 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
369 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
370 /// Is the path or one of its ancestors ignored? |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
371 pub fn dir_ignore(&self, dir: impl AsRef<HgPath>) -> bool { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
372 // Only involve ignore mechanism if we're listing unknowns or ignored. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
373 if self.options.list_ignored || self.options.list_unknown { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
374 if self.is_ignored(&dir) { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
375 true |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
376 } else { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
377 for p in find_dirs(dir.as_ref()) { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
378 if self.is_ignored(p) { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
379 return true; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
380 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
381 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
382 false |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
383 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
384 } else { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
385 true |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
386 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
387 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
388 |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
389 /// Get stat data about the files explicitly specified by the matcher. |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
390 /// Returns a tuple of the directories that need to be traversed and the |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
391 /// files with their corresponding `Dispatch`. |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
392 /// TODO subrepos |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
393 #[timed] |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
394 pub fn walk_explicit( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
395 &self, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
396 traversed_sender: crossbeam_channel::Sender<HgPathBuf>, |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
397 ) -> (Vec<DispatchedPath<'a>>, Vec<DispatchedPath<'a>>) { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
398 self.matcher |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
399 .file_set() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
400 .unwrap_or(&DEFAULT_WORK) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
401 .par_iter() |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
402 .flat_map(|&filename| -> Option<_> { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
403 // TODO normalization |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
404 let normalized = filename; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
405 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
406 let buf = match hg_path_to_path_buf(normalized) { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
407 Ok(x) => x, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
408 Err(_) => { |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
409 return Some(( |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
410 Cow::Borrowed(normalized), |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
411 INVALID_PATH_DISPATCH, |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
412 )) |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
413 } |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
414 }; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
415 let target = self.root_dir.join(buf); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
416 let st = target.symlink_metadata(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
417 let in_dmap = self.dmap.get(normalized); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
418 match st { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
419 Ok(meta) => { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
420 let file_type = meta.file_type(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
421 return if file_type.is_file() || file_type.is_symlink() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
422 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
423 if let Some(entry) = in_dmap { |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
424 return Some(( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
425 Cow::Borrowed(normalized), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
426 dispatch_found( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
427 &normalized, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
428 *entry, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
429 HgMetadata::from_metadata(meta), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
430 &self.dmap.copy_map, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
431 self.options, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
432 ), |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
433 )); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
434 } |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
435 Some(( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
436 Cow::Borrowed(normalized), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
437 Dispatch::Unknown, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
438 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
439 } else if file_type.is_dir() { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
440 if self.options.collect_traversed_dirs { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
441 traversed_sender |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
442 .send(normalized.to_owned()) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
443 .expect("receiver should outlive sender"); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
444 } |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
445 Some(( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
446 Cow::Borrowed(normalized), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
447 Dispatch::Directory { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
448 was_file: in_dmap.is_some(), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
449 }, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
450 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
451 } else { |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
452 Some(( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
453 Cow::Borrowed(normalized), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
454 Dispatch::Bad(BadMatch::BadType( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
455 // TODO do more than unknown |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
456 // Support for all `BadType` variant |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
457 // varies greatly between platforms. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
458 // So far, no tests check the type and |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
459 // this should be good enough for most |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
460 // users. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
461 BadType::Unknown, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
462 )), |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
463 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
464 }; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
465 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
466 Err(_) => { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
467 if let Some(entry) = in_dmap { |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
468 return Some(( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
469 Cow::Borrowed(normalized), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
470 dispatch_missing(entry.state()), |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
471 )); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
472 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
473 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
474 }; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
475 None |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
476 }) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
477 .partition(|(_, dispatch)| match dispatch { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
478 Dispatch::Directory { .. } => true, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
479 _ => false, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
480 }) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
481 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
482 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
483 /// Walk the working directory recursively to look for changes compared to |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
484 /// the current `DirstateMap`. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
485 /// |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
486 /// This takes a mutable reference to the results to account for the |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
487 /// `extend` in timings |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
488 #[timed] |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
489 pub fn traverse( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
490 &self, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
491 path: impl AsRef<HgPath>, |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
492 old_results: &FastHashMap<HgPathCow<'a>, Dispatch>, |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
493 results: &mut Vec<DispatchedPath<'a>>, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
494 traversed_sender: crossbeam_channel::Sender<HgPathBuf>, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
495 ) { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
496 // The traversal is done in parallel, so use a channel to gather |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
497 // entries. `crossbeam_channel::Sender` is `Sync`, while `mpsc::Sender` |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
498 // is not. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
499 let (files_transmitter, files_receiver) = |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
500 crossbeam_channel::unbounded(); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
501 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
502 self.traverse_dir( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
503 &files_transmitter, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
504 path, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
505 &old_results, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
506 traversed_sender, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
507 ); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
508 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
509 // Disconnect the channel so the receiver stops waiting |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
510 drop(files_transmitter); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
511 |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
512 let new_results = files_receiver |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
513 .into_iter() |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
514 .par_bridge() |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
515 .map(|(f, d)| (Cow::Owned(f), d)); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
516 |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
517 results.par_extend(new_results); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
518 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
519 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
520 /// Dispatch a single entry (file, folder, symlink...) found during |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
521 /// `traverse`. If the entry is a folder that needs to be traversed, it |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
522 /// will be handled in a separate thread. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
523 fn handle_traversed_entry<'b>( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
524 &'a self, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
525 scope: &rayon::Scope<'b>, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
526 files_sender: &'b crossbeam_channel::Sender<(HgPathBuf, Dispatch)>, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
527 old_results: &'a FastHashMap<Cow<HgPath>, Dispatch>, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
528 filename: HgPathBuf, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
529 dir_entry: DirEntry, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
530 traversed_sender: crossbeam_channel::Sender<HgPathBuf>, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
531 ) -> IoResult<()> |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
532 where |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
533 'a: 'b, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
534 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
535 let file_type = dir_entry.file_type()?; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
536 let entry_option = self.dmap.get(&filename); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
537 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
538 if filename.as_bytes() == b".hg" { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
539 // Could be a directory or a symlink |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
540 return Ok(()); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
541 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
542 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
543 if file_type.is_dir() { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
544 self.handle_traversed_dir( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
545 scope, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
546 files_sender, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
547 old_results, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
548 entry_option, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
549 filename, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
550 traversed_sender, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
551 ); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
552 } else if file_type.is_file() || file_type.is_symlink() { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
553 if let Some(entry) = entry_option { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
554 if self.matcher.matches_everything() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
555 || self.matcher.matches(&filename) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
556 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
557 let metadata = dir_entry.metadata()?; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
558 files_sender |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
559 .send(( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
560 filename.to_owned(), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
561 dispatch_found( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
562 &filename, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
563 *entry, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
564 HgMetadata::from_metadata(metadata), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
565 &self.dmap.copy_map, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
566 self.options, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
567 ), |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
568 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
569 .unwrap(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
570 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
571 } else if (self.matcher.matches_everything() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
572 || self.matcher.matches(&filename)) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
573 && !self.is_ignored(&filename) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
574 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
575 if (self.options.list_ignored |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
576 || self.matcher.exact_match(&filename)) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
577 && self.dir_ignore(&filename) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
578 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
579 if self.options.list_ignored { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
580 files_sender |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
581 .send((filename.to_owned(), Dispatch::Ignored)) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
582 .unwrap(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
583 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
584 } else if self.options.list_unknown { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
585 files_sender |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
586 .send((filename.to_owned(), Dispatch::Unknown)) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
587 .unwrap(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
588 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
589 } else if self.is_ignored(&filename) && self.options.list_ignored { |
47317
c8f62920f07a
rust-status: fix ignore and include not composing (issue6514)
Raphaël Gomès <rgomes@octobus.net>
parents:
46890
diff
changeset
|
590 if self.matcher.matches(&filename) { |
c8f62920f07a
rust-status: fix ignore and include not composing (issue6514)
Raphaël Gomès <rgomes@octobus.net>
parents:
46890
diff
changeset
|
591 files_sender |
c8f62920f07a
rust-status: fix ignore and include not composing (issue6514)
Raphaël Gomès <rgomes@octobus.net>
parents:
46890
diff
changeset
|
592 .send((filename.to_owned(), Dispatch::Ignored)) |
c8f62920f07a
rust-status: fix ignore and include not composing (issue6514)
Raphaël Gomès <rgomes@octobus.net>
parents:
46890
diff
changeset
|
593 .unwrap(); |
c8f62920f07a
rust-status: fix ignore and include not composing (issue6514)
Raphaël Gomès <rgomes@octobus.net>
parents:
46890
diff
changeset
|
594 } |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
595 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
596 } else if let Some(entry) = entry_option { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
597 // Used to be a file or a folder, now something else. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
598 if self.matcher.matches_everything() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
599 || self.matcher.matches(&filename) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
600 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
601 files_sender |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
602 .send(( |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
603 filename.to_owned(), |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
604 dispatch_missing(entry.state()), |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
605 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
606 .unwrap(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
607 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
608 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
609 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
610 Ok(()) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
611 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
612 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
613 /// A directory was found in the filesystem and needs to be traversed |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
614 fn handle_traversed_dir<'b>( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
615 &'a self, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
616 scope: &rayon::Scope<'b>, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
617 files_sender: &'b crossbeam_channel::Sender<(HgPathBuf, Dispatch)>, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
618 old_results: &'a FastHashMap<Cow<HgPath>, Dispatch>, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
619 entry_option: Option<&'a DirstateEntry>, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
620 directory: HgPathBuf, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
621 traversed_sender: crossbeam_channel::Sender<HgPathBuf>, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
622 ) where |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
623 'a: 'b, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
624 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
625 scope.spawn(move |_| { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
626 // Nested `if` until `rust-lang/rust#53668` is stable |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
627 if let Some(entry) = entry_option { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
628 // Used to be a file, is now a folder |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
629 if self.matcher.matches_everything() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
630 || self.matcher.matches(&directory) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
631 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
632 files_sender |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
633 .send(( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
634 directory.to_owned(), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
635 dispatch_missing(entry.state()), |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
636 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
637 .unwrap(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
638 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
639 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
640 // Do we need to traverse it? |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
641 if !self.is_ignored(&directory) || self.options.list_ignored { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
642 self.traverse_dir( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
643 files_sender, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
644 directory, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
645 &old_results, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
646 traversed_sender, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
647 ) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
648 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
649 }); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
650 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
651 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
652 /// Decides whether the directory needs to be listed, and if so handles the |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
653 /// entries in a separate thread. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
654 fn traverse_dir( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
655 &self, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
656 files_sender: &crossbeam_channel::Sender<(HgPathBuf, Dispatch)>, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
657 directory: impl AsRef<HgPath>, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
658 old_results: &FastHashMap<Cow<HgPath>, Dispatch>, |
46054
fd47483f1645
rust: use crossbeam-channel crate directly
Simon Sapin <simon-commits@exyr.org>
parents:
45862
diff
changeset
|
659 traversed_sender: crossbeam_channel::Sender<HgPathBuf>, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
660 ) { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
661 let directory = directory.as_ref(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
662 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
663 if self.options.collect_traversed_dirs { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
664 traversed_sender |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
665 .send(directory.to_owned()) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
666 .expect("receiver should outlive sender"); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
667 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
668 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
669 let visit_entries = match self.matcher.visit_children_set(directory) { |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
670 VisitChildrenSet::Empty => return, |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
671 VisitChildrenSet::This | VisitChildrenSet::Recursive => None, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
672 VisitChildrenSet::Set(set) => Some(set), |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
673 }; |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
674 let buf = match hg_path_to_path_buf(directory) { |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
675 Ok(b) => b, |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
676 Err(_) => { |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
677 files_sender |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
678 .send((directory.to_owned(), INVALID_PATH_DISPATCH)) |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
679 .expect("receiver should outlive sender"); |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
680 return; |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
681 } |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
682 }; |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
683 let dir_path = self.root_dir.join(buf); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
684 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
685 let skip_dot_hg = !directory.as_bytes().is_empty(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
686 let entries = match list_directory(dir_path, skip_dot_hg) { |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
687 Err(e) => { |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
688 files_sender |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
689 .send((directory.to_owned(), dispatch_os_error(&e))) |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
690 .expect("receiver should outlive sender"); |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
691 return; |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
692 } |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
693 Ok(entries) => entries, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
694 }; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
695 |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
696 rayon::scope(|scope| { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
697 for (filename, dir_entry) in entries { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
698 if let Some(ref set) = visit_entries { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
699 if !set.contains(filename.deref()) { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
700 continue; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
701 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
702 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
703 // TODO normalize |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
704 let filename = if directory.is_empty() { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
705 filename.to_owned() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
706 } else { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
707 directory.join(&filename) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
708 }; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
709 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
710 if !old_results.contains_key(filename.deref()) { |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
711 match self.handle_traversed_entry( |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
712 scope, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
713 files_sender, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
714 old_results, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
715 filename, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
716 dir_entry, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
717 traversed_sender.clone(), |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
718 ) { |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
719 Err(e) => { |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
720 files_sender |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
721 .send(( |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
722 directory.to_owned(), |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
723 dispatch_os_error(&e), |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
724 )) |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
725 .expect("receiver should outlive sender"); |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
726 } |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
727 Ok(_) => {} |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
728 } |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
729 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
730 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
731 }) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
732 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
733 |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
734 /// Add the files in the dirstate to the results. |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
735 /// |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
736 /// This takes a mutable reference to the results to account for the |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
737 /// `extend` in timings |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
738 #[timed] |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
739 pub fn extend_from_dmap(&self, results: &mut Vec<DispatchedPath<'a>>) { |
46489
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
740 results.par_extend( |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
741 self.dmap |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
742 .par_iter() |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
743 .filter(|(path, _)| self.matcher.matches(path)) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
744 .map(move |(filename, entry)| { |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
745 let filename: &HgPath = filename; |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
746 let filename_as_path = match hg_path_to_path_buf(filename) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
747 { |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
748 Ok(f) => f, |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
749 Err(_) => { |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
750 return ( |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
751 Cow::Borrowed(filename), |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
752 INVALID_PATH_DISPATCH, |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
753 ) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
754 } |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
755 }; |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
756 let meta = self |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
757 .root_dir |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
758 .join(filename_as_path) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
759 .symlink_metadata(); |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
760 match meta { |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
761 Ok(m) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
762 if !(m.file_type().is_file() |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
763 || m.file_type().is_symlink()) => |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
764 { |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
765 ( |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
766 Cow::Borrowed(filename), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
767 dispatch_missing(entry.state()), |
46489
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
768 ) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
769 } |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
770 Ok(m) => ( |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
771 Cow::Borrowed(filename), |
46489
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
772 dispatch_found( |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
773 filename, |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
774 *entry, |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
775 HgMetadata::from_metadata(m), |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
776 &self.dmap.copy_map, |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
777 self.options, |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
778 ), |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
779 ), |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
780 Err(e) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
781 if e.kind() == ErrorKind::NotFound |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
782 || e.raw_os_error() == Some(20) => |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
783 { |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
784 // Rust does not yet have an `ErrorKind` for |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
785 // `NotADirectory` (errno 20) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
786 // It happens if the dirstate contains `foo/bar` |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
787 // and foo is not a |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
788 // directory |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
789 ( |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
790 Cow::Borrowed(filename), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
791 dispatch_missing(entry.state()), |
46489
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
792 ) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
793 } |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
794 Err(e) => { |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
795 (Cow::Borrowed(filename), dispatch_os_error(&e)) |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
796 } |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
797 } |
46489
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
798 }), |
fb6eca7b8c63
rust-status: honor matcher when using the dirstate-only fast-path (issue6483)
Raphaël Gomès <rgomes@octobus.net>
parents:
46054
diff
changeset
|
799 ); |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
800 } |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45358
diff
changeset
|
801 |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
802 /// Checks all files that are in the dirstate but were not found during the |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
803 /// working directory traversal. This means that the rest must |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
804 /// be either ignored, under a symlink or under a new nested repo. |
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
805 /// |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
806 /// This takes a mutable reference to the results to account for the |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
807 /// `extend` in timings |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
808 #[timed] |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
809 pub fn handle_unknowns(&self, results: &mut Vec<DispatchedPath<'a>>) { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
810 let to_visit: Vec<(&HgPath, &DirstateEntry)> = |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
811 if results.is_empty() && self.matcher.matches_everything() { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
812 self.dmap.iter().map(|(f, e)| (f.deref(), e)).collect() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
813 } else { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
814 // Only convert to a hashmap if needed. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
815 let old_results: FastHashMap<_, _> = |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
816 results.iter().cloned().collect(); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
817 self.dmap |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
818 .iter() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
819 .filter_map(move |(f, e)| { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
820 if !old_results.contains_key(f.deref()) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
821 && self.matcher.matches(f) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
822 { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
823 Some((f.deref(), e)) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
824 } else { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
825 None |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
826 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
827 }) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
828 .collect() |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
829 }; |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
830 |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
831 let path_auditor = PathAuditor::new(&self.root_dir); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
832 |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
833 let new_results = to_visit.into_par_iter().filter_map( |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
834 |(filename, entry)| -> Option<_> { |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
835 // Report ignored items in the dmap as long as they are not |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
836 // under a symlink directory. |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
837 if path_auditor.check(filename) { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
838 // TODO normalize for case-insensitive filesystems |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
839 let buf = match hg_path_to_path_buf(filename) { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
840 Ok(x) => x, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
841 Err(_) => { |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
842 return Some(( |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
843 Cow::Owned(filename.to_owned()), |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
844 INVALID_PATH_DISPATCH, |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
845 )); |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
846 } |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
847 }; |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
848 Some(( |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
849 Cow::Owned(filename.to_owned()), |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
850 match self.root_dir.join(&buf).symlink_metadata() { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
851 // File was just ignored, no links, and exists |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
852 Ok(meta) => { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
853 let metadata = HgMetadata::from_metadata(meta); |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
854 dispatch_found( |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
855 filename, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
856 *entry, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
857 metadata, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
858 &self.dmap.copy_map, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
859 self.options, |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
860 ) |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
861 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
862 // File doesn't exist |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
863 Err(_) => dispatch_missing(entry.state()), |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
864 }, |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
865 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
866 } else { |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
867 // It's either missing or under a symlink directory which |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
868 // we, in this case, report as missing. |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
869 Some(( |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
870 Cow::Owned(filename.to_owned()), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
871 dispatch_missing(entry.state()), |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
872 )) |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
873 } |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
874 }, |
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
875 ); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
876 |
45862
5c736ba5dc27
rust-status: don't bubble up os errors, translate them to bad matches
Raphaël Gomès <rgomes@octobus.net>
parents:
45615
diff
changeset
|
877 results.par_extend(new_results); |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
878 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
879 } |
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
880 |
44541
d880805d5442
hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents:
44539
diff
changeset
|
881 #[timed] |
45113
98817e5daca7
hg-core: define a `dirstate_status` `Operation`
Raphaël Gomès <rgomes@octobus.net>
parents:
45112
diff
changeset
|
882 pub fn build_response<'a>( |
45112
470d306e616c
rust-status: improve documentation and readability
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
883 results: impl IntoIterator<Item = DispatchedPath<'a>>, |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
884 traversed: Vec<HgPathCow<'a>>, |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
885 ) -> DirstateStatus<'a> { |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
886 let mut unsure = vec![]; |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
887 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
|
888 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
|
889 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
|
890 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
|
891 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
|
892 let mut ignored = vec![]; |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
893 let mut unknown = vec![]; |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
894 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
|
895 |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
896 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
|
897 match dispatch { |
44526
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
898 Dispatch::Unknown => unknown.push(filename), |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
899 Dispatch::Unsure => unsure.push(filename), |
43602
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
900 Dispatch::Modified => modified.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
901 Dispatch::Added => added.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
902 Dispatch::Removed => removed.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
903 Dispatch::Deleted => deleted.push(filename), |
889ac87e8bfd
rust-status: improve status performance
Raphaël Gomès <rgomes@octobus.net>
parents:
43456
diff
changeset
|
904 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
|
905 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
|
906 Dispatch::None => {} |
61709b844420
rust-status: add missing variants to `Dispatch` enum
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
907 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
|
908 Dispatch::Directory { .. } => {} |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
909 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
910 } |
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
911 |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
912 DirstateStatus { |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
913 modified, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
914 added, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
915 removed, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
916 deleted, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
917 clean, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
918 ignored, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
919 unknown, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
920 bad, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
921 unsure, |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
922 traversed, |
47350
04d1f17f49e7
dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
923 dirty: false, |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
924 } |
44528
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
925 } |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
926 |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
927 /// 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
|
928 /// |
c8891bca40fb
rust-status: add bare `hg status` support in hg-core
Raphaël Gomès <rgomes@octobus.net>
parents:
44527
diff
changeset
|
929 /// 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
|
930 /// 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
|
931 /// information that will not be necessary in the future. |
44541
d880805d5442
hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents:
44539
diff
changeset
|
932 #[timed] |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
933 pub fn status<'a>( |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
934 dmap: &'a DirstateMap, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
935 matcher: &'a (dyn Matcher + Sync), |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
936 root_dir: PathBuf, |
44597
e62052d0f377
rust-status: only involve ignore mechanism when needed
Raphaël Gomès <rgomes@octobus.net>
parents:
44562
diff
changeset
|
937 ignore_files: Vec<PathBuf>, |
44524
483fce658e43
rust-status: refactor options into a `StatusOptions` struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44523
diff
changeset
|
938 options: StatusOptions, |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
939 ) -> StatusResult<(DirstateStatus<'a>, Vec<PatternFileWarning>)> { |
45113
98817e5daca7
hg-core: define a `dirstate_status` `Operation`
Raphaël Gomès <rgomes@octobus.net>
parents:
45112
diff
changeset
|
940 let (status, warnings) = |
45111
7528699c6ccb
rust-status: refactor status into a struct
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
941 Status::new(dmap, matcher, root_dir, ignore_files, options)?; |
44838
c802ec4f7196
rust-status: collect traversed directories if required
Raphaël Gomès <rgomes@octobus.net>
parents:
44837
diff
changeset
|
942 |
45113
98817e5daca7
hg-core: define a `dirstate_status` `Operation`
Raphaël Gomès <rgomes@octobus.net>
parents:
45112
diff
changeset
|
943 Ok((status.run()?, warnings)) |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
944 } |