Mercurial > hg
annotate rust/hg-core/src/dirstate/dirs_multiset.rs @ 49137:66e22a4d856b
rust: remove use of `EntryState` in `DirsMultiset`
Let's use the new API.
Differential Revision: https://phab.mercurial-scm.org/D12535
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 12 Apr 2022 17:27:56 +0200 |
parents | bf8837e3d7ce |
children | e98fd81bb151 |
rev | line source |
---|---|
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 // dirs_multiset.rs |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 // |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 // |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 //! A multiset of directory names. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 //! |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 //! Used to counts the references to directories in a manifest or dirstate. |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
11 use crate::dirstate_tree::on_disk::DirstateV2ParseError; |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
12 use crate::{ |
44267
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
13 utils::{ |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
14 files, |
44283
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
15 hg_path::{HgPath, HgPathBuf, HgPathError}, |
44267
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
16 }, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
17 DirstateEntry, DirstateError, DirstateMapError, FastHashMap, |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
18 }; |
44267
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
19 use std::collections::{hash_map, hash_map::Entry, HashMap, HashSet}; |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 |
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
21 // could be encapsulated if we care API stability more seriously |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
22 pub type DirsMultisetIter<'a> = hash_map::Keys<'a, HgPathBuf, u32>; |
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
23 |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 #[derive(PartialEq, Debug)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 pub struct DirsMultiset { |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
26 inner: FastHashMap<HgPathBuf, u32>, |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 impl DirsMultiset { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
30 /// Initializes the multiset from a dirstate. |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 /// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 /// If `skip_state` is provided, skips dirstate entries with equal state. |
47332
4ee9f419c52e
rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
33 pub fn from_dirstate<I, P>( |
47124
cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
34 dirstate: I, |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
35 only_tracked: bool, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
36 ) -> Result<Self, DirstateError> |
47124
cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
37 where |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
38 I: IntoIterator< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
39 Item = Result<(P, DirstateEntry), DirstateV2ParseError>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
40 >, |
47124
cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
41 P: AsRef<HgPath>, |
cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
42 { |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 let mut multiset = DirsMultiset { |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
44 inner: FastHashMap::default(), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 }; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
46 for item in dirstate { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
47 let (filename, entry) = item?; |
47124
cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
48 let filename = filename.as_ref(); |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
49 // This `if` is optimized out of the loop |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
50 if only_tracked { |
49137
66e22a4d856b
rust: remove use of `EntryState` in `DirsMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
48068
diff
changeset
|
51 if !entry.removed() { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
52 multiset.add_path(filename)?; |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 } |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
54 } else { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
55 multiset.add_path(filename)?; |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
59 Ok(multiset) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
62 /// Initializes the multiset from a manifest. |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
63 pub fn from_manifest( |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
64 manifest: &[impl AsRef<HgPath>], |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
65 ) -> Result<Self, DirstateMapError> { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
66 let mut multiset = DirsMultiset { |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
67 inner: FastHashMap::default(), |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
68 }; |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
69 |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
70 for filename in manifest { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
71 multiset.add_path(filename.as_ref())?; |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
72 } |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
73 |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
74 Ok(multiset) |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
75 } |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
76 |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 /// Increases the count of deepest directory contained in the path. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 /// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 /// If the directory is not yet in the map, adds its parents. |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
80 pub fn add_path( |
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
81 &mut self, |
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
82 path: impl AsRef<HgPath>, |
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
83 ) -> Result<(), DirstateMapError> { |
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
84 for subpath in files::find_dirs(path.as_ref()) { |
43788
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
85 if subpath.as_bytes().last() == Some(&b'/') { |
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
86 // TODO Remove this once PathAuditor is certified |
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
87 // as the only entrypoint for path data |
44283
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
88 let second_slash_index = subpath.len() - 1; |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
89 |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
90 return Err(DirstateMapError::InvalidPath( |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
91 HgPathError::ConsecutiveSlashes { |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
92 bytes: path.as_ref().as_bytes().to_owned(), |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
93 second_slash_index, |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
94 }, |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
95 )); |
43788
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
96 } |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 if let Some(val) = self.inner.get_mut(subpath) { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 *val += 1; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 break; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 self.inner.insert(subpath.to_owned(), 1); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 } |
43788
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
103 Ok(()) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
104 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 /// Decreases the count of deepest directory contained in the path. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 /// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 /// If it is the only reference, decreases all parents until one is |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 /// removed. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 /// If the directory is not in the map, something horrible has happened. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 pub fn delete_path( |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 &mut self, |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
113 path: impl AsRef<HgPath>, |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 ) -> Result<(), DirstateMapError> { |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
115 for subpath in files::find_dirs(path.as_ref()) { |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 match self.inner.entry(subpath.to_owned()) { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 Entry::Occupied(mut entry) => { |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
118 let val = *entry.get(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 if val > 1 { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 entry.insert(val - 1); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 break; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 entry.remove(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 Entry::Vacant(_) => { |
42557
d26e4a434fe5
rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents:
42536
diff
changeset
|
126 return Err(DirstateMapError::PathNotFound( |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
127 path.as_ref().to_owned(), |
42557
d26e4a434fe5
rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents:
42536
diff
changeset
|
128 )) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 Ok(()) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 } |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
135 |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
136 pub fn contains(&self, key: impl AsRef<HgPath>) -> bool { |
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
137 self.inner.contains_key(key.as_ref()) |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
138 } |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
139 |
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
140 pub fn iter(&self) -> DirsMultisetIter { |
42750
849e744b925d
rust-dirstate: improve API of `DirsMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
42749
diff
changeset
|
141 self.inner.keys() |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
142 } |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
143 |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
144 pub fn len(&self) -> usize { |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
145 self.inner.len() |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
146 } |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
147 |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
148 pub fn is_empty(&self) -> bool { |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
149 self.len() == 0 |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
150 } |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
151 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 |
44267
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
153 /// This is basically a reimplementation of `DirsMultiset` that stores the |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
154 /// children instead of just a count of them, plus a small optional |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
155 /// optimization to avoid some directories we don't need. |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
156 #[derive(PartialEq, Debug)] |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
157 pub struct DirsChildrenMultiset<'a> { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
158 inner: FastHashMap<&'a HgPath, HashSet<&'a HgPath>>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
159 only_include: Option<HashSet<&'a HgPath>>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
160 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
161 |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
162 impl<'a> DirsChildrenMultiset<'a> { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
163 pub fn new( |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
164 paths: impl Iterator<Item = &'a HgPathBuf>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
165 only_include: Option<&'a HashSet<impl AsRef<HgPath> + 'a>>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
166 ) -> Self { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
167 let mut new = Self { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
168 inner: HashMap::default(), |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
169 only_include: only_include |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
170 .map(|s| s.iter().map(AsRef::as_ref).collect()), |
44267
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
171 }; |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
172 |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
173 for path in paths { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
174 new.add_path(path) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
175 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
176 |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
177 new |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
178 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
179 fn add_path(&mut self, path: &'a (impl AsRef<HgPath> + 'a)) { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
180 if path.as_ref().is_empty() { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
181 return; |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
182 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
183 for (directory, basename) in files::find_dirs_with_base(path.as_ref()) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
184 { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
185 if !self.is_dir_included(directory) { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
186 continue; |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
187 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
188 self.inner |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
189 .entry(directory) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
190 .and_modify(|e| { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
191 e.insert(basename); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
192 }) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
193 .or_insert_with(|| { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
194 let mut set = HashSet::new(); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
195 set.insert(basename); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
196 set |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
197 }); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
198 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
199 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
200 fn is_dir_included(&self, dir: impl AsRef<HgPath>) -> bool { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
201 match &self.only_include { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
202 None => false, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
203 Some(i) => i.contains(dir.as_ref()), |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
204 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
205 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
206 |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
207 pub fn get( |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
208 &self, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
209 path: impl AsRef<HgPath>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
210 ) -> Option<&HashSet<&'a HgPath>> { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
211 self.inner.get(path.as_ref()) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
212 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
213 } |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
214 |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
215 #[cfg(test)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
216 mod tests { |
49137
66e22a4d856b
rust: remove use of `EntryState` in `DirsMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
48068
diff
changeset
|
217 use crate::EntryState; |
66e22a4d856b
rust: remove use of `EntryState` in `DirsMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
48068
diff
changeset
|
218 |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 use super::*; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
220 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
221 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
222 fn test_delete_path_path_not_found() { |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
223 let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
224 let mut map = DirsMultiset::from_manifest(&manifest).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
225 let path = HgPathBuf::from_bytes(b"doesnotexist/"); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
227 Err(DirstateMapError::PathNotFound(path.to_owned())), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
228 map.delete_path(&path) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 ); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
230 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 fn test_delete_path_empty_path() { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
234 let mut map = |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
235 DirsMultiset::from_manifest(&vec![HgPathBuf::new()]).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
236 let path = HgPath::new(b""); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 assert_eq!(Ok(()), map.delete_path(path)); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
239 Err(DirstateMapError::PathNotFound(path.to_owned())), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 map.delete_path(path) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 ); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 fn test_delete_path_successful() { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
246 let mut map = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 inner: [("", 5), ("a", 3), ("a/b", 2), ("a/c", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
249 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 .collect(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
253 assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/b/"))); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
254 eprintln!("{:?}", map); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
255 assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/b/"))); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
256 eprintln!("{:?}", map); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
258 Err(DirstateMapError::PathNotFound(HgPathBuf::from_bytes( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
259 b"a/b/" |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
260 ))), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
261 map.delete_path(HgPath::new(b"a/b/")) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
262 ); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
263 |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
264 assert_eq!(2, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
265 assert_eq!(1, *map.inner.get(HgPath::new(b"a/c")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
266 eprintln!("{:?}", map); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
267 assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/"))); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 eprintln!("{:?}", map); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
269 |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
270 assert_eq!(Ok(()), map.delete_path(HgPath::new(b"a/c/"))); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 assert_eq!( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
272 Err(DirstateMapError::PathNotFound(HgPathBuf::from_bytes( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
273 b"a/c/" |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
274 ))), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
275 map.delete_path(HgPath::new(b"a/c/")) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
276 ); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
278 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
279 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
280 fn test_add_path_empty_path() { |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
281 let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
282 let mut map = DirsMultiset::from_manifest(&manifest).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
283 let path = HgPath::new(b""); |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
284 map.add_path(path).unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
286 assert_eq!(1, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
287 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 fn test_add_path_successful() { |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
291 let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
292 let mut map = DirsMultiset::from_manifest(&manifest).unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
293 |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
294 map.add_path(HgPath::new(b"a/")).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
295 assert_eq!(1, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
296 assert_eq!(1, *map.inner.get(HgPath::new(b"")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 // Non directory should be ignored |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
300 map.add_path(HgPath::new(b"a")).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
301 assert_eq!(1, *map.inner.get(HgPath::new(b"a")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
303 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
304 // Non directory will still add its base |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
305 map.add_path(HgPath::new(b"a/b")).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
306 assert_eq!(2, *map.inner.get(HgPath::new(b"a")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
307 assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
309 // Duplicate path works |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
310 map.add_path(HgPath::new(b"a/")).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
311 assert_eq!(3, *map.inner.get(HgPath::new(b"a")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
312 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
313 // Nested dir adds to its base |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
314 map.add_path(HgPath::new(b"a/b/")).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
315 assert_eq!(4, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
316 assert_eq!(1, *map.inner.get(HgPath::new(b"a/b")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 // but not its base's base, because it already existed |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
319 map.add_path(HgPath::new(b"a/b/c/")).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
320 assert_eq!(4, *map.inner.get(HgPath::new(b"a")).unwrap()); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
321 assert_eq!(2, *map.inner.get(HgPath::new(b"a/b")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
323 map.add_path(HgPath::new(b"a/c/")).unwrap(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
324 assert_eq!(1, *map.inner.get(HgPath::new(b"a/c")).unwrap()); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
325 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
326 let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 inner: [("", 2), ("a", 5), ("a/b", 2), ("a/b/c", 1), ("a/c", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
328 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
329 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
330 .collect(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
331 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 assert_eq!(map, expected); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
334 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
335 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
336 fn test_dirsmultiset_new_empty() { |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
337 let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
338 let new = DirsMultiset::from_manifest(&manifest).unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 let expected = DirsMultiset { |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
340 inner: FastHashMap::default(), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
341 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 |
48068
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
344 let new = DirsMultiset::from_dirstate::<_, HgPathBuf>( |
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
345 std::iter::empty(), |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
346 false, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
347 ) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
348 .unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
349 let expected = DirsMultiset { |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
350 inner: FastHashMap::default(), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
351 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
352 assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
353 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
354 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
355 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
356 fn test_dirsmultiset_new_no_skip() { |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
357 let input_vec: Vec<HgPathBuf> = ["a/", "b/", "a/c", "a/d/"] |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
358 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
359 .map(|e| HgPathBuf::from_bytes(e.as_bytes())) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 .collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
361 let expected_inner = [("", 2), ("a", 3), ("b", 1), ("a/d", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
363 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
364 .collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
365 |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
366 let new = DirsMultiset::from_manifest(&input_vec).unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
367 let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
368 inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
369 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
370 assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
371 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
372 let input_map = ["b/x", "a/c", "a/d/x"].iter().map(|f| { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
373 Ok(( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
374 HgPathBuf::from_bytes(f.as_bytes()), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
375 DirstateEntry::from_v1_data(EntryState::Normal, 0, 0, 0), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
376 )) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
377 }); |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
378 let expected_inner = [("", 2), ("a", 2), ("b", 1), ("a/d", 1)] |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
380 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 .collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
383 let new = DirsMultiset::from_dirstate(input_map, false).unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
385 inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
386 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
387 assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
388 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
389 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
390 #[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 fn test_dirsmultiset_new_skip() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
392 let input_map = [ |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
393 ("a/", EntryState::Normal), |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
394 ("a/b", EntryState::Normal), |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
395 ("a/c", EntryState::Removed), |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
396 ("a/d", EntryState::Merged), |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
397 ] |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
398 .iter() |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
399 .map(|(f, state)| { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
400 Ok(( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
401 HgPathBuf::from_bytes(f.as_bytes()), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
402 DirstateEntry::from_v1_data(*state, 0, 0, 0), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
403 )) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
404 }); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
405 |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
406 // "a" incremented with "a/c" and "a/d/" |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
407 let expected_inner = [("", 1), ("a", 3)] |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
409 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 .collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
412 let new = DirsMultiset::from_dirstate(input_map, true).unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
413 let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
414 inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
415 }; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
416 assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 } |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
418 } |