author | Raphaël Gomès <rgomes@octobus.net> |
Thu, 16 Jun 2022 15:20:48 +0200 | |
changeset 49431 | 79b2c98ab7b4 |
parent 49200 | 10b9f11daf15 |
parent 48893 | 6cd249556e20 |
child 49372 | f8ec7b16c98f |
permissions | -rw-r--r-- |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1 |
use bytes_cast::BytesCast; |
47132
c92e63762573
dirstate-tree: Add #[timed] attribute to `status` and `DirstateMap::read`
Simon Sapin <simon.sapin@octobus.net>
parents:
47130
diff
changeset
|
2 |
use micro_timer::timed; |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
3 |
use std::borrow::Cow; |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
4 |
use std::path::PathBuf; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
5 |
|
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
6 |
use super::on_disk; |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
7 |
use super::on_disk::DirstateV2ParseError; |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
8 |
use super::owning::OwningDirstateMap; |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
9 |
use super::path_with_basename::WithBasename; |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
10 |
use crate::dirstate::parsers::pack_entry; |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
11 |
use crate::dirstate::parsers::packed_entry_size; |
47112
d7631d55da3e
dirstate-tree: Add parsing only dirstate parents from disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47111
diff
changeset
|
12 |
use crate::dirstate::parsers::parse_dirstate_entries; |
48083
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
13 |
use crate::dirstate::CopyMapIter; |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
14 |
use crate::dirstate::DirstateV2Data; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
15 |
use crate::dirstate::ParentFileData; |
48083
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
16 |
use crate::dirstate::StateMapIter; |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
17 |
use crate::dirstate::TruncatedTimestamp; |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
18 |
use crate::matchers::Matcher; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
19 |
use crate::utils::hg_path::{HgPath, HgPathBuf}; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
20 |
use crate::DirstateEntry; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
21 |
use crate::DirstateError; |
49159
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
22 |
use crate::DirstateMapError; |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
23 |
use crate::DirstateParents; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
24 |
use crate::DirstateStatus; |
49041
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48493
diff
changeset
|
25 |
use crate::FastHashbrownMap as FastHashMap; |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
26 |
use crate::PatternFileWarning; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
27 |
use crate::StatusError; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
28 |
use crate::StatusOptions; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
29 |
|
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
30 |
/// Append to an existing data file if the amount of unreachable data (not used |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
31 |
/// anymore) is less than this fraction of the total amount of existing data. |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
32 |
const ACCEPTABLE_UNREACHABLE_BYTES_RATIO: f32 = 0.5; |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
33 |
|
48893
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
34 |
#[derive(Debug, PartialEq, Eq)] |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
35 |
/// Version of the on-disk format |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
36 |
pub enum DirstateVersion { |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
37 |
V1, |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
38 |
V2, |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
39 |
} |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
40 |
|
49180
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49179
diff
changeset
|
41 |
#[derive(Debug)] |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
42 |
pub struct DirstateMap<'on_disk> { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
43 |
/// Contents of the `.hg/dirstate` file |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
44 |
pub(super) on_disk: &'on_disk [u8], |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
45 |
|
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
46 |
pub(super) root: ChildNodes<'on_disk>, |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
47 |
|
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
48 |
/// Number of nodes anywhere in the tree that have `.entry.is_some()`. |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
49 |
pub(super) nodes_with_entry_count: u32, |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
50 |
|
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
51 |
/// Number of nodes anywhere in the tree that have |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
52 |
/// `.copy_source.is_some()`. |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
53 |
pub(super) nodes_with_copy_source_count: u32, |
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
54 |
|
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
55 |
/// See on_disk::Header |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
56 |
pub(super) ignore_patterns_hash: on_disk::IgnorePatternsHash, |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
57 |
|
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
58 |
/// How many bytes of `on_disk` are not used anymore |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
59 |
pub(super) unreachable_bytes: u32, |
48843
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
60 |
|
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
61 |
/// Size of the data used to first load this `DirstateMap`. Used in case |
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
62 |
/// we need to write some new metadata, but no new data on disk. |
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
63 |
pub(super) old_data_size: usize, |
48893
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
64 |
|
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
65 |
pub(super) dirstate_version: DirstateVersion, |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
66 |
} |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
67 |
|
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
68 |
/// Using a plain `HgPathBuf` of the full path from the repository root as a |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
69 |
/// map key would also work: all paths in a given map have the same parent |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
70 |
/// path, so comparing full paths gives the same result as comparing base |
47293
ce41ee53263f
dirstate-tree: Extract into a method sorting children of a given node
Simon Sapin <simon.sapin@octobus.net>
parents:
47291
diff
changeset
|
71 |
/// names. However `HashMap` would waste time always re-hashing the same |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
72 |
/// string prefix. |
47293
ce41ee53263f
dirstate-tree: Extract into a method sorting children of a given node
Simon Sapin <simon.sapin@octobus.net>
parents:
47291
diff
changeset
|
73 |
pub(super) type NodeKey<'on_disk> = WithBasename<Cow<'on_disk, HgPath>>; |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
74 |
|
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
75 |
/// Similar to `&'tree Cow<'on_disk, HgPath>`, but can also be returned |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
76 |
/// for on-disk nodes that don’t actually have a `Cow` to borrow. |
49180
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49179
diff
changeset
|
77 |
#[derive(Debug)] |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
78 |
pub(super) enum BorrowedPath<'tree, 'on_disk> { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
79 |
InMemory(&'tree HgPathBuf), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
80 |
OnDisk(&'on_disk HgPath), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
81 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
82 |
|
49180
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49179
diff
changeset
|
83 |
#[derive(Debug)] |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
84 |
pub(super) enum ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
85 |
InMemory(FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
86 |
OnDisk(&'on_disk [on_disk::Node]), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
87 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
88 |
|
49180
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49179
diff
changeset
|
89 |
#[derive(Debug)] |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
90 |
pub(super) enum ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
91 |
InMemory(&'tree FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
92 |
OnDisk(&'on_disk [on_disk::Node]), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
93 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
94 |
|
49180
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49179
diff
changeset
|
95 |
#[derive(Debug)] |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
96 |
pub(super) enum NodeRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
97 |
InMemory(&'tree NodeKey<'on_disk>, &'tree Node<'on_disk>), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
98 |
OnDisk(&'on_disk on_disk::Node), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
99 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
100 |
|
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
101 |
impl<'tree, 'on_disk> BorrowedPath<'tree, 'on_disk> { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
102 |
pub fn detach_from_tree(&self) -> Cow<'on_disk, HgPath> { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
103 |
match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
104 |
BorrowedPath::InMemory(in_memory) => Cow::Owned(in_memory.clone()), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
105 |
BorrowedPath::OnDisk(on_disk) => Cow::Borrowed(on_disk), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
106 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
107 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
108 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
109 |
|
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
110 |
impl<'tree, 'on_disk> std::ops::Deref for BorrowedPath<'tree, 'on_disk> { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
111 |
type Target = HgPath; |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
112 |
|
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
113 |
fn deref(&self) -> &HgPath { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
114 |
match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
115 |
BorrowedPath::InMemory(in_memory) => in_memory, |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
116 |
BorrowedPath::OnDisk(on_disk) => on_disk, |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
117 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
118 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
119 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
120 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
121 |
impl Default for ChildNodes<'_> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
122 |
fn default() -> Self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
123 |
ChildNodes::InMemory(Default::default()) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
124 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
125 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
126 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
127 |
impl<'on_disk> ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
128 |
pub(super) fn as_ref<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
129 |
&'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
130 |
) -> ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
131 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
132 |
ChildNodes::InMemory(nodes) => ChildNodesRef::InMemory(nodes), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
133 |
ChildNodes::OnDisk(nodes) => ChildNodesRef::OnDisk(nodes), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
134 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
135 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
136 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
137 |
pub(super) fn is_empty(&self) -> bool { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
138 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
139 |
ChildNodes::InMemory(nodes) => nodes.is_empty(), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
140 |
ChildNodes::OnDisk(nodes) => nodes.is_empty(), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
141 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
142 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
143 |
|
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
144 |
fn make_mut( |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
145 |
&mut self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
146 |
on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
147 |
unreachable_bytes: &mut u32, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
148 |
) -> Result< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
149 |
&mut FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
150 |
DirstateV2ParseError, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
151 |
> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
152 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
153 |
ChildNodes::InMemory(nodes) => Ok(nodes), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
154 |
ChildNodes::OnDisk(nodes) => { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
155 |
*unreachable_bytes += |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
156 |
std::mem::size_of_val::<[on_disk::Node]>(nodes) as u32; |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
157 |
let nodes = nodes |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
158 |
.iter() |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
159 |
.map(|node| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
160 |
Ok(( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
161 |
node.path(on_disk)?, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
162 |
node.to_in_memory_node(on_disk)?, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
163 |
)) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
164 |
}) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
165 |
.collect::<Result<_, _>>()?; |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
166 |
*self = ChildNodes::InMemory(nodes); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
167 |
match self { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
168 |
ChildNodes::InMemory(nodes) => Ok(nodes), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
169 |
ChildNodes::OnDisk(_) => unreachable!(), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
170 |
} |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
171 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
172 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
173 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
174 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
175 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
176 |
impl<'tree, 'on_disk> ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
177 |
pub(super) fn get( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
178 |
&self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
179 |
base_name: &HgPath, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
180 |
on_disk: &'on_disk [u8], |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
181 |
) -> Result<Option<NodeRef<'tree, 'on_disk>>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
182 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
183 |
ChildNodesRef::InMemory(nodes) => Ok(nodes |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
184 |
.get_key_value(base_name) |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
185 |
.map(|(k, v)| NodeRef::InMemory(k, v))), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
186 |
ChildNodesRef::OnDisk(nodes) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
187 |
let mut parse_result = Ok(()); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
188 |
let search_result = nodes.binary_search_by(|node| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
189 |
match node.base_name(on_disk) { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
190 |
Ok(node_base_name) => node_base_name.cmp(base_name), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
191 |
Err(e) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
192 |
parse_result = Err(e); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
193 |
// Dummy comparison result, `search_result` won’t |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
194 |
// be used since `parse_result` is an error |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
195 |
std::cmp::Ordering::Equal |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
196 |
} |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
197 |
} |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
198 |
}); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
199 |
parse_result.map(|()| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
200 |
search_result.ok().map(|i| NodeRef::OnDisk(&nodes[i])) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
201 |
}) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
202 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
203 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
204 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
205 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
206 |
/// Iterate in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
207 |
pub(super) fn iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
208 |
&self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
209 |
) -> impl Iterator<Item = NodeRef<'tree, 'on_disk>> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
210 |
match self { |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
211 |
ChildNodesRef::InMemory(nodes) => itertools::Either::Left( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
212 |
nodes.iter().map(|(k, v)| NodeRef::InMemory(k, v)), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
213 |
), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
214 |
ChildNodesRef::OnDisk(nodes) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
215 |
itertools::Either::Right(nodes.iter().map(NodeRef::OnDisk)) |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
216 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
217 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
218 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
219 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
220 |
/// Iterate in parallel in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
221 |
pub(super) fn par_iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
222 |
&self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
223 |
) -> impl rayon::iter::ParallelIterator<Item = NodeRef<'tree, 'on_disk>> |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
224 |
{ |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
225 |
use rayon::prelude::*; |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
226 |
match self { |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
227 |
ChildNodesRef::InMemory(nodes) => rayon::iter::Either::Left( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
228 |
nodes.par_iter().map(|(k, v)| NodeRef::InMemory(k, v)), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
229 |
), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
230 |
ChildNodesRef::OnDisk(nodes) => rayon::iter::Either::Right( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
231 |
nodes.par_iter().map(NodeRef::OnDisk), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
232 |
), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
233 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
234 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
235 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
236 |
pub(super) fn sorted(&self) -> Vec<NodeRef<'tree, 'on_disk>> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
237 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
238 |
ChildNodesRef::InMemory(nodes) => { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
239 |
let mut vec: Vec<_> = nodes |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
240 |
.iter() |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
241 |
.map(|(k, v)| NodeRef::InMemory(k, v)) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
242 |
.collect(); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
243 |
fn sort_key<'a>(node: &'a NodeRef) -> &'a HgPath { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
244 |
match node { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
245 |
NodeRef::InMemory(path, _node) => path.base_name(), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
246 |
NodeRef::OnDisk(_) => unreachable!(), |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
247 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
248 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
249 |
// `sort_unstable_by_key` doesn’t allow keys borrowing from the |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
250 |
// value: https://github.com/rust-lang/rust/issues/34162 |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
251 |
vec.sort_unstable_by(|a, b| sort_key(a).cmp(sort_key(b))); |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
252 |
vec |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
253 |
} |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
254 |
ChildNodesRef::OnDisk(nodes) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
255 |
// Nodes on disk are already sorted |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
256 |
nodes.iter().map(NodeRef::OnDisk).collect() |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
257 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
258 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
259 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
260 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
261 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
262 |
impl<'tree, 'on_disk> NodeRef<'tree, 'on_disk> { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
263 |
pub(super) fn full_path( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
264 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
265 |
on_disk: &'on_disk [u8], |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
266 |
) -> Result<&'tree HgPath, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
267 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
268 |
NodeRef::InMemory(path, _node) => Ok(path.full_path()), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
269 |
NodeRef::OnDisk(node) => node.full_path(on_disk), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
270 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
271 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
272 |
|
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
273 |
/// Returns a `BorrowedPath`, which can be turned into a `Cow<'on_disk, |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
274 |
/// HgPath>` detached from `'tree` |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
275 |
pub(super) fn full_path_borrowed( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
276 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
277 |
on_disk: &'on_disk [u8], |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
278 |
) -> Result<BorrowedPath<'tree, 'on_disk>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
279 |
match self { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
280 |
NodeRef::InMemory(path, _node) => match path.full_path() { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
281 |
Cow::Borrowed(on_disk) => Ok(BorrowedPath::OnDisk(on_disk)), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
282 |
Cow::Owned(in_memory) => Ok(BorrowedPath::InMemory(in_memory)), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
283 |
}, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
284 |
NodeRef::OnDisk(node) => { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
285 |
Ok(BorrowedPath::OnDisk(node.full_path(on_disk)?)) |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
286 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
287 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
288 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
289 |
|
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
290 |
pub(super) fn base_name( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
291 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
292 |
on_disk: &'on_disk [u8], |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
293 |
) -> Result<&'tree HgPath, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
294 |
match self { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
295 |
NodeRef::InMemory(path, _node) => Ok(path.base_name()), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
296 |
NodeRef::OnDisk(node) => node.base_name(on_disk), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
297 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
298 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
299 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
300 |
pub(super) fn children( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
301 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
302 |
on_disk: &'on_disk [u8], |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
303 |
) -> Result<ChildNodesRef<'tree, 'on_disk>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
304 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
305 |
NodeRef::InMemory(_path, node) => Ok(node.children.as_ref()), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
306 |
NodeRef::OnDisk(node) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
307 |
Ok(ChildNodesRef::OnDisk(node.children(on_disk)?)) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
308 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
309 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
310 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
311 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
312 |
pub(super) fn has_copy_source(&self) -> bool { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
313 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
314 |
NodeRef::InMemory(_path, node) => node.copy_source.is_some(), |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
315 |
NodeRef::OnDisk(node) => node.has_copy_source(), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
316 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
317 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
318 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
319 |
pub(super) fn copy_source( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
320 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
321 |
on_disk: &'on_disk [u8], |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
322 |
) -> Result<Option<&'tree HgPath>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
323 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
324 |
NodeRef::InMemory(_path, node) => { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
325 |
Ok(node.copy_source.as_ref().map(|s| &**s)) |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
326 |
} |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
327 |
NodeRef::OnDisk(node) => node.copy_source(on_disk), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
328 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
329 |
} |
48493
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
330 |
/// Returns a `BorrowedPath`, which can be turned into a `Cow<'on_disk, |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
331 |
/// HgPath>` detached from `'tree` |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
332 |
pub(super) fn copy_source_borrowed( |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
333 |
&self, |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
334 |
on_disk: &'on_disk [u8], |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
335 |
) -> Result<Option<BorrowedPath<'tree, 'on_disk>>, DirstateV2ParseError> |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
336 |
{ |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
337 |
Ok(match self { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
338 |
NodeRef::InMemory(_path, node) => { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
339 |
node.copy_source.as_ref().map(|source| match source { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
340 |
Cow::Borrowed(on_disk) => BorrowedPath::OnDisk(on_disk), |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
341 |
Cow::Owned(in_memory) => BorrowedPath::InMemory(in_memory), |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
342 |
}) |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
343 |
} |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
344 |
NodeRef::OnDisk(node) => node |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
345 |
.copy_source(on_disk)? |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
346 |
.map(|source| BorrowedPath::OnDisk(source)), |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
347 |
}) |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
348 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
349 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
350 |
pub(super) fn entry( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
351 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
352 |
) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
353 |
match self { |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
354 |
NodeRef::InMemory(_path, node) => { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
355 |
Ok(node.data.as_entry().copied()) |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
356 |
} |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
357 |
NodeRef::OnDisk(node) => node.entry(), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
358 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
359 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
360 |
|
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
361 |
pub(super) fn cached_directory_mtime( |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
362 |
&self, |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
363 |
) -> Result<Option<TruncatedTimestamp>, DirstateV2ParseError> { |
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
364 |
match self { |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
365 |
NodeRef::InMemory(_path, node) => Ok(match node.data { |
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
366 |
NodeData::CachedDirectory { mtime } => Some(mtime), |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
367 |
_ => None, |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
368 |
}), |
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
369 |
NodeRef::OnDisk(node) => node.cached_directory_mtime(), |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
370 |
} |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
371 |
} |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
372 |
|
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
373 |
pub(super) fn descendants_with_entry_count(&self) -> u32 { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
374 |
match self { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
375 |
NodeRef::InMemory(_path, node) => { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
376 |
node.descendants_with_entry_count |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
377 |
} |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
378 |
NodeRef::OnDisk(node) => node.descendants_with_entry_count.get(), |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
379 |
} |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
380 |
} |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
381 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
382 |
pub(super) fn tracked_descendants_count(&self) -> u32 { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
383 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
384 |
NodeRef::InMemory(_path, node) => node.tracked_descendants_count, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
385 |
NodeRef::OnDisk(node) => node.tracked_descendants_count.get(), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
386 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
387 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
388 |
} |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
389 |
|
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
390 |
/// Represents a file or a directory |
49180
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49179
diff
changeset
|
391 |
#[derive(Default, Debug)] |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
392 |
pub(super) struct Node<'on_disk> { |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
393 |
pub(super) data: NodeData, |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
394 |
|
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
395 |
pub(super) copy_source: Option<Cow<'on_disk, HgPath>>, |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
396 |
|
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
397 |
pub(super) children: ChildNodes<'on_disk>, |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
398 |
|
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
399 |
/// How many (non-inclusive) descendants of this node have an entry. |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
400 |
pub(super) descendants_with_entry_count: u32, |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
401 |
|
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
402 |
/// How many (non-inclusive) descendants of this node have an entry whose |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
403 |
/// state is "tracked". |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
404 |
pub(super) tracked_descendants_count: u32, |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
405 |
} |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
406 |
|
49180
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49179
diff
changeset
|
407 |
#[derive(Debug)] |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
408 |
pub(super) enum NodeData { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
409 |
Entry(DirstateEntry), |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
410 |
CachedDirectory { mtime: TruncatedTimestamp }, |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
411 |
None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
412 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
413 |
|
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
414 |
impl Default for NodeData { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
415 |
fn default() -> Self { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
416 |
NodeData::None |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
417 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
418 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
419 |
|
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
420 |
impl NodeData { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
421 |
fn has_entry(&self) -> bool { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
422 |
match self { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
423 |
NodeData::Entry(_) => true, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
424 |
_ => false, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
425 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
426 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
427 |
|
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
428 |
fn as_entry(&self) -> Option<&DirstateEntry> { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
429 |
match self { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
430 |
NodeData::Entry(entry) => Some(entry), |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
431 |
_ => None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
432 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
433 |
} |
49161
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
434 |
|
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
435 |
fn as_entry_mut(&mut self) -> Option<&mut DirstateEntry> { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
436 |
match self { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
437 |
NodeData::Entry(entry) => Some(entry), |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
438 |
_ => None, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
439 |
} |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
440 |
} |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
441 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
442 |
|
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
443 |
impl<'on_disk> DirstateMap<'on_disk> { |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
444 |
pub(super) fn empty(on_disk: &'on_disk [u8]) -> Self { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
445 |
Self { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
446 |
on_disk, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
447 |
root: ChildNodes::default(), |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
448 |
nodes_with_entry_count: 0, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
449 |
nodes_with_copy_source_count: 0, |
47415
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
450 |
ignore_patterns_hash: [0; on_disk::IGNORE_PATTERNS_HASH_LEN], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
451 |
unreachable_bytes: 0, |
48843
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
452 |
old_data_size: 0, |
48893
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
48843
diff
changeset
|
453 |
dirstate_version: DirstateVersion::V1, |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
454 |
} |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
455 |
} |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
456 |
|
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
457 |
#[timed] |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
458 |
pub fn new_v2( |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
459 |
on_disk: &'on_disk [u8], |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
460 |
data_size: usize, |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
461 |
metadata: &[u8], |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
462 |
) -> Result<Self, DirstateError> { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
463 |
if let Some(data) = on_disk.get(..data_size) { |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
464 |
Ok(on_disk::read(data, metadata)?) |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
465 |
} else { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
466 |
Err(DirstateV2ParseError.into()) |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
467 |
} |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
468 |
} |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
469 |
|
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
470 |
#[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
471 |
pub fn new_v1( |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
472 |
on_disk: &'on_disk [u8], |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
473 |
) -> Result<(Self, Option<DirstateParents>), DirstateError> { |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
474 |
let mut map = Self::empty(on_disk); |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
475 |
if map.on_disk.is_empty() { |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
476 |
return Ok((map, None)); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
477 |
} |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
478 |
|
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
479 |
let parents = parse_dirstate_entries( |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
480 |
map.on_disk, |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
481 |
|path, entry, copy_source| { |
49191
3f5e207f78be
rust: use `entry.tracked()` directly
Raphaël Gomès <rgomes@octobus.net>
parents:
49189
diff
changeset
|
482 |
let tracked = entry.tracked(); |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
483 |
let node = Self::get_or_insert_node_inner( |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
484 |
map.on_disk, |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
485 |
&mut map.unreachable_bytes, |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
486 |
&mut map.root, |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
487 |
path, |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
488 |
WithBasename::to_cow_borrowed, |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
489 |
|ancestor| { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
490 |
if tracked { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
491 |
ancestor.tracked_descendants_count += 1 |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
492 |
} |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
493 |
ancestor.descendants_with_entry_count += 1 |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
494 |
}, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
495 |
)?; |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
496 |
assert!( |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
497 |
!node.data.has_entry(), |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
498 |
"duplicate dirstate entry in read" |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
499 |
); |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
500 |
assert!( |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
501 |
node.copy_source.is_none(), |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
502 |
"duplicate dirstate entry in read" |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
503 |
); |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
504 |
node.data = NodeData::Entry(*entry); |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
505 |
node.copy_source = copy_source.map(Cow::Borrowed); |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
506 |
map.nodes_with_entry_count += 1; |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
507 |
if copy_source.is_some() { |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
508 |
map.nodes_with_copy_source_count += 1 |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
509 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
510 |
Ok(()) |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
511 |
}, |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
512 |
)?; |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
513 |
let parents = Some(parents.clone()); |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
514 |
|
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
515 |
Ok((map, parents)) |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
516 |
} |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
517 |
|
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
518 |
/// Assuming dirstate-v2 format, returns whether the next write should |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
519 |
/// append to the existing data file that contains `self.on_disk` (true), |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
520 |
/// or create a new data file from scratch (false). |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
521 |
pub(super) fn write_should_append(&self) -> bool { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
522 |
let ratio = self.unreachable_bytes as f32 / self.on_disk.len() as f32; |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
523 |
ratio < ACCEPTABLE_UNREACHABLE_BYTES_RATIO |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
524 |
} |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
525 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
526 |
fn get_node<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
527 |
&'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
528 |
path: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
529 |
) -> Result<Option<NodeRef<'tree, 'on_disk>>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
530 |
let mut children = self.root.as_ref(); |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
531 |
let mut components = path.components(); |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
532 |
let mut component = |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
533 |
components.next().expect("expected at least one components"); |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
534 |
loop { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
535 |
if let Some(child) = children.get(component, self.on_disk)? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
536 |
if let Some(next_component) = components.next() { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
537 |
component = next_component; |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
538 |
children = child.children(self.on_disk)?; |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
539 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
540 |
return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
541 |
} |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
542 |
} else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
543 |
return Ok(None); |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
544 |
} |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
545 |
} |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
546 |
} |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
547 |
|
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
548 |
/// Returns a mutable reference to the node at `path` if it exists |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
549 |
/// |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
550 |
/// `each_ancestor` is a callback that is called for each ancestor node |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
551 |
/// when descending the tree. It is used to keep the different counters |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
552 |
/// of the `DirstateMap` up-to-date. |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
553 |
fn get_node_mut<'tree>( |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
554 |
&'tree mut self, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
555 |
path: &HgPath, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
556 |
each_ancestor: impl FnMut(&mut Node), |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
557 |
) -> Result<Option<&'tree mut Node<'on_disk>>, DirstateV2ParseError> { |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
558 |
Self::get_node_mut_inner( |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
559 |
self.on_disk, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
560 |
&mut self.unreachable_bytes, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
561 |
&mut self.root, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
562 |
path, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
563 |
each_ancestor, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
564 |
) |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
565 |
} |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
566 |
|
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
567 |
/// Lower-level version of `get_node_mut`. |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
568 |
/// |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
569 |
/// This takes `root` instead of `&mut self` so that callers can mutate |
49186
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
570 |
/// other fields while the returned borrow is still valid. |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
571 |
/// |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
572 |
/// `each_ancestor` is a callback that is called for each ancestor node |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
573 |
/// when descending the tree. It is used to keep the different counters |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
574 |
/// of the `DirstateMap` up-to-date. |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
575 |
fn get_node_mut_inner<'tree>( |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
576 |
on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
577 |
unreachable_bytes: &mut u32, |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
578 |
root: &'tree mut ChildNodes<'on_disk>, |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
579 |
path: &HgPath, |
49186
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
580 |
mut each_ancestor: impl FnMut(&mut Node), |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
581 |
) -> Result<Option<&'tree mut Node<'on_disk>>, DirstateV2ParseError> { |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
582 |
let mut children = root; |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
583 |
let mut components = path.components(); |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
584 |
let mut component = |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
585 |
components.next().expect("expected at least one components"); |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
586 |
loop { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
587 |
if let Some(child) = children |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
588 |
.make_mut(on_disk, unreachable_bytes)? |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
589 |
.get_mut(component) |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
590 |
{ |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
591 |
if let Some(next_component) = components.next() { |
49186
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
592 |
each_ancestor(child); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
593 |
component = next_component; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
594 |
children = &mut child.children; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
595 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
596 |
return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
597 |
} |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
598 |
} else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
599 |
return Ok(None); |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
600 |
} |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
601 |
} |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
602 |
} |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
603 |
|
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
604 |
/// Get a mutable reference to the node at `path`, creating it if it does |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
605 |
/// not exist. |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
606 |
/// |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
607 |
/// `each_ancestor` is a callback that is called for each ancestor node |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
608 |
/// when descending the tree. It is used to keep the different counters |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
609 |
/// of the `DirstateMap` up-to-date. |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
610 |
fn get_or_insert_node<'tree, 'path>( |
47479
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
611 |
&'tree mut self, |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
612 |
path: &'path HgPath, |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
613 |
each_ancestor: impl FnMut(&mut Node), |
47479
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
614 |
) -> Result<&'tree mut Node<'on_disk>, DirstateV2ParseError> { |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
615 |
Self::get_or_insert_node_inner( |
47479
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
616 |
self.on_disk, |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
617 |
&mut self.unreachable_bytes, |
47479
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
618 |
&mut self.root, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
619 |
path, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
620 |
WithBasename::to_cow_owned, |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
621 |
each_ancestor, |
47479
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
622 |
) |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
623 |
} |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
624 |
|
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
625 |
/// Lower-level version of `get_or_insert_node_inner`, which is used when |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
626 |
/// parsing disk data to remove allocations for new nodes. |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
627 |
fn get_or_insert_node_inner<'tree, 'path>( |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
628 |
on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
629 |
unreachable_bytes: &mut u32, |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
630 |
root: &'tree mut ChildNodes<'on_disk>, |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
631 |
path: &'path HgPath, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
632 |
to_cow: impl Fn( |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
633 |
WithBasename<&'path HgPath>, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
634 |
) -> WithBasename<Cow<'on_disk, HgPath>>, |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
635 |
mut each_ancestor: impl FnMut(&mut Node), |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
636 |
) -> Result<&'tree mut Node<'on_disk>, DirstateV2ParseError> { |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
637 |
let mut child_nodes = root; |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
638 |
let mut inclusive_ancestor_paths = |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
639 |
WithBasename::inclusive_ancestors_of(path); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
640 |
let mut ancestor_path = inclusive_ancestor_paths |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
641 |
.next() |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
642 |
.expect("expected at least one inclusive ancestor"); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
643 |
loop { |
49041
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48493
diff
changeset
|
644 |
let (_, child_node) = child_nodes |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
645 |
.make_mut(on_disk, unreachable_bytes)? |
49041
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48493
diff
changeset
|
646 |
.raw_entry_mut() |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48493
diff
changeset
|
647 |
.from_key(ancestor_path.base_name()) |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48493
diff
changeset
|
648 |
.or_insert_with(|| (to_cow(ancestor_path), Node::default())); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
649 |
if let Some(next) = inclusive_ancestor_paths.next() { |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
650 |
each_ancestor(child_node); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
651 |
ancestor_path = next; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
652 |
child_nodes = &mut child_node.children; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
653 |
} else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
654 |
return Ok(child_node); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
655 |
} |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
656 |
} |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
657 |
} |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
658 |
|
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
659 |
fn reset_state( |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
660 |
&mut self, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
661 |
filename: &HgPath, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
662 |
old_entry_opt: Option<DirstateEntry>, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
663 |
wc_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
664 |
p1_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
665 |
p2_info: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
666 |
has_meaningful_mtime: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
667 |
parent_file_data_opt: Option<ParentFileData>, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
668 |
) -> Result<(), DirstateError> { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
669 |
let (had_entry, was_tracked) = match old_entry_opt { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
670 |
Some(old_entry) => (true, old_entry.tracked()), |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
671 |
None => (false, false), |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
672 |
}; |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
673 |
let node = self.get_or_insert_node(filename, |ancestor| { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
674 |
if !had_entry { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
675 |
ancestor.descendants_with_entry_count += 1; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
676 |
} |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
677 |
if was_tracked { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
678 |
if !wc_tracked { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
679 |
ancestor.tracked_descendants_count = ancestor |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
680 |
.tracked_descendants_count |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
681 |
.checked_sub(1) |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
682 |
.expect("tracked count to be >= 0"); |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
683 |
} |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
684 |
} else { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
685 |
if wc_tracked { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
686 |
ancestor.tracked_descendants_count += 1; |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
687 |
} |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
688 |
} |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
689 |
})?; |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
690 |
|
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
691 |
let v2_data = if let Some(parent_file_data) = parent_file_data_opt { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
692 |
DirstateV2Data { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
693 |
wc_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
694 |
p1_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
695 |
p2_info, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
696 |
mode_size: parent_file_data.mode_size, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
697 |
mtime: if has_meaningful_mtime { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
698 |
parent_file_data.mtime |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
699 |
} else { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
700 |
None |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
701 |
}, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
702 |
..Default::default() |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
703 |
} |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
704 |
} else { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
705 |
DirstateV2Data { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
706 |
wc_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
707 |
p1_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
708 |
p2_info, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
709 |
..Default::default() |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
710 |
} |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
711 |
}; |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
712 |
node.data = NodeData::Entry(DirstateEntry::from_v2_data(v2_data)); |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
713 |
if !had_entry { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
714 |
self.nodes_with_entry_count += 1; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
715 |
} |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
716 |
Ok(()) |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
717 |
} |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
718 |
|
49152
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
719 |
fn set_tracked( |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
720 |
&mut self, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
721 |
filename: &HgPath, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
722 |
old_entry_opt: Option<DirstateEntry>, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
723 |
) -> Result<bool, DirstateV2ParseError> { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
724 |
let was_tracked = old_entry_opt.map_or(false, |e| e.tracked()); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
725 |
let had_entry = old_entry_opt.is_some(); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
726 |
let tracked_count_increment = if was_tracked { 0 } else { 1 }; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
727 |
let mut new = false; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
728 |
|
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
729 |
let node = self.get_or_insert_node(filename, |ancestor| { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
730 |
if !had_entry { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
731 |
ancestor.descendants_with_entry_count += 1; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
732 |
} |
49152
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
733 |
|
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
734 |
ancestor.tracked_descendants_count += tracked_count_increment; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
735 |
})?; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
736 |
if let Some(old_entry) = old_entry_opt { |
49152
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
737 |
let mut e = old_entry.clone(); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
738 |
if e.tracked() { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
739 |
// XXX |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
740 |
// This is probably overkill for more case, but we need this to |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
741 |
// fully replace the `normallookup` call with `set_tracked` |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
742 |
// one. Consider smoothing this in the future. |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
743 |
e.set_possibly_dirty(); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
744 |
} else { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
745 |
new = true; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
746 |
e.set_tracked(); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
747 |
} |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
748 |
node.data = NodeData::Entry(e) |
49152
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
749 |
} else { |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
750 |
node.data = NodeData::Entry(DirstateEntry::new_tracked()); |
49152
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
751 |
self.nodes_with_entry_count += 1; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
752 |
new = true; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
753 |
}; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
754 |
Ok(new) |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
755 |
} |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
756 |
|
49187
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
757 |
/// Set a node as untracked in the dirstate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
758 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
759 |
/// It is the responsibility of the caller to remove the copy source and/or |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
760 |
/// the entry itself if appropriate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
761 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
762 |
/// # Panics |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
763 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
764 |
/// Panics if the node does not exist. |
49163
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
765 |
fn set_untracked( |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
766 |
&mut self, |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
767 |
filename: &HgPath, |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
768 |
old_entry: DirstateEntry, |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
769 |
) -> Result<(), DirstateV2ParseError> { |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
770 |
let node = self |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
771 |
.get_node_mut(filename, |ancestor| { |
49187
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
772 |
ancestor.tracked_descendants_count = ancestor |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
773 |
.tracked_descendants_count |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
774 |
.checked_sub(1) |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
775 |
.expect("tracked_descendants_count should be >= 0"); |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
776 |
})? |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
777 |
.expect("node should exist"); |
49163
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
778 |
let mut new_entry = old_entry.clone(); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
779 |
new_entry.set_untracked(); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
780 |
node.data = NodeData::Entry(new_entry); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
781 |
Ok(()) |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
782 |
} |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
783 |
|
49187
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
784 |
/// Set a node as clean in the dirstate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
785 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
786 |
/// It is the responsibility of the caller to remove the copy source. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
787 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
788 |
/// # Panics |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
789 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
790 |
/// Panics if the node does not exist. |
49159
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
791 |
fn set_clean( |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
792 |
&mut self, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
793 |
filename: &HgPath, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
794 |
old_entry: DirstateEntry, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
795 |
mode: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
796 |
size: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
797 |
mtime: TruncatedTimestamp, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
798 |
) -> Result<(), DirstateError> { |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
799 |
let node = self |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
800 |
.get_node_mut(filename, |ancestor| { |
49187
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
801 |
if !old_entry.tracked() { |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
802 |
ancestor.tracked_descendants_count += 1; |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
803 |
} |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
804 |
})? |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
805 |
.expect("node should exist"); |
49159
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
806 |
let mut new_entry = old_entry.clone(); |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
807 |
new_entry.set_clean(mode, size, mtime); |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
808 |
node.data = NodeData::Entry(new_entry); |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
809 |
Ok(()) |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
810 |
} |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
811 |
|
49187
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
812 |
/// Set a node as possibly dirty in the dirstate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
813 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
814 |
/// # Panics |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
815 |
/// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49186
diff
changeset
|
816 |
/// Panics if the node does not exist. |
49161
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
817 |
fn set_possibly_dirty( |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
818 |
&mut self, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
819 |
filename: &HgPath, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
820 |
) -> Result<(), DirstateError> { |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
821 |
let node = self |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
822 |
.get_node_mut(filename, |_ancestor| {})? |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
823 |
.expect("node should exist"); |
49161
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
824 |
let entry = node.data.as_entry_mut().expect("entry should exist"); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
825 |
entry.set_possibly_dirty(); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
826 |
node.data = NodeData::Entry(*entry); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
827 |
Ok(()) |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
828 |
} |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
829 |
|
49182
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
830 |
/// Clears the cached mtime for the (potential) folder at `path`. |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
831 |
pub(super) fn clear_cached_mtime( |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
832 |
&mut self, |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
833 |
path: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
834 |
) -> Result<(), DirstateV2ParseError> { |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
835 |
let node = match self.get_node_mut(path, |_ancestor| {})? { |
49182
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
836 |
Some(node) => node, |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
837 |
None => return Ok(()), |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
838 |
}; |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
839 |
if let NodeData::CachedDirectory { .. } = &node.data { |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
840 |
node.data = NodeData::None |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
841 |
} |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
842 |
Ok(()) |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49181
diff
changeset
|
843 |
} |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
844 |
|
49183
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
845 |
/// Sets the cached mtime for the (potential) folder at `path`. |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
846 |
pub(super) fn set_cached_mtime( |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
847 |
&mut self, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
848 |
path: &HgPath, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
849 |
mtime: TruncatedTimestamp, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
850 |
) -> Result<(), DirstateV2ParseError> { |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
851 |
let node = match self.get_node_mut(path, |_ancestor| {})? { |
49183
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
852 |
Some(node) => node, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
853 |
None => return Ok(()), |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
854 |
}; |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
855 |
match &node.data { |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
856 |
NodeData::Entry(_) => {} // Don’t overwrite an entry |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
857 |
NodeData::CachedDirectory { .. } | NodeData::None => { |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
858 |
node.data = NodeData::CachedDirectory { mtime } |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49182
diff
changeset
|
859 |
} |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
860 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
861 |
Ok(()) |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
862 |
} |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
863 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
864 |
fn iter_nodes<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
865 |
&'tree self, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
866 |
) -> impl Iterator< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
867 |
Item = Result<NodeRef<'tree, 'on_disk>, DirstateV2ParseError>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
868 |
> + 'tree { |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
869 |
// Depth first tree traversal. |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
870 |
// |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
871 |
// If we could afford internal iteration and recursion, |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
872 |
// this would look like: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
873 |
// |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
874 |
// ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
875 |
// fn traverse_children( |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
876 |
// children: &ChildNodes, |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
877 |
// each: &mut impl FnMut(&Node), |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
878 |
// ) { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
879 |
// for child in children.values() { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
880 |
// traverse_children(&child.children, each); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
881 |
// each(child); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
882 |
// } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
883 |
// } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
884 |
// ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
885 |
// |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
886 |
// However we want an external iterator and therefore can’t use the |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
887 |
// call stack. Use an explicit stack instead: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
888 |
let mut stack = Vec::new(); |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
889 |
let mut iter = self.root.as_ref().iter(); |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
890 |
std::iter::from_fn(move || { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
891 |
while let Some(child_node) = iter.next() { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
892 |
let children = match child_node.children(self.on_disk) { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
893 |
Ok(children) => children, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
894 |
Err(error) => return Some(Err(error)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
895 |
}; |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
896 |
// Pseudo-recursion |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
897 |
let new_iter = children.iter(); |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
898 |
let old_iter = std::mem::replace(&mut iter, new_iter); |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
899 |
stack.push((child_node, old_iter)); |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
900 |
} |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
901 |
// Found the end of a `children.iter()` iterator. |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
902 |
if let Some((child_node, next_iter)) = stack.pop() { |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
903 |
// "Return" from pseudo-recursion by restoring state from the |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
904 |
// explicit stack |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
905 |
iter = next_iter; |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
906 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
907 |
Some(Ok(child_node)) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
908 |
} else { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
909 |
// Reached the bottom of the stack, we’re done |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
910 |
None |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
911 |
} |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
912 |
}) |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
913 |
} |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
914 |
|
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
915 |
fn count_dropped_path(unreachable_bytes: &mut u32, path: &Cow<HgPath>) { |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
916 |
if let Cow::Borrowed(path) = path { |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
917 |
*unreachable_bytes += path.len() as u32 |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
918 |
} |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
919 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
920 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
921 |
|
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
922 |
/// Like `Iterator::filter_map`, but over a fallible iterator of `Result`s. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
923 |
/// |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
924 |
/// The callback is only called for incoming `Ok` values. Errors are passed |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
925 |
/// through as-is. In order to let it use the `?` operator the callback is |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
926 |
/// expected to return a `Result` of `Option`, instead of an `Option` of |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
927 |
/// `Result`. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
928 |
fn filter_map_results<'a, I, F, A, B, E>( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
929 |
iter: I, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
930 |
f: F, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
931 |
) -> impl Iterator<Item = Result<B, E>> + 'a |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
932 |
where |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
933 |
I: Iterator<Item = Result<A, E>> + 'a, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
934 |
F: Fn(A) -> Result<Option<B>, E> + 'a, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
935 |
{ |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
936 |
iter.filter_map(move |result| match result { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
937 |
Ok(node) => f(node).transpose(), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
938 |
Err(e) => Some(Err(e)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
939 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
940 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
941 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
942 |
impl OwningDirstateMap { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
943 |
pub fn clear(&mut self) { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
944 |
self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
945 |
map.root = Default::default(); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
946 |
map.nodes_with_entry_count = 0; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
947 |
map.nodes_with_copy_source_count = 0; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
948 |
}); |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
949 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
950 |
|
49152
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
951 |
pub fn set_tracked( |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
952 |
&mut self, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
953 |
filename: &HgPath, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
954 |
) -> Result<bool, DirstateV2ParseError> { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
955 |
let old_entry_opt = self.get(filename)?; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
956 |
self.with_dmap_mut(|map| map.set_tracked(filename, old_entry_opt)) |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
957 |
} |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49110
diff
changeset
|
958 |
|
49163
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
959 |
pub fn set_untracked( |
48062
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
960 |
&mut self, |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
961 |
filename: &HgPath, |
49163
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
962 |
) -> Result<bool, DirstateError> { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
963 |
let old_entry_opt = self.get(filename)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
964 |
match old_entry_opt { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
965 |
None => Ok(false), |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
966 |
Some(old_entry) => { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
967 |
if !old_entry.tracked() { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
968 |
// `DirstateMap::set_untracked` is not a noop if |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
969 |
// already not tracked as it will decrement the |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
970 |
// tracked counters while going down. |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
971 |
return Ok(true); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
972 |
} |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
973 |
if old_entry.added() { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
974 |
// Untracking an "added" entry will just result in a |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
975 |
// worthless entry (and other parts of the code will |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
976 |
// complain about it), just drop it entirely. |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
977 |
self.drop_entry_and_copy_source(filename)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
978 |
return Ok(true); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
979 |
} |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
980 |
if !old_entry.p2_info() { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
981 |
self.copy_map_remove(filename)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
982 |
} |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
983 |
|
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
984 |
self.with_dmap_mut(|map| { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
985 |
map.set_untracked(filename, old_entry)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
986 |
Ok(true) |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
987 |
}) |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
988 |
} |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49161
diff
changeset
|
989 |
} |
47692
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47683
diff
changeset
|
990 |
} |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47683
diff
changeset
|
991 |
|
49159
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
992 |
pub fn set_clean( |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
993 |
&mut self, |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
994 |
filename: &HgPath, |
49159
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
995 |
mode: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
996 |
size: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
997 |
mtime: TruncatedTimestamp, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
998 |
) -> Result<(), DirstateError> { |
49159
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
999 |
let old_entry = match self.get(filename)? { |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1000 |
None => { |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1001 |
return Err( |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1002 |
DirstateMapError::PathNotFound(filename.into()).into() |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1003 |
) |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1004 |
} |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1005 |
Some(e) => e, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1006 |
}; |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1007 |
self.copy_map_remove(filename)?; |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1008 |
self.with_dmap_mut(|map| { |
49159
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
1009 |
map.set_clean(filename, old_entry, mode, size, mtime) |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1010 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1011 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1012 |
|
49161
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1013 |
pub fn set_possibly_dirty( |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1014 |
&mut self, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1015 |
filename: &HgPath, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1016 |
) -> Result<(), DirstateError> { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1017 |
if self.get(filename)?.is_none() { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1018 |
return Err(DirstateMapError::PathNotFound(filename.into()).into()); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1019 |
} |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1020 |
self.with_dmap_mut(|map| map.set_possibly_dirty(filename)) |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1021 |
} |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49159
diff
changeset
|
1022 |
|
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1023 |
pub fn reset_state( |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1024 |
&mut self, |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
1025 |
filename: &HgPath, |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1026 |
wc_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1027 |
p1_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1028 |
p2_info: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1029 |
has_meaningful_mtime: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1030 |
parent_file_data_opt: Option<ParentFileData>, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1031 |
) -> Result<(), DirstateError> { |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1032 |
if !(p1_tracked || p2_info || wc_tracked) { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1033 |
self.drop_entry_and_copy_source(filename)?; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1034 |
return Ok(()); |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1035 |
} |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1036 |
self.copy_map_remove(filename)?; |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
1037 |
let old_entry_opt = self.get(filename)?; |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1038 |
self.with_dmap_mut(|map| { |
49156
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1039 |
map.reset_state( |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1040 |
filename, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1041 |
old_entry_opt, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1042 |
wc_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1043 |
p1_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1044 |
p2_info, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1045 |
has_meaningful_mtime, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1046 |
parent_file_data_opt, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49152
diff
changeset
|
1047 |
) |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1048 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1049 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1050 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1051 |
pub fn drop_entry_and_copy_source( |
48065
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
1052 |
&mut self, |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
1053 |
filename: &HgPath, |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
1054 |
) -> Result<(), DirstateError> { |
49178
afe60def963d
rust-dirstatemap: use `DirstateEntry::tracked` directly
Raphaël Gomès <rgomes@octobus.net>
parents:
49176
diff
changeset
|
1055 |
let was_tracked = self.get(filename)?.map_or(false, |e| e.tracked()); |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1056 |
struct Dropped { |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1057 |
was_tracked: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1058 |
had_entry: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1059 |
had_copy_source: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1060 |
} |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1061 |
|
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1062 |
/// If this returns `Ok(Some((dropped, removed)))`, then |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1063 |
/// |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1064 |
/// * `dropped` is about the leaf node that was at `filename` |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1065 |
/// * `removed` is whether this particular level of recursion just |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1066 |
/// removed a node in `nodes`. |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1067 |
fn recur<'on_disk>( |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1068 |
on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1069 |
unreachable_bytes: &mut u32, |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1070 |
nodes: &mut ChildNodes<'on_disk>, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1071 |
path: &HgPath, |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1072 |
) -> Result<Option<(Dropped, bool)>, DirstateV2ParseError> { |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1073 |
let (first_path_component, rest_of_path) = |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1074 |
path.split_first_component(); |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1075 |
let nodes = nodes.make_mut(on_disk, unreachable_bytes)?; |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1076 |
let node = if let Some(node) = nodes.get_mut(first_path_component) |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1077 |
{ |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1078 |
node |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1079 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1080 |
return Ok(None); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1081 |
}; |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1082 |
let dropped; |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1083 |
if let Some(rest) = rest_of_path { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1084 |
if let Some((d, removed)) = recur( |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1085 |
on_disk, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1086 |
unreachable_bytes, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1087 |
&mut node.children, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1088 |
rest, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1089 |
)? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1090 |
dropped = d; |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
1091 |
if dropped.had_entry { |
48826
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1092 |
node.descendants_with_entry_count = node |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1093 |
.descendants_with_entry_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1094 |
.checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1095 |
.expect( |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1096 |
"descendants_with_entry_count should be >= 0", |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1097 |
); |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
1098 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1099 |
if dropped.was_tracked { |
48826
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1100 |
node.tracked_descendants_count = node |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1101 |
.tracked_descendants_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1102 |
.checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1103 |
.expect( |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1104 |
"tracked_descendants_count should be >= 0", |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1105 |
); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1106 |
} |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1107 |
|
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1108 |
// Directory caches must be invalidated when removing a |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1109 |
// child node |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1110 |
if removed { |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1111 |
if let NodeData::CachedDirectory { .. } = &node.data { |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1112 |
node.data = NodeData::None |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1113 |
} |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1114 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1115 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1116 |
return Ok(None); |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
1117 |
} |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1118 |
} else { |
48827
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
48826
diff
changeset
|
1119 |
let entry = node.data.as_entry(); |
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
48826
diff
changeset
|
1120 |
let was_tracked = entry.map_or(false, |entry| entry.tracked()); |
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
48826
diff
changeset
|
1121 |
let had_entry = entry.is_some(); |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
1122 |
if had_entry { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
1123 |
node.data = NodeData::None |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
1124 |
} |
48828
ce919b1a1063
rust-dirstatemap: correctly decrement the copies counter
Raphaël Gomès <rgomes@octobus.net>
parents:
48827
diff
changeset
|
1125 |
let mut had_copy_source = false; |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1126 |
if let Some(source) = &node.copy_source { |
48065
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
1127 |
DirstateMap::count_dropped_path(unreachable_bytes, source); |
48828
ce919b1a1063
rust-dirstatemap: correctly decrement the copies counter
Raphaël Gomès <rgomes@octobus.net>
parents:
48827
diff
changeset
|
1128 |
had_copy_source = true; |
48065
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
1129 |
node.copy_source = None |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1130 |
} |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1131 |
dropped = Dropped { |
48827
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
48826
diff
changeset
|
1132 |
was_tracked, |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
1133 |
had_entry, |
48828
ce919b1a1063
rust-dirstatemap: correctly decrement the copies counter
Raphaël Gomès <rgomes@octobus.net>
parents:
48827
diff
changeset
|
1134 |
had_copy_source, |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1135 |
}; |
47204
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
1136 |
} |
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
1137 |
// After recursion, for both leaf (rest_of_path is None) nodes and |
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
1138 |
// parent nodes, remove a node if it just became empty. |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1139 |
let remove = !node.data.has_entry() |
47204
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
1140 |
&& node.copy_source.is_none() |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1141 |
&& node.children.is_empty(); |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1142 |
if remove { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1143 |
let (key, _) = |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1144 |
nodes.remove_entry(first_path_component).unwrap(); |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1145 |
DirstateMap::count_dropped_path( |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1146 |
unreachable_bytes, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1147 |
key.full_path(), |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1148 |
) |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1149 |
} |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
1150 |
Ok(Some((dropped, remove))) |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
1151 |
} |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
1152 |
|
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1153 |
self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1154 |
if let Some((dropped, _removed)) = recur( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1155 |
map.on_disk, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1156 |
&mut map.unreachable_bytes, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1157 |
&mut map.root, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1158 |
filename, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1159 |
)? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1160 |
if dropped.had_entry { |
48826
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1161 |
map.nodes_with_entry_count = map |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1162 |
.nodes_with_entry_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1163 |
.checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1164 |
.expect("nodes_with_entry_count should be >= 0"); |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1165 |
} |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1166 |
if dropped.had_copy_source { |
48826
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1167 |
map.nodes_with_copy_source_count = map |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1168 |
.nodes_with_copy_source_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1169 |
.checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
1170 |
.expect("nodes_with_copy_source_count should be >= 0"); |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1171 |
} |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1172 |
} else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1173 |
debug_assert!(!was_tracked); |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
1174 |
} |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1175 |
Ok(()) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1176 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1177 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1178 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1179 |
pub fn has_tracked_dir( |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1180 |
&mut self, |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1181 |
directory: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1182 |
) -> Result<bool, DirstateError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1183 |
self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1184 |
if let Some(node) = map.get_node(directory)? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1185 |
// A node without a `DirstateEntry` was created to hold child |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1186 |
// nodes, and is therefore a directory. |
49195
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49191
diff
changeset
|
1187 |
let is_dir = node.entry()?.is_none(); |
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49191
diff
changeset
|
1188 |
Ok(is_dir && node.tracked_descendants_count() > 0) |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1189 |
} else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1190 |
Ok(false) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1191 |
} |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1192 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1193 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1194 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1195 |
pub fn has_dir( |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1196 |
&mut self, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1197 |
directory: &HgPath, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1198 |
) -> Result<bool, DirstateError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1199 |
self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1200 |
if let Some(node) = map.get_node(directory)? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1201 |
// A node without a `DirstateEntry` was created to hold child |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1202 |
// nodes, and is therefore a directory. |
49195
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49191
diff
changeset
|
1203 |
let is_dir = node.entry()?.is_none(); |
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49191
diff
changeset
|
1204 |
Ok(is_dir && node.descendants_with_entry_count() > 0) |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1205 |
} else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1206 |
Ok(false) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1207 |
} |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1208 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1209 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1210 |
|
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
1211 |
#[timed] |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1212 |
pub fn pack_v1( |
48462
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48440
diff
changeset
|
1213 |
&self, |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1214 |
parents: DirstateParents, |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1215 |
) -> Result<Vec<u8>, DirstateError> { |
48462
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48440
diff
changeset
|
1216 |
let map = self.get_map(); |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1217 |
// Optizimation (to be measured?): pre-compute size to avoid `Vec` |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1218 |
// reallocations |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1219 |
let mut size = parents.as_bytes().len(); |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1220 |
for node in map.iter_nodes() { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1221 |
let node = node?; |
48440
434de12918fd
dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48271
diff
changeset
|
1222 |
if node.entry()?.is_some() { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1223 |
size += packed_entry_size( |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1224 |
node.full_path(map.on_disk)?, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1225 |
node.copy_source(map.on_disk)?, |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1226 |
); |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1227 |
} |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1228 |
} |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1229 |
|
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1230 |
let mut packed = Vec::with_capacity(size); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1231 |
packed.extend(parents.as_bytes()); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1232 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1233 |
for node in map.iter_nodes() { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1234 |
let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1235 |
if let Some(entry) = node.entry()? { |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1236 |
pack_entry( |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1237 |
node.full_path(map.on_disk)?, |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
1238 |
&entry, |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1239 |
node.copy_source(map.on_disk)?, |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1240 |
&mut packed, |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1241 |
); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1242 |
} |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1243 |
} |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1244 |
Ok(packed) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1245 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1246 |
|
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1247 |
/// Returns new data and metadata together with whether that data should be |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1248 |
/// appended to the existing data file whose content is at |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1249 |
/// `map.on_disk` (true), instead of written to a new data file |
48843
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
1250 |
/// (false), and the previous size of data on disk. |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
1251 |
#[timed] |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1252 |
pub fn pack_v2( |
48462
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48440
diff
changeset
|
1253 |
&self, |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
1254 |
can_append: bool, |
48843
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
1255 |
) -> Result<(Vec<u8>, on_disk::TreeMetadata, bool, usize), DirstateError> |
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48828
diff
changeset
|
1256 |
{ |
48462
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48440
diff
changeset
|
1257 |
let map = self.get_map(); |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1258 |
on_disk::write(map, can_append) |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
1259 |
} |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
1260 |
|
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1261 |
/// `callback` allows the caller to process and do something with the |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1262 |
/// results of the status. This is needed to do so efficiently (i.e. |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1263 |
/// without cloning the `DirstateStatus` object with its paths) because |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1264 |
/// we need to borrow from `Self`. |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1265 |
pub fn with_status<R>( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1266 |
&mut self, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1267 |
matcher: &(dyn Matcher + Sync), |
47126
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1268 |
root_dir: PathBuf, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1269 |
ignore_files: Vec<PathBuf>, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1270 |
options: StatusOptions, |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1271 |
callback: impl for<'r> FnOnce( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1272 |
Result<(DirstateStatus<'r>, Vec<PatternFileWarning>), StatusError>, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1273 |
) -> R, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1274 |
) -> R { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1275 |
self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1276 |
callback(super::status::status( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1277 |
map, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1278 |
matcher, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1279 |
root_dir, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1280 |
ignore_files, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1281 |
options, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1282 |
)) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1283 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1284 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1285 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1286 |
pub fn copy_map_len(&self) -> usize { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1287 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1288 |
map.nodes_with_copy_source_count as usize |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1289 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1290 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1291 |
pub fn copy_map_iter(&self) -> CopyMapIter<'_> { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1292 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1293 |
Box::new(filter_map_results(map.iter_nodes(), move |node| { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1294 |
Ok(if let Some(source) = node.copy_source(map.on_disk)? { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1295 |
Some((node.full_path(map.on_disk)?, source)) |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1296 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1297 |
None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1298 |
}) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
1299 |
})) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1300 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1301 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1302 |
pub fn copy_map_contains_key( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1303 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1304 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1305 |
) -> Result<bool, DirstateV2ParseError> { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1306 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1307 |
Ok(if let Some(node) = map.get_node(key)? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1308 |
node.has_copy_source() |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
1309 |
} else { |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
1310 |
false |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1311 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1312 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1313 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1314 |
pub fn copy_map_get( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1315 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1316 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1317 |
) -> Result<Option<&HgPath>, DirstateV2ParseError> { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1318 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1319 |
if let Some(node) = map.get_node(key)? { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1320 |
if let Some(source) = node.copy_source(map.on_disk)? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1321 |
return Ok(Some(source)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1322 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1323 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1324 |
Ok(None) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1325 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1326 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1327 |
pub fn copy_map_remove( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1328 |
&mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1329 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1330 |
) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1331 |
self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1332 |
let count = &mut map.nodes_with_copy_source_count; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1333 |
let unreachable_bytes = &mut map.unreachable_bytes; |
49188
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49187
diff
changeset
|
1334 |
Ok(DirstateMap::get_node_mut_inner( |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1335 |
map.on_disk, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1336 |
unreachable_bytes, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1337 |
&mut map.root, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1338 |
key, |
49186
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49185
diff
changeset
|
1339 |
|_ancestor| {}, |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1340 |
)? |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1341 |
.and_then(|node| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1342 |
if let Some(source) = &node.copy_source { |
49189
8c59d8adcf5b
rust-dirstatemap: use a checked sub instead of a potentially underflowing one
Raphaël Gomès <rgomes@octobus.net>
parents:
49188
diff
changeset
|
1343 |
*count = count |
8c59d8adcf5b
rust-dirstatemap: use a checked sub instead of a potentially underflowing one
Raphaël Gomès <rgomes@octobus.net>
parents:
49188
diff
changeset
|
1344 |
.checked_sub(1) |
8c59d8adcf5b
rust-dirstatemap: use a checked sub instead of a potentially underflowing one
Raphaël Gomès <rgomes@octobus.net>
parents:
49188
diff
changeset
|
1345 |
.expect("nodes_with_copy_source_count should be >= 0"); |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1346 |
DirstateMap::count_dropped_path(unreachable_bytes, source); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1347 |
} |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1348 |
node.copy_source.take().map(Cow::into_owned) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1349 |
})) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1350 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1351 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1352 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1353 |
pub fn copy_map_insert( |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1354 |
&mut self, |
49179
d9a66d62c604
rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents:
49178
diff
changeset
|
1355 |
key: &HgPath, |
d9a66d62c604
rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents:
49178
diff
changeset
|
1356 |
value: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1357 |
) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1358 |
self.with_dmap_mut(|map| { |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1359 |
let node = map.get_or_insert_node(&key, |_ancestor| {})?; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1360 |
let had_copy_source = node.copy_source.is_none(); |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1361 |
let old = node |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1362 |
.copy_source |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1363 |
.replace(value.to_owned().into()) |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1364 |
.map(Cow::into_owned); |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1365 |
if had_copy_source { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1366 |
map.nodes_with_copy_source_count += 1 |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1367 |
} |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1368 |
Ok(old) |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1369 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1370 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1371 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1372 |
pub fn len(&self) -> usize { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1373 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1374 |
map.nodes_with_entry_count as usize |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1375 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1376 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1377 |
pub fn contains_key( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1378 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1379 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1380 |
) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1381 |
Ok(self.get(key)?.is_some()) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1382 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1383 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1384 |
pub fn get( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1385 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1386 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1387 |
) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1388 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1389 |
Ok(if let Some(node) = map.get_node(key)? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1390 |
node.entry()? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1391 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1392 |
None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1393 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1394 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1395 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1396 |
pub fn iter(&self) -> StateMapIter<'_> { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1397 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1398 |
Box::new(filter_map_results(map.iter_nodes(), move |node| { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1399 |
Ok(if let Some(entry) = node.entry()? { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1400 |
Some((node.full_path(map.on_disk)?, entry)) |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1401 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1402 |
None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1403 |
}) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
1404 |
})) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1405 |
} |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1406 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1407 |
pub fn iter_tracked_dirs( |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1408 |
&mut self, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1409 |
) -> Result< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1410 |
Box< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1411 |
dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1412 |
+ Send |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1413 |
+ '_, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1414 |
>, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1415 |
DirstateError, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1416 |
> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1417 |
let map = self.get_map(); |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1418 |
let on_disk = map.on_disk; |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1419 |
Ok(Box::new(filter_map_results( |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1420 |
map.iter_nodes(), |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1421 |
move |node| { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1422 |
Ok(if node.tracked_descendants_count() > 0 { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1423 |
Some(node.full_path(on_disk)?) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1424 |
} else { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1425 |
None |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1426 |
}) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1427 |
}, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1428 |
))) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1429 |
} |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1430 |
|
49175
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1431 |
/// Only public because it needs to be exposed to the Python layer. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1432 |
/// It is not the full `setparents` logic, only the parts that mutate the |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1433 |
/// entries. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1434 |
pub fn setparents_fixup( |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1435 |
&mut self, |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1436 |
) -> Result<Vec<(HgPathBuf, HgPathBuf)>, DirstateV2ParseError> { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1437 |
// XXX |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1438 |
// All the copying and re-querying is quite inefficient, but this is |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1439 |
// still a lot better than doing it from Python. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1440 |
// |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1441 |
// The better solution is to develop a mechanism for `iter_mut`, |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1442 |
// which will be a lot more involved: we're dealing with a lazy, |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1443 |
// append-mostly, tree-like data structure. This will do for now. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1444 |
let mut copies = vec![]; |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1445 |
let mut files_with_p2_info = vec![]; |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1446 |
for res in self.iter() { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1447 |
let (path, entry) = res?; |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1448 |
if entry.p2_info() { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1449 |
files_with_p2_info.push(path.to_owned()) |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1450 |
} |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1451 |
} |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1452 |
self.with_dmap_mut(|map| { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1453 |
for path in files_with_p2_info.iter() { |
49185
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49184
diff
changeset
|
1454 |
let node = map.get_or_insert_node(path, |_| {})?; |
49175
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1455 |
let entry = |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1456 |
node.data.as_entry_mut().expect("entry should exist"); |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1457 |
entry.drop_merge_data(); |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1458 |
if let Some(source) = node.copy_source.take().as_deref() { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1459 |
copies.push((path.to_owned(), source.to_owned())); |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1460 |
} |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1461 |
} |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1462 |
Ok(copies) |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1463 |
}) |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1464 |
} |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49167
diff
changeset
|
1465 |
|
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1466 |
pub fn debug_iter( |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1467 |
&self, |
48045
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
1468 |
all: bool, |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1469 |
) -> Box< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1470 |
dyn Iterator< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1471 |
Item = Result< |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1472 |
(&HgPath, (u8, i32, i32, i32)), |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1473 |
DirstateV2ParseError, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1474 |
>, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1475 |
> + Send |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1476 |
+ '_, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1477 |
> { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1478 |
let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1479 |
Box::new(filter_map_results(map.iter_nodes(), move |node| { |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1480 |
let debug_tuple = if let Some(entry) = node.entry()? { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1481 |
entry.debug_tuple() |
48045
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
1482 |
} else if !all { |
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
1483 |
return Ok(None); |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
1484 |
} else if let Some(mtime) = node.cached_directory_mtime()? { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
1485 |
(b' ', 0, -1, mtime.truncated_seconds() as i32) |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1486 |
} else { |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1487 |
(b' ', 0, -1, -1) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1488 |
}; |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1489 |
Ok(Some((node.full_path(map.on_disk)?, debug_tuple))) |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1490 |
})) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1491 |
} |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1492 |
} |
49181
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1493 |
#[cfg(test)] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1494 |
mod tests { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1495 |
use super::*; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1496 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1497 |
/// Shortcut to return tracked descendants of a path. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1498 |
/// Panics if the path does not exist. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1499 |
fn tracked_descendants(map: &OwningDirstateMap, path: &[u8]) -> u32 { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1500 |
let path = dbg!(HgPath::new(path)); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1501 |
let node = map.get_map().get_node(path); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1502 |
node.unwrap().unwrap().tracked_descendants_count() |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1503 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1504 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1505 |
/// Shortcut to return descendants with an entry. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1506 |
/// Panics if the path does not exist. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1507 |
fn descendants_with_an_entry(map: &OwningDirstateMap, path: &[u8]) -> u32 { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1508 |
let path = dbg!(HgPath::new(path)); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1509 |
let node = map.get_map().get_node(path); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1510 |
node.unwrap().unwrap().descendants_with_entry_count() |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1511 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1512 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1513 |
fn assert_does_not_exist(map: &OwningDirstateMap, path: &[u8]) { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1514 |
let path = dbg!(HgPath::new(path)); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1515 |
let node = map.get_map().get_node(path); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1516 |
assert!(node.unwrap().is_none()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1517 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1518 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1519 |
/// Shortcut for path creation in tests |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1520 |
fn p(b: &[u8]) -> &HgPath { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1521 |
HgPath::new(b) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1522 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1523 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1524 |
/// Test the very simple case a single tracked file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1525 |
#[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1526 |
fn test_tracked_descendants_simple() -> Result<(), DirstateError> { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1527 |
let mut map = OwningDirstateMap::new_empty(vec![]); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1528 |
assert_eq!(map.len(), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1529 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1530 |
map.set_tracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1531 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1532 |
assert_eq!(map.len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1533 |
assert_eq!(tracked_descendants(&map, b"some"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1534 |
assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1535 |
assert_eq!(tracked_descendants(&map, b"some/nested/path"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1536 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1537 |
map.set_untracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1538 |
assert_eq!(map.len(), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1539 |
assert!(map.get_map().get_node(p(b"some"))?.is_none()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1540 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1541 |
Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1542 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1543 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1544 |
/// Test the simple case of all tracked, but multiple files |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1545 |
#[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1546 |
fn test_tracked_descendants_multiple() -> Result<(), DirstateError> { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1547 |
let mut map = OwningDirstateMap::new_empty(vec![]); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1548 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1549 |
map.set_tracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1550 |
map.set_tracked(p(b"some/nested/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1551 |
// one layer without any files to test deletion cascade |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1552 |
map.set_tracked(p(b"some/other/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1553 |
map.set_tracked(p(b"root_file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1554 |
map.set_tracked(p(b"some/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1555 |
map.set_tracked(p(b"some/file2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1556 |
map.set_tracked(p(b"some/file3"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1557 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1558 |
assert_eq!(map.len(), 7); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1559 |
assert_eq!(tracked_descendants(&map, b"some"), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1560 |
assert_eq!(tracked_descendants(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1561 |
assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1562 |
assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1563 |
assert_eq!(tracked_descendants(&map, b"some/nested/path"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1564 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1565 |
map.set_untracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1566 |
assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1567 |
assert_eq!(tracked_descendants(&map, b"some"), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1568 |
assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1569 |
assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1570 |
assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1571 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1572 |
map.set_untracked(p(b"some/nested/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1573 |
assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1574 |
assert_eq!(tracked_descendants(&map, b"some"), 4); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1575 |
assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1576 |
assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1577 |
assert_does_not_exist(&map, b"some_nested"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1578 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1579 |
map.set_untracked(p(b"some/other/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1580 |
assert_eq!(map.len(), 4); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1581 |
assert_eq!(tracked_descendants(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1582 |
assert_does_not_exist(&map, b"some/other"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1583 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1584 |
map.set_untracked(p(b"root_file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1585 |
assert_eq!(map.len(), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1586 |
assert_eq!(tracked_descendants(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1587 |
assert_does_not_exist(&map, b"root_file"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1588 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1589 |
map.set_untracked(p(b"some/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1590 |
assert_eq!(map.len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1591 |
assert_eq!(tracked_descendants(&map, b"some"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1592 |
assert_does_not_exist(&map, b"some/file"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1593 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1594 |
map.set_untracked(p(b"some/file2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1595 |
assert_eq!(map.len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1596 |
assert_eq!(tracked_descendants(&map, b"some"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1597 |
assert_does_not_exist(&map, b"some/file2"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1598 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1599 |
map.set_untracked(p(b"some/file3"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1600 |
assert_eq!(map.len(), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1601 |
assert_does_not_exist(&map, b"some/file3"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1602 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1603 |
Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1604 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1605 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1606 |
/// Check with a mix of tracked and non-tracked items |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1607 |
#[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1608 |
fn test_tracked_descendants_different() -> Result<(), DirstateError> { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1609 |
let mut map = OwningDirstateMap::new_empty(vec![]); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1610 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1611 |
// A file that was just added |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1612 |
map.set_tracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1613 |
// This has no information, the dirstate should ignore it |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1614 |
map.reset_state(p(b"some/file"), false, false, false, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1615 |
assert_does_not_exist(&map, b"some/file"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1616 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1617 |
// A file that was removed |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1618 |
map.reset_state( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1619 |
p(b"some/nested/file"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1620 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1621 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1622 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1623 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1624 |
None, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1625 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1626 |
assert!(!map.get(p(b"some/nested/file"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1627 |
// Only present in p2 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1628 |
map.reset_state(p(b"some/file3"), false, false, true, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1629 |
assert!(!map.get(p(b"some/file3"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1630 |
// A file that was merged |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1631 |
map.reset_state(p(b"root_file"), true, true, true, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1632 |
assert!(map.get(p(b"root_file"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1633 |
// A file that is added, with info from p2 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1634 |
// XXX is that actually possible? |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1635 |
map.reset_state(p(b"some/file2"), true, false, true, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1636 |
assert!(map.get(p(b"some/file2"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1637 |
// A clean file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1638 |
// One layer without any files to test deletion cascade |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1639 |
map.reset_state( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1640 |
p(b"some/other/nested/path"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1641 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1642 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1643 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1644 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1645 |
None, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1646 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1647 |
assert!(map.get(p(b"some/other/nested/path"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1648 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1649 |
assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1650 |
assert_eq!(tracked_descendants(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1651 |
assert_eq!(descendants_with_an_entry(&map, b"some"), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1652 |
assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1653 |
assert_eq!(descendants_with_an_entry(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1654 |
assert_eq!(tracked_descendants(&map, b"some/other/nested/path"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1655 |
assert_eq!( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1656 |
descendants_with_an_entry(&map, b"some/other/nested/path"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1657 |
0 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1658 |
); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1659 |
assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1660 |
assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1661 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1662 |
// might as well check this |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1663 |
map.set_untracked(p(b"path/does/not/exist"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1664 |
assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1665 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1666 |
map.set_untracked(p(b"some/other/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1667 |
// It is set untracked but not deleted since it held other information |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1668 |
assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1669 |
assert_eq!(tracked_descendants(&map, b"some"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1670 |
assert_eq!(descendants_with_an_entry(&map, b"some"), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1671 |
assert_eq!(descendants_with_an_entry(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1672 |
assert_eq!(descendants_with_an_entry(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1673 |
assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1674 |
assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1675 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1676 |
map.set_untracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1677 |
// It is set untracked *and* deleted since it was only added |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1678 |
assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1679 |
assert_eq!(tracked_descendants(&map, b"some"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1680 |
assert_eq!(descendants_with_an_entry(&map, b"some"), 4); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1681 |
assert_eq!(tracked_descendants(&map, b"some/nested"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1682 |
assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1683 |
assert_does_not_exist(&map, b"some/nested/path"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1684 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1685 |
map.set_untracked(p(b"root_file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1686 |
// Untracked but not deleted |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1687 |
assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1688 |
assert!(map.get(p(b"root_file"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1689 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1690 |
map.set_untracked(p(b"some/file2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1691 |
assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1692 |
assert_eq!(tracked_descendants(&map, b"some"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1693 |
assert!(map.get(p(b"some/file2"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1694 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1695 |
map.set_untracked(p(b"some/file3"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1696 |
assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1697 |
assert_eq!(tracked_descendants(&map, b"some"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1698 |
assert!(map.get(p(b"some/file3"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1699 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1700 |
Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1701 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1702 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1703 |
/// Check that copies counter is correctly updated |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1704 |
#[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1705 |
fn test_copy_source() -> Result<(), DirstateError> { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1706 |
let mut map = OwningDirstateMap::new_empty(vec![]); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1707 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1708 |
// Clean file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1709 |
map.reset_state(p(b"files/clean"), true, true, false, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1710 |
// Merged file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1711 |
map.reset_state(p(b"files/from_p2"), true, true, true, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1712 |
// Removed file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1713 |
map.reset_state(p(b"removed"), false, true, false, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1714 |
// Added file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1715 |
map.reset_state(p(b"files/added"), true, false, false, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1716 |
// Add copy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1717 |
map.copy_map_insert(p(b"files/clean"), p(b"clean_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1718 |
assert_eq!(map.copy_map_len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1719 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1720 |
// Copy override |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1721 |
map.copy_map_insert(p(b"files/clean"), p(b"other_clean_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1722 |
assert_eq!(map.copy_map_len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1723 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1724 |
// Multiple copies |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1725 |
map.copy_map_insert(p(b"removed"), p(b"removed_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1726 |
assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1727 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1728 |
map.copy_map_insert(p(b"files/added"), p(b"added_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1729 |
assert_eq!(map.copy_map_len(), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1730 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1731 |
// Added, so the entry is completely removed |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1732 |
map.set_untracked(p(b"files/added"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1733 |
assert_does_not_exist(&map, b"files/added"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1734 |
assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1735 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1736 |
// Removed, so the entry is kept around, so is its copy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1737 |
map.set_untracked(p(b"removed"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1738 |
assert!(map.get(p(b"removed"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1739 |
assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1740 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1741 |
// Clean, so the entry is kept around, but not its copy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1742 |
map.set_untracked(p(b"files/clean"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1743 |
assert!(map.get(p(b"files/clean"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1744 |
assert_eq!(map.copy_map_len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1745 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1746 |
map.copy_map_insert(p(b"files/from_p2"), p(b"from_p2_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1747 |
assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1748 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1749 |
// Info from p2, so its copy source info is kept around |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1750 |
map.set_untracked(p(b"files/from_p2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1751 |
assert!(map.get(p(b"files/from_p2"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1752 |
assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1753 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1754 |
Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1755 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1756 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1757 |
/// Test with "on disk" data. For the sake of this test, the "on disk" data |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1758 |
/// does not actually come from the disk, but it's opaque to the code being |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1759 |
/// tested. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1760 |
#[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1761 |
fn test_on_disk() -> Result<(), DirstateError> { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1762 |
// First let's create some data to put "on disk" |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1763 |
let mut map = OwningDirstateMap::new_empty(vec![]); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1764 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1765 |
// A file that was just added |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1766 |
map.set_tracked(p(b"some/nested/added"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1767 |
map.copy_map_insert(p(b"some/nested/added"), p(b"added_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1768 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1769 |
// A file that was removed |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1770 |
map.reset_state( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1771 |
p(b"some/nested/removed"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1772 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1773 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1774 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1775 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1776 |
None, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1777 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1778 |
// Only present in p2 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1779 |
map.reset_state( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1780 |
p(b"other/p2_info_only"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1781 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1782 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1783 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1784 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1785 |
None, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1786 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1787 |
map.copy_map_insert( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1788 |
p(b"other/p2_info_only"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1789 |
p(b"other/p2_info_copy_source"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1790 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1791 |
// A file that was merged |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1792 |
map.reset_state(p(b"merged"), true, true, true, false, None)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1793 |
// A file that is added, with info from p2 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1794 |
// XXX is that actually possible? |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1795 |
map.reset_state( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1796 |
p(b"other/added_with_p2"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1797 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1798 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1799 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1800 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1801 |
None, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1802 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1803 |
// One layer without any files to test deletion cascade |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1804 |
// A clean file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1805 |
map.reset_state( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1806 |
p(b"some/other/nested/clean"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1807 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1808 |
true, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1809 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1810 |
false, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1811 |
None, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1812 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1813 |
|
49200 | 1814 |
let (packed, metadata, _should_append, _old_data_size) = |
1815 |
map.pack_v2(false)?; |
|
49181
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1816 |
let packed_len = packed.len(); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1817 |
assert!(packed_len > 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1818 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1819 |
// Recreate "from disk" |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1820 |
let mut map = OwningDirstateMap::new_v2( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1821 |
packed, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1822 |
packed_len, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1823 |
metadata.as_bytes(), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1824 |
)?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1825 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1826 |
// Check that everything is accounted for |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1827 |
assert!(map.contains_key(p(b"some/nested/added"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1828 |
assert!(map.contains_key(p(b"some/nested/removed"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1829 |
assert!(map.contains_key(p(b"merged"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1830 |
assert!(map.contains_key(p(b"other/p2_info_only"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1831 |
assert!(map.contains_key(p(b"other/added_with_p2"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1832 |
assert!(map.contains_key(p(b"some/other/nested/clean"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1833 |
assert_eq!( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1834 |
map.copy_map_get(p(b"some/nested/added"))?, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1835 |
Some(p(b"added_copy_source")) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1836 |
); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1837 |
assert_eq!( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1838 |
map.copy_map_get(p(b"other/p2_info_only"))?, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1839 |
Some(p(b"other/p2_info_copy_source")) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1840 |
); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1841 |
assert_eq!(tracked_descendants(&map, b"some"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1842 |
assert_eq!(descendants_with_an_entry(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1843 |
assert_eq!(tracked_descendants(&map, b"other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1844 |
assert_eq!(descendants_with_an_entry(&map, b"other"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1845 |
assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1846 |
assert_eq!(descendants_with_an_entry(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1847 |
assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1848 |
assert_eq!(descendants_with_an_entry(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1849 |
assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1850 |
assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1851 |
assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1852 |
assert_eq!(map.get_map().unreachable_bytes, 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1853 |
assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1854 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1855 |
// Shouldn't change anything since it's already not tracked |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1856 |
map.set_untracked(p(b"some/nested/removed"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1857 |
assert_eq!(map.get_map().unreachable_bytes, 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1858 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1859 |
match map.get_map().root { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1860 |
ChildNodes::InMemory(_) => { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1861 |
panic!("root should not have been mutated") |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1862 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1863 |
_ => (), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1864 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1865 |
// We haven't mutated enough (nothing, actually), we should still be in |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1866 |
// the append strategy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1867 |
assert!(map.get_map().write_should_append()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1868 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1869 |
// But this mutates the structure, so there should be unreachable_bytes |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1870 |
assert!(map.set_untracked(p(b"some/nested/added"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1871 |
let unreachable_bytes = map.get_map().unreachable_bytes; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1872 |
assert!(unreachable_bytes > 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1873 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1874 |
match map.get_map().root { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1875 |
ChildNodes::OnDisk(_) => panic!("root should have been mutated"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1876 |
_ => (), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1877 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1878 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1879 |
// This should not mutate the structure either, since `root` has |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1880 |
// already been mutated along with its direct children. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1881 |
map.set_untracked(p(b"merged"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1882 |
assert_eq!(map.get_map().unreachable_bytes, unreachable_bytes); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1883 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1884 |
match map.get_map().get_node(p(b"other/added_with_p2"))?.unwrap() { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1885 |
NodeRef::InMemory(_, _) => { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1886 |
panic!("'other/added_with_p2' should not have been mutated") |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1887 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1888 |
_ => (), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1889 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1890 |
// But this should, since it's in a different path |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1891 |
// than `<root>some/nested/add` |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1892 |
map.set_untracked(p(b"other/added_with_p2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1893 |
assert!(map.get_map().unreachable_bytes > unreachable_bytes); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1894 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1895 |
match map.get_map().get_node(p(b"other/added_with_p2"))?.unwrap() { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1896 |
NodeRef::OnDisk(_) => { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1897 |
panic!("'other/added_with_p2' should have been mutated") |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1898 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1899 |
_ => (), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1900 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1901 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1902 |
// We have rewritten most of the tree, we should create a new file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1903 |
assert!(!map.get_map().write_should_append()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1904 |
|
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1905 |
Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1906 |
} |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49180
diff
changeset
|
1907 |
} |