author | Raphaël Gomès <rgomes@octobus.net> |
Mon, 15 Jun 2020 18:26:40 +0200 | |
changeset 44973 | 26114bd6ec60 |
parent 44283 | 934a79697c36 |
child 45610 | 496537c9c1b4 |
permissions | -rw-r--r-- |
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. |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
11 |
use crate::{ |
44267
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
12 |
dirstate::EntryState, |
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 |
}, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
17 |
DirstateEntry, 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. |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
33 |
pub fn from_dirstate( |
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
34 |
dirstate: &FastHashMap<HgPathBuf, DirstateEntry>, |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
35 |
skip_state: Option<EntryState>, |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
36 |
) -> Result<Self, DirstateMapError> { |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
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
|
38 |
inner: FastHashMap::default(), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
|
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
41 |
for (filename, DirstateEntry { state, .. }) in dirstate { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
42 |
// This `if` is optimized out of the loop |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
43 |
if let Some(skip) = skip_state { |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
44 |
if skip != *state { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
45 |
multiset.add_path(filename)?; |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
} |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
47 |
} else { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
48 |
multiset.add_path(filename)?; |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
|
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
52 |
Ok(multiset) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
|
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
55 |
/// 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
|
56 |
pub fn from_manifest( |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
57 |
manifest: &[impl AsRef<HgPath>], |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
58 |
) -> Result<Self, DirstateMapError> { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
59 |
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
|
60 |
inner: FastHashMap::default(), |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
61 |
}; |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
62 |
|
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
63 |
for filename in manifest { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
64 |
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
|
65 |
} |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42750
diff
changeset
|
66 |
|
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
67 |
Ok(multiset) |
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 |
|
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
70 |
/// 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
|
71 |
/// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
/// 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
|
73 |
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
|
74 |
&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
|
75 |
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
|
76 |
) -> 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
|
77 |
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
|
78 |
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
|
79 |
// 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
|
80 |
// 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
|
81 |
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
|
82 |
|
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
83 |
return Err(DirstateMapError::InvalidPath( |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
84 |
HgPathError::ConsecutiveSlashes { |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
85 |
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
|
86 |
second_slash_index, |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
87 |
}, |
934a79697c36
rust-dirs-multiset: improve temporary error message
Raphaël Gomès <rgomes@octobus.net>
parents:
44267
diff
changeset
|
88 |
)); |
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
|
89 |
} |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 |
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
|
91 |
*val += 1; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 |
break; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 |
self.inner.insert(subpath.to_owned(), 1); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
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 |
Ok(()) |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 |
/// 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
|
100 |
/// |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 |
/// 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
|
102 |
/// removed. |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 |
/// 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
|
104 |
pub fn delete_path( |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
&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
|
106 |
path: impl AsRef<HgPath>, |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 |
) -> 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
|
108 |
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
|
109 |
match self.inner.entry(subpath.to_owned()) { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 |
Entry::Occupied(mut entry) => { |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
111 |
let val = *entry.get(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 |
if val > 1 { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 |
entry.insert(val - 1); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 |
break; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 |
entry.remove(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
)) |
42536
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 |
}; |
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 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 |
Ok(()) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
} |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
128 |
|
43831
088ba9d94079
rust-dirs-multiset: use `AsRef` instead of concrete types when possible
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
} |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
132 |
|
42885
a03a29462c0a
rust-dirstate: specify concrete return type of DirsMultiset::iter()
Yuya Nishihara <yuya@tcha.org>
parents:
42841
diff
changeset
|
133 |
pub fn iter(&self) -> DirsMultisetIter { |
42750
849e744b925d
rust-dirstate: improve API of `DirsMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
42749
diff
changeset
|
134 |
self.inner.keys() |
42559
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
135 |
} |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
136 |
|
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
137 |
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
|
138 |
self.inner.len() |
a80464e85ddd
rust: remove Deref in favor of explicit methods
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
139 |
} |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
140 |
|
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
141 |
pub fn is_empty(&self) -> bool { |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
142 |
self.len() == 0 |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
143 |
} |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
145 |
|
44267
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
146 |
/// 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
|
147 |
/// 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
|
148 |
/// 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
|
149 |
#[derive(PartialEq, Debug)] |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
150 |
pub struct DirsChildrenMultiset<'a> { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
151 |
inner: FastHashMap<&'a HgPath, HashSet<&'a HgPath>>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
152 |
only_include: Option<HashSet<&'a HgPath>>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
153 |
} |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
154 |
|
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
155 |
impl<'a> DirsChildrenMultiset<'a> { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
156 |
pub fn new( |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
157 |
paths: impl Iterator<Item = &'a HgPathBuf>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
158 |
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
|
159 |
) -> Self { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
160 |
let mut new = Self { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
161 |
inner: HashMap::default(), |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
162 |
only_include: only_include |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44283
diff
changeset
|
163 |
.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
|
164 |
}; |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
165 |
|
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
166 |
for path in paths { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
167 |
new.add_path(path) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
168 |
} |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
169 |
|
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
170 |
new |
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 |
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
|
173 |
if path.as_ref().is_empty() { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
174 |
return; |
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 |
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
|
177 |
{ |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
178 |
if !self.is_dir_included(directory) { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
179 |
continue; |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
180 |
} |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
181 |
self.inner |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
182 |
.entry(directory) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
183 |
.and_modify(|e| { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
184 |
e.insert(basename); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
185 |
}) |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
186 |
.or_insert_with(|| { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
187 |
let mut set = HashSet::new(); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
188 |
set.insert(basename); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
189 |
set |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
190 |
}); |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
191 |
} |
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 |
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
|
194 |
match &self.only_include { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
195 |
None => false, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
196 |
Some(i) => i.contains(dir.as_ref()), |
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 |
pub fn get( |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
201 |
&self, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
202 |
path: impl AsRef<HgPath>, |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
203 |
) -> Option<&HashSet<&'a HgPath>> { |
0e9ac3968b56
rust-dirs-multiset: add `DirsChildrenMultiset`
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
204 |
self.inner.get(path.as_ref()) |
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 |
|
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 |
#[cfg(test)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 |
mod tests { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 |
use super::*; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
212 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 |
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
|
214 |
let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
215 |
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
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
map.delete_path(&path) |
42536
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 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
222 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
224 |
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
|
225 |
let mut map = |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
226 |
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
|
227 |
let path = HgPath::new(b""); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 |
assert_eq!(Ok(()), map.delete_path(path)); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 |
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
|
230 |
Err(DirstateMapError::PathNotFound(path.to_owned())), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 |
map.delete_path(path) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 |
); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
234 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
235 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 |
fn test_delete_path_successful() { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 |
let mut map = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 |
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
|
239 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
240 |
.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
|
241 |
.collect(), |
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 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
244 |
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
|
245 |
eprintln!("{:?}", map); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
246 |
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
|
247 |
eprintln!("{:?}", map); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
))), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
252 |
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
|
253 |
); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
254 |
|
42957
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!(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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
eprintln!("{:?}", map); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
))), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
266 |
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
|
267 |
); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
269 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
270 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 |
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
|
272 |
let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
273 |
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
|
274 |
let path = HgPath::new(b""); |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
275 |
map.add_path(path).unwrap(); |
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 |
assert_eq!(1, map.len()); |
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 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
280 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 |
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
|
282 |
let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
283 |
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
|
284 |
|
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 |
// Non directory should be ignored |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
291 |
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
|
292 |
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
|
293 |
assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 |
// 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
|
296 |
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
|
297 |
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
|
298 |
assert_eq!(2, map.len()); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
300 |
// Duplicate path works |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
304 |
// 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
|
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!(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
|
307 |
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
|
308 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
309 |
// 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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
|
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/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
|
315 |
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
|
316 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 |
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
|
319 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
320 |
.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
|
321 |
.collect(), |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
323 |
assert_eq!(map, expected); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
324 |
} |
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 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 |
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
|
328 |
let manifest: Vec<HgPathBuf> = vec![]; |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
329 |
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
|
330 |
let expected = DirsMultiset { |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
331 |
inner: FastHashMap::default(), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
334 |
|
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
335 |
let new = DirsMultiset::from_dirstate(&FastHashMap::default(), None) |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
336 |
.unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 |
let expected = DirsMultiset { |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
338 |
inner: FastHashMap::default(), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 |
assert_eq!(expected, new); |
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 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
344 |
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
|
345 |
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
|
346 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
347 |
.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
|
348 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
349 |
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
|
350 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
351 |
.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
|
352 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
353 |
|
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
354 |
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
|
355 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
356 |
inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
357 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
358 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
359 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 |
let input_map = ["a/", "b/", "a/c", "a/d/"] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
361 |
.iter() |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 |
.map(|f| { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
364 |
HgPathBuf::from_bytes(f.as_bytes()), |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
365 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
366 |
state: EntryState::Normal, |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
367 |
mode: 0, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
368 |
mtime: 0, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
369 |
size: 0, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
370 |
}, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
371 |
) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
372 |
}) |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
374 |
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
|
375 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
376 |
.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
|
377 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
378 |
|
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
379 |
let new = DirsMultiset::from_dirstate(&input_map, None).unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
380 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 |
inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
383 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
385 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
386 |
#[test] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
387 |
fn test_dirsmultiset_new_skip() { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
388 |
let input_map = [ |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
389 |
("a/", EntryState::Normal), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
390 |
("a/b/", EntryState::Normal), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
391 |
("a/c", EntryState::Removed), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
392 |
("a/d/", EntryState::Merged), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
393 |
] |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
394 |
.iter() |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
395 |
.map(|(f, state)| { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
396 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
397 |
HgPathBuf::from_bytes(f.as_bytes()), |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
398 |
DirstateEntry { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
399 |
state: *state, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
400 |
mode: 0, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
401 |
mtime: 0, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
402 |
size: 0, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
403 |
}, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
404 |
) |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
405 |
}) |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
406 |
.collect(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
407 |
|
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 |
// "a" incremented with "a/c" and "a/d/" |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 |
let expected_inner = [("", 1), ("a", 2), ("a/d", 1)] |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42885
diff
changeset
|
411 |
.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
|
412 |
.collect(); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
413 |
|
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
414 |
let new = |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
415 |
DirsMultiset::from_dirstate(&input_map, Some(EntryState::Normal)) |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43831
diff
changeset
|
416 |
.unwrap(); |
42536
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 |
let expected = DirsMultiset { |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
418 |
inner: expected_inner, |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
419 |
}; |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
420 |
assert_eq!(expected, new); |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
421 |
} |
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
422 |
} |