author | Simon Sapin <simon.sapin@octobus.net> |
Fri, 17 Sep 2021 13:33:45 +0200 | |
changeset 48044 | f2a9db29cb2d |
parent 47692 | e5fb14a07866 |
child 48045 | 357307feaf61 |
permissions | -rw-r--r-- |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1 |
use bytes_cast::BytesCast; |
47132
c92e63762573
dirstate-tree: Add #[timed] attribute to `status` and `DirstateMap::read`
Simon Sapin <simon.sapin@octobus.net>
parents:
47130
diff
changeset
|
2 |
use micro_timer::timed; |
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
3 |
use std::borrow::Cow; |
47133
15395fd8ab28
dirstate-tree: Use HashMap instead of BTreeMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47132
diff
changeset
|
4 |
use std::convert::TryInto; |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
5 |
use std::path::PathBuf; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
6 |
|
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
7 |
use super::on_disk; |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
8 |
use super::on_disk::DirstateV2ParseError; |
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; |
47115
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47114
diff
changeset
|
13 |
use crate::dirstate::parsers::Timestamp; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
14 |
use crate::dirstate::MTIME_UNSET; |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
15 |
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
|
16 |
use crate::dirstate::SIZE_NON_NORMAL; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
17 |
use crate::dirstate::V1_RANGEMASK; |
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::CopyMapIter; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
21 |
use crate::DirstateEntry; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
22 |
use crate::DirstateError; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
23 |
use crate::DirstateParents; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
24 |
use crate::DirstateStatus; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
25 |
use crate::EntryState; |
47133
15395fd8ab28
dirstate-tree: Use HashMap instead of BTreeMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47132
diff
changeset
|
26 |
use crate::FastHashMap; |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
27 |
use crate::PatternFileWarning; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
28 |
use crate::StateMapIter; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
29 |
use crate::StatusError; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
30 |
use crate::StatusOptions; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
31 |
|
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
32 |
/// 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
|
33 |
/// 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
|
34 |
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
|
35 |
|
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
36 |
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
|
37 |
/// 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
|
38 |
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
|
39 |
|
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
40 |
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
|
41 |
|
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
42 |
/// 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
|
43 |
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
|
44 |
|
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
45 |
/// 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
|
46 |
/// `.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
|
47 |
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
|
48 |
|
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
49 |
/// See on_disk::Header |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47358
diff
changeset
|
50 |
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
|
51 |
|
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
52 |
/// 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
|
53 |
pub(super) unreachable_bytes: u32, |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
54 |
} |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
55 |
|
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
56 |
/// 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
|
57 |
/// 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
|
58 |
/// 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
|
59 |
/// 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
|
60 |
/// 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
|
61 |
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
|
62 |
|
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
63 |
/// 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
|
64 |
/// 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
|
65 |
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
|
66 |
InMemory(&'tree HgPathBuf), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
67 |
OnDisk(&'on_disk HgPath), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
68 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
69 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
70 |
pub(super) enum ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
74 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
79 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
84 |
|
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
88 |
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
|
89 |
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
|
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 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
93 |
|
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
94 |
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
|
95 |
type Target = HgPath; |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
96 |
|
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
97 |
fn deref(&self) -> &HgPath { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
98 |
match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
99 |
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
|
100 |
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
|
101 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
102 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
103 |
} |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
104 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
105 |
impl Default for ChildNodes<'_> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
106 |
fn default() -> Self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
107 |
ChildNodes::InMemory(Default::default()) |
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 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
110 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
111 |
impl<'on_disk> ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
112 |
pub(super) fn as_ref<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
113 |
&'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
114 |
) -> ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
115 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
119 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
120 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
121 |
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
|
122 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
126 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
127 |
|
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
128 |
fn make_mut( |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
129 |
&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
|
130 |
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
|
131 |
unreachable_bytes: &mut u32, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
132 |
) -> Result< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
133 |
&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
|
134 |
DirstateV2ParseError, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
135 |
> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
136 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
*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
|
140 |
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
|
141 |
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
|
142 |
.iter() |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
143 |
.map(|node| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
144 |
Ok(( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
)) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
148 |
}) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
149 |
.collect::<Result<_, _>>()?; |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
150 |
*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
|
151 |
match self { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
} |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
155 |
} |
47341
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 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
159 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
160 |
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
|
161 |
pub(super) fn get( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
162 |
&self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
) -> 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
|
166 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
167 |
ChildNodesRef::InMemory(nodes) => Ok(nodes |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
168 |
.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
|
169 |
.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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
Err(e) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
176 |
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
|
177 |
// 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
|
178 |
// 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
|
179 |
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
|
180 |
} |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
181 |
} |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
182 |
}); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
}) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
186 |
} |
47341
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 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
189 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
190 |
/// Iterate in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
191 |
pub(super) fn iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
192 |
&self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
193 |
) -> 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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
198 |
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
|
199 |
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
|
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 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
203 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
204 |
/// Iterate in parallel in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
205 |
pub(super) fn par_iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
206 |
&self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
207 |
) -> 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
|
208 |
{ |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
209 |
use rayon::prelude::*; |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
210 |
match self { |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
211 |
ChildNodesRef::InMemory(nodes) => 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
|
212 |
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
|
213 |
), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
214 |
ChildNodesRef::OnDisk(nodes) => 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
|
215 |
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
|
216 |
), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
217 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
218 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
219 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
220 |
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
|
221 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
222 |
ChildNodesRef::InMemory(nodes) => { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
223 |
let mut vec: Vec<_> = nodes |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
224 |
.iter() |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
225 |
.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
|
226 |
.collect(); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
227 |
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
|
228 |
match node { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
229 |
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
|
230 |
NodeRef::OnDisk(_) => unreachable!(), |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
231 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
232 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
233 |
// `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
|
234 |
// 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
|
235 |
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
|
236 |
vec |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
237 |
} |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
238 |
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
|
239 |
// 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
|
240 |
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
|
241 |
} |
47341
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 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
245 |
|
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
246 |
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
|
247 |
pub(super) fn full_path( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
248 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
249 |
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
|
250 |
) -> Result<&'tree HgPath, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
251 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
255 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
256 |
|
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
257 |
/// 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
|
258 |
/// HgPath>` detached from `'tree` |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
259 |
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
|
260 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
261 |
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
|
262 |
) -> 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
|
263 |
match self { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
}, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
268 |
NodeRef::OnDisk(node) => { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
269 |
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
|
270 |
} |
47343
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 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
273 |
|
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
274 |
pub(super) fn base_name( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
275 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
276 |
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
|
277 |
) -> Result<&'tree HgPath, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
278 |
match self { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
279 |
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
|
280 |
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
|
281 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
282 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
283 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
284 |
pub(super) fn children( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
285 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
286 |
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
|
287 |
) -> 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
|
288 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
} |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
293 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
294 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
295 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
296 |
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
|
297 |
match self { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
301 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
302 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
303 |
pub(super) fn copy_source( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
304 |
&self, |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
305 |
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
|
306 |
) -> Result<Option<&'tree HgPath>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
307 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
308 |
NodeRef::InMemory(_path, node) => { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
309 |
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
|
310 |
} |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
311 |
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
|
312 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
313 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
314 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
315 |
pub(super) fn entry( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
316 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
317 |
) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
} |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
322 |
NodeRef::OnDisk(node) => node.entry(), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
323 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
324 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
325 |
|
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
326 |
pub(super) fn state( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
327 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
328 |
) -> Result<Option<EntryState>, DirstateV2ParseError> { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
329 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
330 |
NodeRef::InMemory(_path, node) => { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
331 |
Ok(node.data.as_entry().map(|entry| entry.state())) |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
332 |
} |
47345
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47344
diff
changeset
|
333 |
NodeRef::OnDisk(node) => node.state(), |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
334 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
335 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
336 |
|
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
337 |
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
|
338 |
&self, |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
339 |
) -> Option<&'tree on_disk::Timestamp> { |
47355
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
340 |
match self { |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
341 |
NodeRef::InMemory(_path, node) => match &node.data { |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
342 |
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
|
343 |
_ => None, |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
344 |
}, |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
345 |
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
|
346 |
} |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
347 |
} |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47354
diff
changeset
|
348 |
|
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
349 |
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
|
350 |
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
|
351 |
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
|
352 |
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
|
353 |
} |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
354 |
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
|
355 |
} |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
356 |
} |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
357 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
358 |
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
|
359 |
match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
360 |
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
|
361 |
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
|
362 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
363 |
} |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
364 |
} |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
365 |
|
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
366 |
/// Represents a file or a directory |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
367 |
#[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
|
368 |
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
|
369 |
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
|
370 |
|
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
371 |
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
|
372 |
|
47139
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
373 |
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
|
374 |
|
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
375 |
/// 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
|
376 |
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
|
377 |
|
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
378 |
/// 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
|
379 |
/// 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
|
380 |
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
|
381 |
} |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
382 |
|
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
383 |
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
|
384 |
Entry(DirstateEntry), |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
385 |
CachedDirectory { mtime: on_disk::Timestamp }, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
386 |
None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
387 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
388 |
|
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
389 |
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
|
390 |
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
|
391 |
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
|
392 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
393 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
394 |
|
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
395 |
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
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
_ => false, |
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 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
402 |
|
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
_ => None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
407 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
408 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
409 |
} |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
410 |
|
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
411 |
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
|
412 |
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
|
413 |
Self { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
414 |
on_disk, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
415 |
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
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
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
|
420 |
} |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
421 |
} |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
422 |
|
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
423 |
#[timed] |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
metadata: &[u8], |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
428 |
) -> Result<Self, DirstateError> { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
} else { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
432 |
Err(DirstateV2ParseError.into()) |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
433 |
} |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
434 |
} |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
435 |
|
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
436 |
#[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
437 |
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
|
438 |
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
|
439 |
) -> 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
|
440 |
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
|
441 |
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
|
442 |
return Ok((map, None)); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
443 |
} |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
444 |
|
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
445 |
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
|
446 |
map.on_disk, |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
447 |
|path, entry, copy_source| { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
&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
|
452 |
&mut map.root, |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
453 |
path, |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
454 |
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
|
455 |
|ancestor| { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
456 |
if tracked { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
457 |
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
|
458 |
} |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
459 |
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
|
460 |
}, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
461 |
)?; |
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
462 |
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
|
463 |
!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
|
464 |
"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
|
465 |
); |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
466 |
assert!( |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
467 |
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
|
468 |
"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
|
469 |
); |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
476 |
Ok(()) |
47137
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 |
)?; |
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
479 |
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
|
480 |
|
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
481 |
Ok((map, parents)) |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
482 |
} |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
483 |
|
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
484 |
/// 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
|
485 |
/// 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
|
486 |
/// 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
|
487 |
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
|
488 |
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
|
489 |
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
|
490 |
} |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
491 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
492 |
fn get_node<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
493 |
&'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
494 |
path: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
495 |
) -> 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
|
496 |
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
|
497 |
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
|
498 |
let mut component = |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
499 |
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
|
500 |
loop { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
501 |
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
|
502 |
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
|
503 |
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
|
504 |
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
|
505 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
506 |
return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
507 |
} |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
508 |
} else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
509 |
return Ok(None); |
47113
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
510 |
} |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
511 |
} |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
512 |
} |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
513 |
|
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
514 |
/// 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
|
515 |
/// |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
516 |
/// 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
|
517 |
/// 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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
path: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
523 |
) -> 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
|
524 |
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
|
525 |
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
|
526 |
let mut component = |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
.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
|
531 |
.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
|
532 |
{ |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
533 |
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
|
534 |
component = next_component; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
535 |
children = &mut child.children; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
536 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
537 |
return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
538 |
} |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
539 |
} else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
540 |
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
|
541 |
} |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
542 |
} |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
543 |
} |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
544 |
|
47479
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
545 |
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
|
546 |
&'tree mut self, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
547 |
path: &HgPath, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
548 |
) -> 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
|
549 |
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
|
550 |
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
|
551 |
&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
|
552 |
&mut self.root, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
553 |
path, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
554 |
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
|
555 |
|_| {}, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
556 |
) |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
557 |
} |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47415
diff
changeset
|
558 |
|
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
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
|
563 |
path: &'path HgPath, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
564 |
to_cow: impl Fn( |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
565 |
WithBasename<&'path HgPath>, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
566 |
) -> 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
|
567 |
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
|
568 |
) -> 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
|
569 |
let mut child_nodes = root; |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
570 |
let mut inclusive_ancestor_paths = |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
571 |
WithBasename::inclusive_ancestors_of(path); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
572 |
let mut ancestor_path = inclusive_ancestor_paths |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
573 |
.next() |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
574 |
.expect("expected at least one inclusive ancestor"); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
575 |
loop { |
47130
04bcba539c96
dirstate-tree: Avoid BTreeMap double-lookup when inserting a dirstate entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47127
diff
changeset
|
576 |
// 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
|
577 |
// 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
|
578 |
// lookup? |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
579 |
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
|
580 |
.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
|
581 |
.entry(to_cow(ancestor_path)) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
582 |
.or_default(); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
583 |
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
|
584 |
each_ancestor(child_node); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
585 |
ancestor_path = next; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
586 |
child_nodes = &mut child_node.children; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
587 |
} else { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
588 |
return Ok(child_node); |
47111
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
589 |
} |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
590 |
} |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
591 |
} |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
592 |
|
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
593 |
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
|
594 |
&mut self, |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
595 |
path: &HgPath, |
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
596 |
old_state: EntryState, |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
597 |
new_entry: DirstateEntry, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
598 |
) -> Result<(), DirstateV2ParseError> { |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
599 |
let had_entry = old_state != EntryState::Unknown; |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
600 |
let tracked_count_increment = |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
601 |
match (old_state.is_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
|
602 |
(false, true) => 1, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
603 |
(true, false) => -1, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
604 |
_ => 0, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
605 |
}; |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
606 |
|
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
607 |
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
|
608 |
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
|
609 |
&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
|
610 |
&mut self.root, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
611 |
path, |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
612 |
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
|
613 |
|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
|
614 |
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
|
615 |
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
|
616 |
} |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
617 |
|
47134
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
618 |
// 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
|
619 |
// 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
|
620 |
// through zero |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
621 |
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
|
622 |
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
|
623 |
-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
|
624 |
_ => {} |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
625 |
} |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47133
diff
changeset
|
626 |
}, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
627 |
)?; |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
628 |
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
|
629 |
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
|
630 |
} |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
631 |
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
|
632 |
Ok(()) |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
633 |
} |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
634 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
635 |
fn iter_nodes<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
636 |
&'tree self, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
637 |
) -> impl Iterator< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
638 |
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
|
639 |
> + 'tree { |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
640 |
// Depth first tree traversal. |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
641 |
// |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
642 |
// 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
|
643 |
// this would look like: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
644 |
// |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
645 |
// ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
646 |
// fn traverse_children( |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
647 |
// children: &ChildNodes, |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
648 |
// each: &mut impl FnMut(&Node), |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
649 |
// ) { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
650 |
// for child in children.values() { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
651 |
// traverse_children(&child.children, each); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
652 |
// each(child); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
653 |
// } |
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 |
// ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
656 |
// |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
657 |
// 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
|
658 |
// call stack. Use an explicit stack instead: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
659 |
let mut stack = Vec::new(); |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
660 |
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
|
661 |
std::iter::from_fn(move || { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
662 |
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
|
663 |
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
|
664 |
Ok(children) => children, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
665 |
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
|
666 |
}; |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
667 |
// Pseudo-recursion |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
668 |
let new_iter = children.iter(); |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
669 |
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
|
670 |
stack.push((child_node, old_iter)); |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
671 |
} |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
672 |
// 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
|
673 |
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
|
674 |
// "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
|
675 |
// explicit stack |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
676 |
iter = next_iter; |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
677 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
678 |
Some(Ok(child_node)) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
679 |
} else { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
680 |
// 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
|
681 |
None |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
682 |
} |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
683 |
}) |
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 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
686 |
fn clear_known_ambiguous_mtimes( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
687 |
&mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
688 |
paths: &[impl AsRef<HgPath>], |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
689 |
) -> Result<(), DirstateV2ParseError> { |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
690 |
for path in paths { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
691 |
if let Some(node) = Self::get_node_mut( |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
692 |
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
|
693 |
&mut self.unreachable_bytes, |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
694 |
&mut self.root, |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
695 |
path.as_ref(), |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
696 |
)? { |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
697 |
if let NodeData::Entry(entry) = &mut node.data { |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
698 |
entry.clear_mtime(); |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
699 |
} |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
700 |
} |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
701 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
702 |
Ok(()) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
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 |
/// Return a faillilble iterator of full paths of nodes that have an |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
706 |
/// `entry` for which the given `predicate` returns true. |
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 |
/// Fallibility means that each iterator item is a `Result`, which may |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
709 |
/// indicate a parse error of the on-disk dirstate-v2 format. Such errors |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
710 |
/// should only happen if Mercurial is buggy or a repository is corrupted. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
711 |
fn filter_full_paths<'tree>( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
712 |
&'tree self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
713 |
predicate: impl Fn(&DirstateEntry) -> bool + 'tree, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
714 |
) -> impl Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + 'tree |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
715 |
{ |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
716 |
filter_map_results(self.iter_nodes(), move |node| { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
717 |
if let Some(entry) = node.entry()? { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
718 |
if predicate(&entry) { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
719 |
return Ok(Some(node.full_path(self.on_disk)?)); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
720 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
721 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
722 |
Ok(None) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
723 |
}) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
724 |
} |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
725 |
|
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
726 |
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
|
727 |
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
|
728 |
*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
|
729 |
} |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
730 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
731 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
732 |
|
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
733 |
/// 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
|
734 |
/// |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
735 |
/// 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
|
736 |
/// 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
|
737 |
/// 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
|
738 |
/// `Result`. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
739 |
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
|
740 |
iter: I, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
741 |
f: F, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
742 |
) -> 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
|
743 |
where |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
744 |
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
|
745 |
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
|
746 |
{ |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
747 |
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
|
748 |
Ok(node) => f(node).transpose(), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
749 |
Err(e) => Some(Err(e)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
750 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
751 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
752 |
|
47137
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
753 |
impl<'on_disk> super::dispatch::DirstateMapMethods for DirstateMap<'on_disk> { |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
754 |
fn clear(&mut self) { |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
755 |
self.root = Default::default(); |
47117
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
756 |
self.nodes_with_entry_count = 0; |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
757 |
self.nodes_with_copy_source_count = 0; |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
758 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
759 |
|
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
|
760 |
fn set_v1(&mut self, filename: &HgPath, entry: DirstateEntry) { |
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
|
761 |
let node = |
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
|
762 |
self.get_or_insert(&filename).expect("no parse error in v1"); |
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
|
763 |
node.data = NodeData::Entry(entry); |
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
|
764 |
node.children = ChildNodes::default(); |
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
|
765 |
node.copy_source = None; |
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
|
766 |
node.descendants_with_entry_count = 0; |
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
|
767 |
node.tracked_descendants_count = 0; |
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
|
768 |
} |
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
|
769 |
|
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
770 |
fn add_file( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
771 |
&mut self, |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
772 |
filename: &HgPath, |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
773 |
entry: DirstateEntry, |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
774 |
added: bool, |
47527
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
775 |
merged: bool, |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
776 |
from_p2: bool, |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
777 |
possibly_dirty: bool, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
778 |
) -> Result<(), DirstateError> { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
779 |
let state; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
780 |
let size; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
781 |
let mtime; |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
782 |
if added { |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
783 |
assert!(!possibly_dirty); |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
784 |
assert!(!from_p2); |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
785 |
state = EntryState::Added; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
786 |
size = SIZE_NON_NORMAL; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
787 |
mtime = MTIME_UNSET; |
47527
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
788 |
} else if merged { |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
789 |
assert!(!possibly_dirty); |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
790 |
assert!(!from_p2); |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
791 |
state = EntryState::Merged; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
792 |
size = SIZE_FROM_OTHER_PARENT; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
793 |
mtime = MTIME_UNSET; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
794 |
} else if from_p2 { |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
795 |
assert!(!possibly_dirty); |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
796 |
state = EntryState::Normal; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
797 |
size = SIZE_FROM_OTHER_PARENT; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
798 |
mtime = MTIME_UNSET; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
799 |
} else if possibly_dirty { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
800 |
state = EntryState::Normal; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
801 |
size = SIZE_NON_NORMAL; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
802 |
mtime = MTIME_UNSET; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
803 |
} else { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
804 |
state = EntryState::Normal; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
805 |
size = entry.size() & V1_RANGEMASK; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
806 |
mtime = entry.mtime() & V1_RANGEMASK; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
807 |
} |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
808 |
let mode = entry.mode(); |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
809 |
let entry = DirstateEntry::from_v1_data(state, mode, size, mtime); |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
810 |
|
47524
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
811 |
let old_state = match self.get(filename)? { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
812 |
Some(e) => e.state(), |
47524
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
813 |
None => EntryState::Unknown, |
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
814 |
}; |
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
815 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
816 |
Ok(self.add_or_remove_file(filename, old_state, entry)?) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
817 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
818 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
819 |
fn remove_file( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
820 |
&mut self, |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
821 |
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
|
822 |
in_merge: bool, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
823 |
) -> 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
|
824 |
let old_entry_opt = self.get(filename)?; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
825 |
let old_state = match old_entry_opt { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
826 |
Some(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
|
827 |
None => EntryState::Unknown, |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
828 |
}; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
829 |
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
|
830 |
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
|
831 |
// 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
|
832 |
// 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
|
833 |
// 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
|
834 |
// 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
|
835 |
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
|
836 |
// backup the previous state |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
837 |
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
|
838 |
size = SIZE_NON_NORMAL; |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
839 |
} 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
|
840 |
&& 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
|
841 |
{ |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
842 |
// 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
|
843 |
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
|
844 |
} |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
845 |
} |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
846 |
} |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47483
diff
changeset
|
847 |
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
|
848 |
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
|
849 |
} |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
850 |
let entry = DirstateEntry::new_removed(size); |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
851 |
Ok(self.add_or_remove_file(filename, old_state, entry)?) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
852 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
853 |
|
47535
6025353c9c55
dirstate: no longer pass `oldstate` to the `dropfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47530
diff
changeset
|
854 |
fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> { |
6025353c9c55
dirstate: no longer pass `oldstate` to the `dropfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47530
diff
changeset
|
855 |
let old_state = match self.get(filename)? { |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
856 |
Some(e) => e.state(), |
47535
6025353c9c55
dirstate: no longer pass `oldstate` to the `dropfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47530
diff
changeset
|
857 |
None => EntryState::Unknown, |
6025353c9c55
dirstate: no longer pass `oldstate` to the `dropfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47530
diff
changeset
|
858 |
}; |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
859 |
struct Dropped { |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
860 |
was_tracked: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
861 |
had_entry: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
862 |
had_copy_source: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
863 |
} |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
864 |
|
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
865 |
/// 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
|
866 |
/// |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
867 |
/// * `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
|
868 |
/// * `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
|
869 |
/// 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
|
870 |
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
|
871 |
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
|
872 |
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
|
873 |
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
|
874 |
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
|
875 |
) -> 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
|
876 |
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
|
877 |
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
|
878 |
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
|
879 |
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
|
880 |
{ |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
881 |
node |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
882 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
883 |
return Ok(None); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
884 |
}; |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
885 |
let dropped; |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
886 |
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
|
887 |
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
|
888 |
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
|
889 |
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
|
890 |
&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
|
891 |
rest, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
892 |
)? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
893 |
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
|
894 |
if dropped.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
|
895 |
node.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
|
896 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
897 |
if dropped.was_tracked { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
898 |
node.tracked_descendants_count -= 1; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
899 |
} |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
900 |
|
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
901 |
// 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
|
902 |
// child node |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
903 |
if removed { |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
904 |
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
|
905 |
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
|
906 |
} |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
907 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
908 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
909 |
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
|
910 |
} |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
911 |
} else { |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
912 |
let had_entry = node.data.has_entry(); |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
913 |
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
|
914 |
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
|
915 |
} |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
916 |
if let Some(source) = &node.copy_source { |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
917 |
DirstateMap::count_dropped_path(unreachable_bytes, source) |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
918 |
} |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
919 |
dropped = Dropped { |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
920 |
was_tracked: node |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
921 |
.data |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
922 |
.as_entry() |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
923 |
.map_or(false, |entry| entry.state().is_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
|
924 |
had_entry, |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
925 |
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
|
926 |
}; |
47204
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
927 |
} |
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47203
diff
changeset
|
928 |
// 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
|
929 |
// 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
|
930 |
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
|
931 |
&& 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
|
932 |
&& 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
|
933 |
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
|
934 |
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
|
935 |
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
|
936 |
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
|
937 |
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
|
938 |
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
|
939 |
) |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
940 |
} |
47358
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47357
diff
changeset
|
941 |
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
|
942 |
} |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
943 |
|
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
944 |
if let Some((dropped, _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
|
945 |
self.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
|
946 |
&mut self.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
|
947 |
&mut self.root, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
948 |
filename, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
949 |
)? { |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
950 |
if dropped.had_entry { |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
951 |
self.nodes_with_entry_count -= 1 |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
952 |
} |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
953 |
if dropped.had_copy_source { |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
954 |
self.nodes_with_copy_source_count -= 1 |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
955 |
} |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
956 |
Ok(dropped.had_entry) |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
957 |
} else { |
47203
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47140
diff
changeset
|
958 |
debug_assert!(!old_state.is_tracked()); |
47121
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
959 |
Ok(false) |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
960 |
} |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
961 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
962 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
963 |
fn clear_ambiguous_times( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
964 |
&mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
965 |
filenames: Vec<HgPathBuf>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
966 |
now: i32, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
967 |
) -> Result<(), DirstateV2ParseError> { |
47119
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47118
diff
changeset
|
968 |
for filename in filenames { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
969 |
if let Some(node) = Self::get_node_mut( |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
970 |
self.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
|
971 |
&mut self.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
|
972 |
&mut self.root, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
973 |
&filename, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
974 |
)? { |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
975 |
if let NodeData::Entry(entry) = &mut node.data { |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
976 |
entry.clear_ambiguous_mtime(now); |
47119
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47118
diff
changeset
|
977 |
} |
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47118
diff
changeset
|
978 |
} |
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47118
diff
changeset
|
979 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
980 |
Ok(()) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
981 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
982 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
983 |
fn non_normal_entries_contains( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
984 |
&mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
985 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
986 |
) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
987 |
Ok(if let Some(node) = self.get_node(key)? { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
988 |
node.entry()?.map_or(false, |entry| entry.is_non_normal()) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
989 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
990 |
false |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
991 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
992 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
993 |
|
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
|
994 |
fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool { |
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
|
995 |
// Do nothing, this `DirstateMap` does not have a separate "non normal |
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
|
996 |
// entries" set that need to be kept up to date. |
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
|
997 |
if let Ok(Some(v)) = self.get(key) { |
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
|
998 |
return v.is_non_normal(); |
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
|
999 |
} |
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
|
1000 |
false |
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
|
1001 |
} |
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
|
1002 |
|
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
|
1003 |
fn non_normal_entries_add(&mut self, _key: &HgPath) { |
47122
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
1004 |
// Do nothing, this `DirstateMap` does not have a separate "non normal |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
1005 |
// entries" set that need to be kept up to date |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1006 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1007 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1008 |
fn non_normal_or_other_parent_paths( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1009 |
&mut self, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1010 |
) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_> |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1011 |
{ |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1012 |
Box::new(self.filter_full_paths(|entry| { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1013 |
entry.is_non_normal() || entry.is_from_other_parent() |
47122
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
1014 |
})) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1015 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1016 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1017 |
fn set_non_normal_other_parent_entries(&mut self, _force: bool) { |
47122
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
1018 |
// Do nothing, this `DirstateMap` does not have a separate "non normal |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
1019 |
// entries" and "from other parent" sets that need to be recomputed |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1020 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1021 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1022 |
fn iter_non_normal_paths( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1023 |
&mut self, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1024 |
) -> Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1025 |
dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1026 |
> { |
47122
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
1027 |
self.iter_non_normal_paths_panic() |
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 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1030 |
fn iter_non_normal_paths_panic( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1031 |
&self, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1032 |
) -> Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1033 |
dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1034 |
> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1035 |
Box::new(self.filter_full_paths(|entry| entry.is_non_normal())) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1036 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1037 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1038 |
fn iter_other_parent_paths( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1039 |
&mut self, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1040 |
) -> Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1041 |
dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1042 |
> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1043 |
Box::new(self.filter_full_paths(|entry| entry.is_from_other_parent())) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1044 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1045 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1046 |
fn has_tracked_dir( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1047 |
&mut self, |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1048 |
directory: &HgPath, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1049 |
) -> Result<bool, DirstateError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1050 |
if let Some(node) = self.get_node(directory)? { |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1051 |
// A node without a `DirstateEntry` was created to hold child |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1052 |
// nodes, and is therefore a directory. |
47354
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
1053 |
let state = node.state()?; |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47353
diff
changeset
|
1054 |
Ok(state.is_none() && node.tracked_descendants_count() > 0) |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1055 |
} else { |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1056 |
Ok(false) |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1057 |
} |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1058 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1059 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1060 |
fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1061 |
if let Some(node) = self.get_node(directory)? { |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1062 |
// A node without a `DirstateEntry` was created to hold child |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1063 |
// nodes, and is therefore a directory. |
47483
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
1064 |
let state = node.state()?; |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47482
diff
changeset
|
1065 |
Ok(state.is_none() && node.descendants_with_entry_count() > 0) |
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1066 |
} else { |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1067 |
Ok(false) |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
1068 |
} |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1069 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1070 |
|
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
1071 |
#[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
1072 |
fn pack_v1( |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1073 |
&mut self, |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1074 |
parents: DirstateParents, |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1075 |
now: Timestamp, |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1076 |
) -> Result<Vec<u8>, DirstateError> { |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1077 |
let now: i32 = now.0.try_into().expect("time overflow"); |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1078 |
let mut ambiguous_mtimes = Vec::new(); |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1079 |
// 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
|
1080 |
// reallocations |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1081 |
let mut size = parents.as_bytes().len(); |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
1082 |
for node in self.iter_nodes() { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1083 |
let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1084 |
if let Some(entry) = node.entry()? { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1085 |
size += packed_entry_size( |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1086 |
node.full_path(self.on_disk)?, |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1087 |
node.copy_source(self.on_disk)?, |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1088 |
); |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1089 |
if entry.mtime_is_ambiguous(now) { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1090 |
ambiguous_mtimes.push( |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1091 |
node.full_path_borrowed(self.on_disk)? |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1092 |
.detach_from_tree(), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1093 |
) |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1094 |
} |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1095 |
} |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1096 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1097 |
self.clear_known_ambiguous_mtimes(&ambiguous_mtimes)?; |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1098 |
|
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1099 |
let mut packed = Vec::with_capacity(size); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1100 |
packed.extend(parents.as_bytes()); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1101 |
|
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
1102 |
for node in self.iter_nodes() { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1103 |
let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1104 |
if let Some(entry) = node.entry()? { |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1105 |
pack_entry( |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1106 |
node.full_path(self.on_disk)?, |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
1107 |
&entry, |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1108 |
node.copy_source(self.on_disk)?, |
47116
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1109 |
&mut packed, |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1110 |
); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1111 |
} |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1112 |
} |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
1113 |
Ok(packed) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1114 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1115 |
|
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1116 |
/// 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
|
1117 |
/// appended to the existing data file whose content is at |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1118 |
/// `self.on_disk` (true), instead of written to a new data file |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1119 |
/// (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
|
1120 |
#[timed] |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
1121 |
fn pack_v2( |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
1122 |
&mut self, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
1123 |
now: Timestamp, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
1124 |
can_append: bool, |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1125 |
) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> { |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1126 |
// TODO: how do we want to handle this in 2038? |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1127 |
let now: i32 = now.0.try_into().expect("time overflow"); |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1128 |
let mut paths = Vec::new(); |
47341
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
1129 |
for node in self.iter_nodes() { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1130 |
let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1131 |
if let Some(entry) = node.entry()? { |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1132 |
if entry.mtime_is_ambiguous(now) { |
47353
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1133 |
paths.push( |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1134 |
node.full_path_borrowed(self.on_disk)? |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1135 |
.detach_from_tree(), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47345
diff
changeset
|
1136 |
) |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1137 |
} |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1138 |
} |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1139 |
} |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1140 |
// Borrow of `self` ends here since we collect cloned paths |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1141 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1142 |
self.clear_known_ambiguous_mtimes(&paths)?; |
47338
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47294
diff
changeset
|
1143 |
|
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
1144 |
on_disk::write(self, 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
|
1145 |
} |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47204
diff
changeset
|
1146 |
|
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1147 |
fn status<'a>( |
47126
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1148 |
&'a mut self, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1149 |
matcher: &'a (dyn Matcher + Sync), |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1150 |
root_dir: PathBuf, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1151 |
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
|
1152 |
options: StatusOptions, |
47124
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47123
diff
changeset
|
1153 |
) -> Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError> |
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47123
diff
changeset
|
1154 |
{ |
47126
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
1155 |
super::status::status(self, matcher, root_dir, ignore_files, options) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1156 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1157 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1158 |
fn copy_map_len(&self) -> usize { |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
1159 |
self.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
|
1160 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1161 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1162 |
fn copy_map_iter(&self) -> CopyMapIter<'_> { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1163 |
Box::new(filter_map_results(self.iter_nodes(), move |node| { |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1164 |
Ok(if let Some(source) = node.copy_source(self.on_disk)? { |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1165 |
Some((node.full_path(self.on_disk)?, source)) |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1166 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1167 |
None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1168 |
}) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
1169 |
})) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1170 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1171 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1172 |
fn copy_map_contains_key( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1173 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1174 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1175 |
) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1176 |
Ok(if let Some(node) = self.get_node(key)? { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1177 |
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
|
1178 |
} else { |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
1179 |
false |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1180 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1181 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1182 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1183 |
fn copy_map_get( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1184 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1185 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1186 |
) -> Result<Option<&HgPath>, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1187 |
if let Some(node) = self.get_node(key)? { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1188 |
if let Some(source) = node.copy_source(self.on_disk)? { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1189 |
return Ok(Some(source)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1190 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1191 |
} |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1192 |
Ok(None) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1193 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1194 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1195 |
fn copy_map_remove( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1196 |
&mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1197 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1198 |
) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1199 |
let count = &mut self.nodes_with_copy_source_count; |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1200 |
let unreachable_bytes = &mut self.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
|
1201 |
Ok(Self::get_node_mut( |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1202 |
self.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
|
1203 |
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
|
1204 |
&mut self.root, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1205 |
key, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1206 |
)? |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1207 |
.and_then(|node| { |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1208 |
if let Some(source) = &node.copy_source { |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1209 |
*count -= 1; |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1210 |
Self::count_dropped_path(unreachable_bytes, source); |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1211 |
} |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1212 |
node.copy_source.take().map(Cow::into_owned) |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1213 |
})) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1214 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1215 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1216 |
fn copy_map_insert( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1217 |
&mut self, |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1218 |
key: HgPathBuf, |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1219 |
value: HgPathBuf, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1220 |
) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
1221 |
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
|
1222 |
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
|
1223 |
&mut self.unreachable_bytes, |
47140
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
1224 |
&mut self.root, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
1225 |
&key, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
1226 |
WithBasename::to_cow_owned, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47139
diff
changeset
|
1227 |
|_ancestor| {}, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1228 |
)?; |
47118
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1229 |
if node.copy_source.is_none() { |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1230 |
self.nodes_with_copy_source_count += 1 |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47117
diff
changeset
|
1231 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1232 |
Ok(node.copy_source.replace(value.into()).map(Cow::into_owned)) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1233 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1234 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1235 |
fn len(&self) -> usize { |
47294
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47293
diff
changeset
|
1236 |
self.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
|
1237 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1238 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1239 |
fn contains_key( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1240 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1241 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1242 |
) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1243 |
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
|
1244 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1245 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1246 |
fn get( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1247 |
&self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1248 |
key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1249 |
) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1250 |
Ok(if let Some(node) = self.get_node(key)? { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1251 |
node.entry()? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1252 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1253 |
None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1254 |
}) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1255 |
} |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1256 |
|
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1257 |
fn iter(&self) -> StateMapIter<'_> { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1258 |
Box::new(filter_map_results(self.iter_nodes(), move |node| { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1259 |
Ok(if let Some(entry) = node.entry()? { |
47344
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
1260 |
Some((node.full_path(self.on_disk)?, entry)) |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1261 |
} else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1262 |
None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47342
diff
changeset
|
1263 |
}) |
47114
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
1264 |
})) |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1265 |
} |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1266 |
|
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1267 |
fn iter_tracked_dirs( |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1268 |
&mut self, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1269 |
) -> Result< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1270 |
Box< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1271 |
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
|
1272 |
+ Send |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1273 |
+ '_, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1274 |
>, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1275 |
DirstateError, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1276 |
> { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1277 |
let on_disk = self.on_disk; |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1278 |
Ok(Box::new(filter_map_results( |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1279 |
self.iter_nodes(), |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1280 |
move |node| { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1281 |
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
|
1282 |
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
|
1283 |
} else { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1284 |
None |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1285 |
}) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1286 |
}, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1287 |
))) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1288 |
} |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1289 |
|
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1290 |
fn debug_iter( |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1291 |
&self, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1292 |
) -> Box< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1293 |
dyn Iterator< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1294 |
Item = Result< |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1295 |
(&HgPath, (u8, i32, i32, i32)), |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1296 |
DirstateV2ParseError, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1297 |
>, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1298 |
> + Send |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1299 |
+ '_, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1300 |
> { |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1301 |
Box::new(self.iter_nodes().map(move |node| { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1302 |
let node = node?; |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1303 |
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
|
1304 |
entry.debug_tuple() |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1305 |
} else if let Some(mtime) = node.cached_directory_mtime() { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1306 |
(b' ', 0, -1, mtime.seconds() as i32) |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1307 |
} else { |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1308 |
(b' ', 0, -1, -1) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1309 |
}; |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1310 |
Ok((node.full_path(self.on_disk)?, debug_tuple)) |
47357
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1311 |
})) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47355
diff
changeset
|
1312 |
} |
47109
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1313 |
} |