Mercurial > hg-stable
annotate rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 48827:fbc02ccc207e stable
rust-dirstatemap: properly decrement counter for tracked descendants
I found this bug when writing unit tests after the fact for the `DirstateMap`.
We never decremented the tracked descendants counter since we were always
resetting the node data before reading it. This also drops the use of `state`,
in favor of the new API to get that information.
Differential Revision: https://phab.mercurial-scm.org/D12431
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 05 Apr 2022 10:55:28 +0200 |
parents | 2593873cda0f |
children | ce919b1a1063 |
rev | line source |
---|---|
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; |
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
14 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
|
15 use crate::dirstate::TruncatedTimestamp; |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
16 use crate::dirstate::SIZE_FROM_OTHER_PARENT; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
17 use crate::dirstate::SIZE_NON_NORMAL; |
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; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
22 use crate::DirstateParents; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
23 use crate::DirstateStatus; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
24 use crate::EntryState; |
47133
15395fd8ab28
dirstate-tree: Use HashMap instead of BTreeMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47132
diff
changeset
|
25 use crate::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 |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
34 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
|
35 /// 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
|
36 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
|
37 |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
38 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
|
39 |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
40 /// 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
|
41 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
|
42 |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
43 /// 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
|
44 /// `.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
|
45 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
|
46 |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
47 /// See on_disk::Header |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
48 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
|
49 |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
50 /// 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
|
51 pub(super) unreachable_bytes: u32, |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
52 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
53 |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
54 /// 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
|
55 /// 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
|
56 /// 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
|
57 /// 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
|
58 /// 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
|
59 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
|
60 |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
61 /// 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
|
62 /// for on-disk nodes that don’t actually have a `Cow` to borrow. |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
63 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
|
64 InMemory(&'tree HgPathBuf), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
65 OnDisk(&'on_disk HgPath), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
66 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
67 |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
68 pub(super) enum ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
69 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
|
70 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
|
71 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
72 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
77 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
82 |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
83 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
|
84 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
|
85 match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
86 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
|
87 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
|
88 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
89 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
90 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
91 |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
92 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
|
93 type Target = HgPath; |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
94 |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
95 fn deref(&self) -> &HgPath { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
96 match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
97 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
|
98 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
|
99 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
100 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
101 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
102 |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
103 impl Default for ChildNodes<'_> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
104 fn default() -> Self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
105 ChildNodes::InMemory(Default::default()) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
106 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
107 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
108 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
109 impl<'on_disk> ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
110 pub(super) fn as_ref<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
111 &'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
112 ) -> ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
113 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
114 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
|
115 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
|
116 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
117 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
118 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
119 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
|
120 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
121 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
|
122 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
|
123 } |
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 |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
126 fn make_mut( |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
127 &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
|
128 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
|
129 unreachable_bytes: &mut u32, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
130 ) -> Result< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
131 &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
|
132 DirstateV2ParseError, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
133 > { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
134 match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
135 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
|
136 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
|
137 *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
|
138 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
|
139 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
|
140 .iter() |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
141 .map(|node| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
142 Ok(( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
143 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
|
144 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
|
145 )) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
146 }) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
147 .collect::<Result<_, _>>()?; |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
148 *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
|
149 match self { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
150 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
|
151 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
|
152 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
153 } |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
154 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
155 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
156 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
157 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
158 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
|
159 pub(super) fn get( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
160 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
161 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
|
162 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
|
163 ) -> 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
|
164 match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
165 ChildNodesRef::InMemory(nodes) => Ok(nodes |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
166 .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
|
167 .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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 Err(e) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
174 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
|
175 // 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
|
176 // 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
|
177 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
|
178 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
179 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
180 }); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
181 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
|
182 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
|
183 }) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
184 } |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
185 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
186 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
187 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
188 /// Iterate in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
189 pub(super) fn iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
190 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
191 ) -> 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
|
192 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
|
193 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
|
194 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
|
195 ), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
196 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
|
197 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
|
198 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
199 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
200 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
201 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
202 /// Iterate in parallel in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
203 pub(super) fn par_iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
204 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
205 ) -> 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
|
206 { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
207 use rayon::prelude::*; |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 ), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
212 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
|
213 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
|
214 ), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
215 } |
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 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
|
219 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
220 ChildNodesRef::InMemory(nodes) => { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
221 let mut vec: Vec<_> = nodes |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
222 .iter() |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
223 .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
|
224 .collect(); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
225 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
|
226 match node { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
227 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
|
228 NodeRef::OnDisk(_) => unreachable!(), |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
229 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
230 } |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
231 // `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
|
232 // 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
|
233 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
|
234 vec |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
235 } |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
236 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
|
237 // 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
|
238 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
|
239 } |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
240 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
241 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
242 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
243 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
244 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
|
245 pub(super) fn full_path( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
246 &self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
247 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
|
248 ) -> Result<&'tree HgPath, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
249 match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
250 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
|
251 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
|
252 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
253 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
254 |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
255 /// 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
|
256 /// HgPath>` detached from `'tree` |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
257 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
|
258 &self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
259 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
|
260 ) -> 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
|
261 match self { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 }, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
266 NodeRef::OnDisk(node) => { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
267 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
|
268 } |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
269 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
270 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
271 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
272 pub(super) fn base_name( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
273 &self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
274 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
|
275 ) -> Result<&'tree HgPath, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
276 match self { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
277 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
|
278 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
|
279 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
280 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
281 |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
282 pub(super) fn children( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
283 &self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
284 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
|
285 ) -> 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
|
286 match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 } |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
291 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
292 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
293 |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
294 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
|
295 match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
296 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
|
297 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
|
298 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
299 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
300 |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
301 pub(super) fn copy_source( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
302 &self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
303 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
|
304 ) -> Result<Option<&'tree HgPath>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
305 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
306 NodeRef::InMemory(_path, node) => { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
307 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
|
308 } |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
309 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
|
310 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
311 } |
48493
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
312 /// 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
|
313 /// HgPath>` detached from `'tree` |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
314 pub(super) fn copy_source_borrowed( |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
315 &self, |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
316 on_disk: &'on_disk [u8], |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
317 ) -> 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
|
318 { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
319 Ok(match self { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
320 NodeRef::InMemory(_path, node) => { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 }) |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
325 } |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
326 NodeRef::OnDisk(node) => node |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
327 .copy_source(on_disk)? |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
328 .map(|source| BorrowedPath::OnDisk(source)), |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
329 }) |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48467
diff
changeset
|
330 } |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
331 |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
332 pub(super) fn entry( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
333 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
334 ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 } |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
339 NodeRef::OnDisk(node) => node.entry(), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
340 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
341 } |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
342 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
343 pub(super) fn state( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
344 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
345 ) -> Result<Option<EntryState>, DirstateV2ParseError> { |
48151
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48150
diff
changeset
|
346 Ok(self.entry()?.map(|e| e.state())) |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
347 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
348 |
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
349 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
|
350 &self, |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
351 ) -> 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
|
352 match self { |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
353 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
|
354 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
|
355 _ => None, |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
356 }), |
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
357 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
|
358 } |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
359 } |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
360 |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 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
|
365 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
366 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
|
367 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
368 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
369 |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
370 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
|
371 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
372 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
|
373 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
|
374 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
375 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
376 } |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
377 |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
378 /// Represents a file or a directory |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
379 #[derive(Default)] |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
380 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
|
381 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
|
382 |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
383 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
|
384 |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
385 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
|
386 |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
387 /// 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
|
388 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
|
389 |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
390 /// 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
|
391 /// 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
|
392 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
|
393 } |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
394 |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
395 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
|
396 Entry(DirstateEntry), |
48205
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48204
diff
changeset
|
397 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
|
398 None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
399 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
400 |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
405 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
406 |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 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
|
411 _ => false, |
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 |
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 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
|
416 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
|
417 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
|
418 _ => None, |
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 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
421 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
422 |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
423 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
|
424 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
|
425 Self { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
426 on_disk, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 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
|
431 unreachable_bytes: 0, |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
432 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
433 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
434 |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
435 #[timed] |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
436 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
|
437 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
|
438 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
|
439 metadata: &[u8], |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
440 ) -> Result<Self, DirstateError> { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
441 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
|
442 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
|
443 } else { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
444 Err(DirstateV2ParseError.into()) |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
445 } |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
446 } |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
447 |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
448 #[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
449 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
|
450 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
|
451 ) -> 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
|
452 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
|
453 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
|
454 return Ok((map, None)); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
455 } |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
456 |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
457 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
|
458 map.on_disk, |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
459 |path, entry, copy_source| { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
460 let tracked = entry.state().is_tracked(); |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
461 let node = Self::get_or_insert_node( |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
462 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
|
463 &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
|
464 &mut map.root, |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
465 path, |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
466 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
|
467 |ancestor| { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
468 if tracked { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
469 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
|
470 } |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
471 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
|
472 }, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
473 )?; |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
474 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
|
475 !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
|
476 "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
|
477 ); |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
478 assert!( |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
479 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
|
480 "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
|
481 ); |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 } |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
488 Ok(()) |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
489 }, |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
490 )?; |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
491 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
|
492 |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
493 Ok((map, parents)) |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
494 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
495 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
496 /// 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
|
497 /// 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
|
498 /// 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
|
499 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
|
500 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
|
501 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
|
502 } |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
503 |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
504 fn get_node<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
505 &'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
506 path: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
507 ) -> 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
|
508 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
|
509 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
|
510 let mut component = |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
511 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
|
512 loop { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
513 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
|
514 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
|
515 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
|
516 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
|
517 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
518 return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
519 } |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
520 } else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
521 return Ok(None); |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
522 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
523 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
524 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
525 |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
526 /// 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
|
527 /// |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
528 /// This takes `root` instead of `&mut self` so that callers can mutate |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
529 /// other fields while the returned borrow is still valid |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
530 fn get_node_mut<'tree>( |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
531 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
|
532 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
|
533 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
|
534 path: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
535 ) -> 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
|
536 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
|
537 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
|
538 let mut component = |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
539 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
|
540 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
|
541 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
|
542 .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
|
543 .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
|
544 { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
545 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
|
546 component = next_component; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
547 children = &mut child.children; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
548 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
549 return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
550 } |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
551 } else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
552 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
|
553 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
554 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
555 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
556 |
47479
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
557 pub(super) fn get_or_insert<'tree, 'path>( |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
558 &'tree mut self, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
559 path: &HgPath, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
560 ) -> Result<&'tree mut Node<'on_disk>, DirstateV2ParseError> { |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
561 Self::get_or_insert_node( |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
562 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
|
563 &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
|
564 &mut self.root, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
565 path, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
566 WithBasename::to_cow_owned, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
567 |_| {}, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
568 ) |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
569 } |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
570 |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
571 fn get_or_insert_node<'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
|
572 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
|
573 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
|
574 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
|
575 path: &'path HgPath, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
576 to_cow: impl Fn( |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
577 WithBasename<&'path HgPath>, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
578 ) -> 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
|
579 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
|
580 ) -> 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
|
581 let mut child_nodes = root; |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
582 let mut inclusive_ancestor_paths = |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
583 WithBasename::inclusive_ancestors_of(path); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
584 let mut ancestor_path = inclusive_ancestor_paths |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
585 .next() |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
586 .expect("expected at least one inclusive ancestor"); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
587 loop { |
47130
04bcba539c96
dirstate-tree: Avoid BTreeMap double-lookup when inserting a dirstate entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47127
diff
changeset
|
588 // TODO: can we avoid allocating an owned key in cases where the |
04bcba539c96
dirstate-tree: Avoid BTreeMap double-lookup when inserting a dirstate entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47127
diff
changeset
|
589 // map already contains that key, without introducing double |
04bcba539c96
dirstate-tree: Avoid BTreeMap double-lookup when inserting a dirstate entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47127
diff
changeset
|
590 // lookup? |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
591 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
|
592 .make_mut(on_disk, unreachable_bytes)? |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
593 .entry(to_cow(ancestor_path)) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
594 .or_default(); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
595 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
|
596 each_ancestor(child_node); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
597 ancestor_path = next; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
598 child_nodes = &mut child_node.children; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
599 } else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
600 return Ok(child_node); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
601 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
602 } |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
603 } |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
604 |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
605 fn add_or_remove_file( |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
606 &mut self, |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
607 path: &HgPath, |
48048
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
608 old_state: Option<EntryState>, |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
609 new_entry: DirstateEntry, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
610 ) -> Result<(), DirstateV2ParseError> { |
48048
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
611 let had_entry = old_state.is_some(); |
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
612 let was_tracked = old_state.map_or(false, |s| s.is_tracked()); |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
613 let tracked_count_increment = |
48048
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
614 match (was_tracked, new_entry.state().is_tracked()) { |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
615 (false, true) => 1, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
616 (true, false) => -1, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
617 _ => 0, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
618 }; |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
619 |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
620 let node = Self::get_or_insert_node( |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
621 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
|
622 &mut self.unreachable_bytes, |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
623 &mut self.root, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
624 path, |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
625 WithBasename::to_cow_owned, |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
626 |ancestor| { |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
627 if !had_entry { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
628 ancestor.descendants_with_entry_count += 1; |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
629 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
630 |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
631 // We can’t use `+= increment` because the counter is unsigned, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
632 // and we want debug builds to detect accidental underflow |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
633 // through zero |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
634 match tracked_count_increment { |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
635 1 => ancestor.tracked_descendants_count += 1, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
636 -1 => ancestor.tracked_descendants_count -= 1, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
637 _ => {} |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
638 } |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
639 }, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
640 )?; |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
641 if !had_entry { |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
642 self.nodes_with_entry_count += 1 |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
643 } |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
644 node.data = NodeData::Entry(new_entry); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
645 Ok(()) |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
646 } |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
647 |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
648 fn iter_nodes<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
649 &'tree self, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
650 ) -> impl Iterator< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
651 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
|
652 > + 'tree { |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
653 // Depth first tree traversal. |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
654 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
655 // 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
|
656 // this would look like: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
657 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
658 // ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
659 // fn traverse_children( |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
660 // children: &ChildNodes, |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
661 // each: &mut impl FnMut(&Node), |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
662 // ) { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
663 // for child in children.values() { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
664 // traverse_children(&child.children, each); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
665 // each(child); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
666 // } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
667 // } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
668 // ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
669 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
670 // 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
|
671 // call stack. Use an explicit stack instead: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
672 let mut stack = Vec::new(); |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
673 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
|
674 std::iter::from_fn(move || { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
675 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
|
676 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
|
677 Ok(children) => children, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
678 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
|
679 }; |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
680 // Pseudo-recursion |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
681 let new_iter = children.iter(); |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
682 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
|
683 stack.push((child_node, old_iter)); |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
684 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
685 // 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
|
686 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
|
687 // "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
|
688 // explicit stack |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
689 iter = next_iter; |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
690 |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
691 Some(Ok(child_node)) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
692 } else { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
693 // 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
|
694 None |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
695 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
696 }) |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
697 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
698 |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
699 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
|
700 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
|
701 *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
|
702 } |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
703 } |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
704 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
705 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
706 /// 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
|
707 /// |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
708 /// 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
|
709 /// 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
|
710 /// 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
|
711 /// `Result`. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
712 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
|
713 iter: I, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
714 f: F, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
715 ) -> 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
|
716 where |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
717 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
|
718 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
|
719 { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
720 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
|
721 Ok(node) => f(node).transpose(), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
722 Err(e) => Some(Err(e)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
723 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
724 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
725 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
726 impl OwningDirstateMap { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
727 pub fn clear(&mut self) { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
728 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
729 map.root = Default::default(); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
730 map.nodes_with_entry_count = 0; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
731 map.nodes_with_copy_source_count = 0; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
732 }); |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
733 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
734 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
735 pub fn set_entry( |
48062
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
736 &mut self, |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
737 filename: &HgPath, |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
738 entry: DirstateEntry, |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
739 ) -> Result<(), DirstateV2ParseError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
740 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
741 map.get_or_insert(&filename)?.data = NodeData::Entry(entry); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
742 Ok(()) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
743 }) |
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
|
744 } |
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
|
745 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
746 pub fn add_file( |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
747 &mut self, |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
748 filename: &HgPath, |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
749 entry: DirstateEntry, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
750 ) -> Result<(), DirstateError> { |
48048
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
751 let old_state = self.get(filename)?.map(|e| e.state()); |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
752 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
753 Ok(map.add_or_remove_file(filename, old_state, entry)?) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
754 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
755 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
756 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
757 pub fn remove_file( |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
758 &mut self, |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
759 filename: &HgPath, |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
760 in_merge: bool, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
761 ) -> Result<(), DirstateError> { |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
762 let old_entry_opt = self.get(filename)?; |
48048
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
763 let old_state = old_entry_opt.map(|e| e.state()); |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
764 let mut size = 0; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
765 if in_merge { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
766 // XXX we should not be able to have 'm' state and 'FROM_P2' if not |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
767 // during a merge. So I (marmoute) am not sure we need the |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
768 // conditionnal at all. Adding double checking this with assert |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
769 // would be nice. |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
770 if let Some(old_entry) = old_entry_opt { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
771 // backup the previous state |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
772 if old_entry.state() == EntryState::Merged { |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
773 size = SIZE_NON_NORMAL; |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
774 } else if old_entry.state() == EntryState::Normal |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
775 && old_entry.size() == SIZE_FROM_OTHER_PARENT |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
776 { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
777 // other parent |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
778 size = SIZE_FROM_OTHER_PARENT; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
779 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
780 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
781 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
782 if size == 0 { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
783 self.copy_map_remove(filename)?; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
784 } |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
785 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
786 let entry = DirstateEntry::new_removed(size); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
787 Ok(map.add_or_remove_file(filename, old_state, entry)?) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
788 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
789 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
790 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
791 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
|
792 &mut self, |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
793 filename: &HgPath, |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
794 ) -> Result<(), DirstateError> { |
48048
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
795 let was_tracked = self |
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
796 .get(filename)? |
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
797 .map_or(false, |e| e.state().is_tracked()); |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
798 struct Dropped { |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
799 was_tracked: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
800 had_entry: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
801 had_copy_source: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
802 } |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
803 |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
804 /// 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
|
805 /// |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
806 /// * `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
|
807 /// * `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
|
808 /// 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
|
809 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 ) -> 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
|
815 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
|
816 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
|
817 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
|
818 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
|
819 { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
820 node |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
821 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
822 return Ok(None); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
823 }; |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
824 let dropped; |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
825 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
|
826 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
|
827 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
|
828 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
|
829 &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
|
830 rest, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
831 )? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
832 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
|
833 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
|
834 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
|
835 .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
|
836 .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
|
837 .expect( |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
838 "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
|
839 ); |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
840 } |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
841 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
|
842 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
|
843 .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
|
844 .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
|
845 .expect( |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
48825
diff
changeset
|
846 "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
|
847 ); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
848 } |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
849 |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
850 // 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
|
851 // child node |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
852 if removed { |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
853 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
|
854 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
|
855 } |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
856 } |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
857 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
858 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
|
859 } |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
860 } else { |
48827
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
48826
diff
changeset
|
861 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
|
862 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
|
863 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
|
864 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
|
865 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
|
866 } |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
867 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
|
868 DirstateMap::count_dropped_path(unreachable_bytes, source); |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
869 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
|
870 } |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
871 dropped = Dropped { |
48827
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
48826
diff
changeset
|
872 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
|
873 had_entry, |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
874 had_copy_source: node.copy_source.take().is_some(), |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
875 }; |
47204
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
876 } |
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
877 // 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
|
878 // 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
|
879 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
|
880 && 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
|
881 && 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
|
882 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
|
883 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
|
884 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
|
885 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
|
886 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
|
887 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
|
888 ) |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
889 } |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
890 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
|
891 } |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
892 |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
893 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
894 if let Some((dropped, _removed)) = recur( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
895 map.on_disk, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
896 &mut map.unreachable_bytes, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
897 &mut map.root, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
898 filename, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
899 )? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
900 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
|
901 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
|
902 .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
|
903 .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
|
904 .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
|
905 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
906 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
|
907 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
|
908 .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
|
909 .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
|
910 .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
|
911 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
912 } else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
913 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
|
914 } |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
915 Ok(()) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
916 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
917 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
918 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
919 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
|
920 &mut self, |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
921 directory: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
922 ) -> Result<bool, DirstateError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
923 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
924 if let Some(node) = map.get_node(directory)? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
925 // 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
|
926 // nodes, and is therefore a directory. |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
927 let state = node.state()?; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
928 Ok(state.is_none() && node.tracked_descendants_count() > 0) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
929 } else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
930 Ok(false) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
931 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
932 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
933 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
934 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
935 pub fn has_dir( |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
936 &mut self, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
937 directory: &HgPath, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
938 ) -> Result<bool, DirstateError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
939 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
940 if let Some(node) = map.get_node(directory)? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
941 // 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
|
942 // nodes, and is therefore a directory. |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
943 let state = node.state()?; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
944 Ok(state.is_none() && node.descendants_with_entry_count() > 0) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
945 } else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
946 Ok(false) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
947 } |
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 |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
951 #[timed] |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
952 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
|
953 &self, |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
954 parents: DirstateParents, |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
955 ) -> 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
|
956 let map = self.get_map(); |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
957 // 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
|
958 // reallocations |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
959 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
|
960 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
|
961 let node = node?; |
48440
434de12918fd
dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48271
diff
changeset
|
962 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
|
963 size += packed_entry_size( |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
964 node.full_path(map.on_disk)?, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
965 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
|
966 ); |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
967 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
968 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
969 |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
970 let mut packed = Vec::with_capacity(size); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
971 packed.extend(parents.as_bytes()); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
972 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
973 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
|
974 let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
975 if let Some(entry) = node.entry()? { |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
976 pack_entry( |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
977 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
|
978 &entry, |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
979 node.copy_source(map.on_disk)?, |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
980 &mut packed, |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
981 ); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
982 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
983 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
984 Ok(packed) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
985 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
986 |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
987 /// 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
|
988 /// 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
|
989 /// `map.on_disk` (true), instead of written to a new data file |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
990 /// (false). |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
991 #[timed] |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
992 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
|
993 &self, |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
994 can_append: bool, |
48467
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48462
diff
changeset
|
995 ) -> Result<(Vec<u8>, on_disk::TreeMetadata, bool), DirstateError> { |
48462
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48440
diff
changeset
|
996 let map = self.get_map(); |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
997 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
|
998 } |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
999 |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1000 /// `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
|
1001 /// 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
|
1002 /// 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
|
1003 /// we need to borrow from `Self`. |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1004 pub fn with_status<R>( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1005 &mut self, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1006 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
|
1007 root_dir: PathBuf, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1008 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
|
1009 options: StatusOptions, |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1010 callback: impl for<'r> FnOnce( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1011 Result<(DirstateStatus<'r>, Vec<PatternFileWarning>), StatusError>, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1012 ) -> R, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1013 ) -> R { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1014 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1015 callback(super::status::status( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1016 map, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1017 matcher, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1018 root_dir, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1019 ignore_files, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1020 options, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1021 )) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1022 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1023 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1024 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1025 pub fn copy_map_len(&self) -> usize { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1026 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1027 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
|
1028 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1029 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1030 pub fn copy_map_iter(&self) -> CopyMapIter<'_> { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1031 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1032 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
|
1033 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
|
1034 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
|
1035 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1036 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1037 }) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
1038 })) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1039 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1040 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1041 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
|
1042 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1043 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1044 ) -> Result<bool, DirstateV2ParseError> { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1045 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1046 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
|
1047 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
|
1048 } else { |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
1049 false |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1050 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1051 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1052 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1053 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
|
1054 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1055 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1056 ) -> Result<Option<&HgPath>, DirstateV2ParseError> { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1057 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1058 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
|
1059 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
|
1060 return Ok(Some(source)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1061 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1062 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1063 Ok(None) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1064 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1065 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1066 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
|
1067 &mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1068 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1069 ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1070 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1071 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
|
1072 let unreachable_bytes = &mut map.unreachable_bytes; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1073 Ok(DirstateMap::get_node_mut( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1074 map.on_disk, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1075 unreachable_bytes, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1076 &mut map.root, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1077 key, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1078 )? |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1079 .and_then(|node| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1080 if let Some(source) = &node.copy_source { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1081 *count -= 1; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1082 DirstateMap::count_dropped_path(unreachable_bytes, source); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1083 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1084 node.copy_source.take().map(Cow::into_owned) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1085 })) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1086 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1087 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1088 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1089 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
|
1090 &mut self, |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1091 key: HgPathBuf, |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1092 value: HgPathBuf, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1093 ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1094 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1095 let node = DirstateMap::get_or_insert_node( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1096 map.on_disk, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1097 &mut map.unreachable_bytes, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1098 &mut map.root, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1099 &key, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1100 WithBasename::to_cow_owned, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1101 |_ancestor| {}, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1102 )?; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1103 if node.copy_source.is_none() { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1104 map.nodes_with_copy_source_count += 1 |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1105 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1106 Ok(node.copy_source.replace(value.into()).map(Cow::into_owned)) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1107 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1108 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1109 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1110 pub fn len(&self) -> usize { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1111 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1112 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
|
1113 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1114 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1115 pub fn contains_key( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1116 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1117 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1118 ) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1119 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
|
1120 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1121 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1122 pub fn get( |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1123 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1124 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1125 ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1126 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1127 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
|
1128 node.entry()? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1129 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1130 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1131 }) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1132 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1133 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1134 pub fn iter(&self) -> StateMapIter<'_> { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1135 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1136 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
|
1137 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
|
1138 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
|
1139 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1140 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1141 }) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
1142 })) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1143 } |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1144 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1145 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
|
1146 &mut self, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1147 ) -> Result< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1148 Box< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1149 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
|
1150 + Send |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1151 + '_, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1152 >, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1153 DirstateError, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1154 > { |
48825
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48493
diff
changeset
|
1155 let map = self.get_map(); |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1156 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
|
1157 Ok(Box::new(filter_map_results( |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1158 map.iter_nodes(), |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1159 move |node| { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1160 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
|
1161 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
|
1162 } else { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1163 None |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1164 }) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1165 }, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1166 ))) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1167 } |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1168 |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1169 pub fn debug_iter( |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1170 &self, |
48045
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
1171 all: bool, |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1172 ) -> Box< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1173 dyn Iterator< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1174 Item = Result< |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1175 (&HgPath, (u8, i32, i32, i32)), |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1176 DirstateV2ParseError, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1177 >, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1178 > + Send |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1179 + '_, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1180 > { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1181 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1182 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
|
1183 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
|
1184 entry.debug_tuple() |
48045
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
1185 } else if !all { |
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
1186 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
|
1187 } 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
|
1188 (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
|
1189 } else { |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1190 (b' ', 0, -1, -1) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1191 }; |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
1192 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
|
1193 })) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1194 } |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1195 } |