Mercurial > hg
annotate rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47527:c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Differential Revision: https://phab.mercurial-scm.org/D10969
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 04 Jul 2021 01:48:11 +0200 |
parents | fe4641cf9b72 |
children | 80617f3c0f9a |
rev | line source |
---|---|
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1 use bytes_cast::BytesCast; |
47118
c92e63762573
dirstate-tree: Add #[timed] attribute to `status` and `DirstateMap::read`
Simon Sapin <simon.sapin@octobus.net>
parents:
47116
diff
changeset
|
2 use micro_timer::timed; |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
3 use std::borrow::Cow; |
47119
15395fd8ab28
dirstate-tree: Use HashMap instead of BTreeMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47118
diff
changeset
|
4 use std::convert::TryInto; |
47095
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 |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
7 use super::on_disk; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
8 use super::on_disk::DirstateV2ParseError; |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
9 use super::path_with_basename::WithBasename; |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
10 use crate::dirstate::parsers::pack_entry; |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
11 use crate::dirstate::parsers::packed_entry_size; |
47098
d7631d55da3e
dirstate-tree: Add parsing only dirstate parents from disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47097
diff
changeset
|
12 use crate::dirstate::parsers::parse_dirstate_entries; |
47101
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47100
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:
47478
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:
47478
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; |
47095
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; |
47119
15395fd8ab28
dirstate-tree: Use HashMap instead of BTreeMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47118
diff
changeset
|
26 use crate::FastHashMap; |
47095
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 |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
32 pub struct DirstateMap<'on_disk> { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
33 /// Contents of the `.hg/dirstate` file |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
34 pub(super) on_disk: &'on_disk [u8], |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
35 |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
36 pub(super) root: ChildNodes<'on_disk>, |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
37 |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
38 /// Number of nodes anywhere in the tree that have `.entry.is_some()`. |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
39 pub(super) nodes_with_entry_count: u32, |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
40 |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
41 /// 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:
47102
diff
changeset
|
42 /// `.copy_source.is_some()`. |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
43 pub(super) nodes_with_copy_source_count: u32, |
47409
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47352
diff
changeset
|
44 |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47352
diff
changeset
|
45 /// See on_disk::Header |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47352
diff
changeset
|
46 pub(super) ignore_patterns_hash: on_disk::IgnorePatternsHash, |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
47 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
48 |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
49 /// 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:
47095
diff
changeset
|
50 /// 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:
47095
diff
changeset
|
51 /// path, so comparing full paths gives the same result as comparing base |
47282
ce41ee53263f
dirstate-tree: Extract into a method sorting children of a given node
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
52 /// names. However `HashMap` would waste time always re-hashing the same |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
53 /// string prefix. |
47282
ce41ee53263f
dirstate-tree: Extract into a method sorting children of a given node
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
54 pub(super) type NodeKey<'on_disk> = WithBasename<Cow<'on_disk, HgPath>>; |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
55 |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
56 /// 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:
47337
diff
changeset
|
57 /// 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:
47337
diff
changeset
|
58 pub(super) enum BorrowedPath<'tree, 'on_disk> { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
59 InMemory(&'tree HgPathBuf), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
60 OnDisk(&'on_disk HgPath), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
61 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
62 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
63 pub(super) enum ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
64 InMemory(FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
65 OnDisk(&'on_disk [on_disk::Node]), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
66 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
67 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
68 pub(super) enum ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
69 InMemory(&'tree FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
70 OnDisk(&'on_disk [on_disk::Node]), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
71 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
72 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
73 pub(super) enum NodeRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
74 InMemory(&'tree NodeKey<'on_disk>, &'tree Node<'on_disk>), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
75 OnDisk(&'on_disk on_disk::Node), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
76 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
77 |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
78 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:
47337
diff
changeset
|
79 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:
47337
diff
changeset
|
80 match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
81 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:
47337
diff
changeset
|
82 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:
47337
diff
changeset
|
83 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
84 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
85 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
86 |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
87 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:
47337
diff
changeset
|
88 type Target = HgPath; |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
89 |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
90 fn deref(&self) -> &HgPath { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
91 match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
92 BorrowedPath::InMemory(in_memory) => in_memory, |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
93 BorrowedPath::OnDisk(on_disk) => on_disk, |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
94 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
95 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
96 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
97 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
98 impl Default for ChildNodes<'_> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
99 fn default() -> Self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
100 ChildNodes::InMemory(Default::default()) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
101 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
102 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
103 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
104 impl<'on_disk> ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
105 pub(super) fn as_ref<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
106 &'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
107 ) -> ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
108 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
109 ChildNodes::InMemory(nodes) => ChildNodesRef::InMemory(nodes), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
110 ChildNodes::OnDisk(nodes) => ChildNodesRef::OnDisk(nodes), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
111 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
112 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
113 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
114 pub(super) fn is_empty(&self) -> bool { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
115 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
116 ChildNodes::InMemory(nodes) => nodes.is_empty(), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
117 ChildNodes::OnDisk(nodes) => nodes.is_empty(), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
118 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
119 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
120 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
121 pub(super) fn make_mut( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
122 &mut self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
123 on_disk: &'on_disk [u8], |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
124 ) -> Result< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
125 &mut FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
126 DirstateV2ParseError, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
127 > { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
128 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
129 ChildNodes::InMemory(nodes) => Ok(nodes), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
130 ChildNodes::OnDisk(nodes) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
131 let nodes = nodes |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
132 .iter() |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
133 .map(|node| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
134 Ok(( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
135 node.path(on_disk)?, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
136 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:
47336
diff
changeset
|
137 )) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
138 }) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
139 .collect::<Result<_, _>>()?; |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
140 *self = ChildNodes::InMemory(nodes); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
141 match self { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
142 ChildNodes::InMemory(nodes) => Ok(nodes), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
143 ChildNodes::OnDisk(_) => unreachable!(), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
144 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
145 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
146 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
147 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
148 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
149 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
150 impl<'tree, 'on_disk> ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
151 pub(super) fn get( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
152 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
153 base_name: &HgPath, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
154 on_disk: &'on_disk [u8], |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
155 ) -> Result<Option<NodeRef<'tree, 'on_disk>>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
156 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
157 ChildNodesRef::InMemory(nodes) => Ok(nodes |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
158 .get_key_value(base_name) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
159 .map(|(k, v)| NodeRef::InMemory(k, v))), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
160 ChildNodesRef::OnDisk(nodes) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
161 let mut parse_result = Ok(()); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
162 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:
47336
diff
changeset
|
163 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:
47336
diff
changeset
|
164 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:
47336
diff
changeset
|
165 Err(e) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
166 parse_result = Err(e); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
167 // 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:
47336
diff
changeset
|
168 // 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:
47336
diff
changeset
|
169 std::cmp::Ordering::Equal |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
170 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
171 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
172 }); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
173 parse_result.map(|()| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
174 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:
47336
diff
changeset
|
175 }) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
176 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
177 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
178 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
179 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
180 /// Iterate in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
181 pub(super) fn iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
182 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
183 ) -> impl Iterator<Item = NodeRef<'tree, 'on_disk>> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
184 match self { |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
185 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:
47336
diff
changeset
|
186 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:
47336
diff
changeset
|
187 ), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
188 ChildNodesRef::OnDisk(nodes) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
189 itertools::Either::Right(nodes.iter().map(NodeRef::OnDisk)) |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
190 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
191 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
192 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
193 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
194 /// Iterate in parallel in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
195 pub(super) fn par_iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
196 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
197 ) -> impl rayon::iter::ParallelIterator<Item = NodeRef<'tree, 'on_disk>> |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
198 { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
199 use rayon::prelude::*; |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
200 match self { |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
201 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:
47336
diff
changeset
|
202 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:
47336
diff
changeset
|
203 ), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
204 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:
47336
diff
changeset
|
205 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:
47336
diff
changeset
|
206 ), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
207 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
208 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
209 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
210 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:
47332
diff
changeset
|
211 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
212 ChildNodesRef::InMemory(nodes) => { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
213 let mut vec: Vec<_> = nodes |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
214 .iter() |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
215 .map(|(k, v)| NodeRef::InMemory(k, v)) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
216 .collect(); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
217 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:
47334
diff
changeset
|
218 match node { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
219 NodeRef::InMemory(path, _node) => path.base_name(), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
220 NodeRef::OnDisk(_) => unreachable!(), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
221 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
222 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
223 // `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:
47332
diff
changeset
|
224 // value: https://github.com/rust-lang/rust/issues/34162 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
225 vec.sort_unstable_by(|a, b| sort_key(a).cmp(sort_key(b))); |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
226 vec |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
227 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
228 ChildNodesRef::OnDisk(nodes) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
229 // 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:
47336
diff
changeset
|
230 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:
47336
diff
changeset
|
231 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
232 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
233 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
234 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
235 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
236 impl<'tree, 'on_disk> NodeRef<'tree, 'on_disk> { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
237 pub(super) fn full_path( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
238 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
239 on_disk: &'on_disk [u8], |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
240 ) -> Result<&'tree HgPath, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
241 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
242 NodeRef::InMemory(path, _node) => Ok(path.full_path()), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
243 NodeRef::OnDisk(node) => node.full_path(on_disk), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
244 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
245 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
246 |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
247 /// 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:
47337
diff
changeset
|
248 /// HgPath>` detached from `'tree` |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
249 pub(super) fn full_path_borrowed( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
250 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
251 on_disk: &'on_disk [u8], |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
252 ) -> Result<BorrowedPath<'tree, 'on_disk>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
253 match self { |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
254 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:
47337
diff
changeset
|
255 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:
47337
diff
changeset
|
256 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:
47337
diff
changeset
|
257 }, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
258 NodeRef::OnDisk(node) => { |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
259 Ok(BorrowedPath::OnDisk(node.full_path(on_disk)?)) |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
260 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
261 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
262 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
263 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
264 pub(super) fn base_name( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
265 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
266 on_disk: &'on_disk [u8], |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
267 ) -> Result<&'tree HgPath, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
268 match self { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
269 NodeRef::InMemory(path, _node) => Ok(path.base_name()), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
270 NodeRef::OnDisk(node) => node.base_name(on_disk), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
271 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
272 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
273 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
274 pub(super) fn children( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
275 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
276 on_disk: &'on_disk [u8], |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
277 ) -> Result<ChildNodesRef<'tree, 'on_disk>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
278 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
279 NodeRef::InMemory(_path, node) => Ok(node.children.as_ref()), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
280 NodeRef::OnDisk(node) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
281 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:
47336
diff
changeset
|
282 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
283 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
284 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
285 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
286 pub(super) fn has_copy_source(&self) -> bool { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
287 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
288 NodeRef::InMemory(_path, node) => node.copy_source.is_some(), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
289 NodeRef::OnDisk(node) => node.has_copy_source(), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
290 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
291 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
292 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
293 pub(super) fn copy_source( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
294 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
295 on_disk: &'on_disk [u8], |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
296 ) -> Result<Option<&'tree HgPath>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
297 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
298 NodeRef::InMemory(_path, node) => { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
299 Ok(node.copy_source.as_ref().map(|s| &**s)) |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
300 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
301 NodeRef::OnDisk(node) => node.copy_source(on_disk), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
302 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
303 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
304 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
305 pub(super) fn entry( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
306 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
307 ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
308 match self { |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
309 NodeRef::InMemory(_path, node) => { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
310 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:
47347
diff
changeset
|
311 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
312 NodeRef::OnDisk(node) => node.entry(), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
313 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
314 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
315 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
316 pub(super) fn state( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
317 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
318 ) -> Result<Option<EntryState>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
319 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
320 NodeRef::InMemory(_path, node) => { |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
321 Ok(node.data.as_entry().map(|entry| entry.state)) |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
322 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
323 NodeRef::OnDisk(node) => node.state(), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
324 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
325 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
326 |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
327 pub(super) fn cached_directory_mtime( |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
328 &self, |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
329 ) -> Option<&'tree on_disk::Timestamp> { |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
330 match self { |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
331 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:
47348
diff
changeset
|
332 NodeData::CachedDirectory { mtime } => Some(mtime), |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
333 _ => None, |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
334 }, |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
335 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:
47348
diff
changeset
|
336 } |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
337 } |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
338 |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
339 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:
47477
diff
changeset
|
340 match self { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
341 NodeRef::InMemory(_path, node) => { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
342 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:
47477
diff
changeset
|
343 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
344 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:
47477
diff
changeset
|
345 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
346 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
347 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
348 pub(super) fn tracked_descendants_count(&self) -> u32 { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
349 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
350 NodeRef::InMemory(_path, node) => node.tracked_descendants_count, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
351 NodeRef::OnDisk(node) => node.tracked_descendants_count.get(), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
352 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
353 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
354 } |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
355 |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
356 /// Represents a file or a directory |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
357 #[derive(Default)] |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
358 pub(super) struct Node<'on_disk> { |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
359 pub(super) data: NodeData, |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
360 |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
361 pub(super) copy_source: Option<Cow<'on_disk, HgPath>>, |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
362 |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
363 pub(super) children: ChildNodes<'on_disk>, |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
364 |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
365 /// 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:
47477
diff
changeset
|
366 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:
47477
diff
changeset
|
367 |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
368 /// 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:
47477
diff
changeset
|
369 /// state is "tracked". |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
370 pub(super) tracked_descendants_count: u32, |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
371 } |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
372 |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
373 pub(super) enum NodeData { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
374 Entry(DirstateEntry), |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
375 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:
47347
diff
changeset
|
376 None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
377 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
378 |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
379 impl Default for NodeData { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
380 fn default() -> Self { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
381 NodeData::None |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
382 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
383 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
384 |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
385 impl NodeData { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
386 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:
47347
diff
changeset
|
387 match self { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
388 NodeData::Entry(_) => true, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
389 _ => false, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
390 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
391 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
392 |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
393 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:
47347
diff
changeset
|
394 match self { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
395 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:
47347
diff
changeset
|
396 _ => None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
397 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
398 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
399 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
400 |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
401 impl<'on_disk> DirstateMap<'on_disk> { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
402 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:
47282
diff
changeset
|
403 Self { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
404 on_disk, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
405 root: ChildNodes::default(), |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
406 nodes_with_entry_count: 0, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
407 nodes_with_copy_source_count: 0, |
47409
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47352
diff
changeset
|
408 ignore_patterns_hash: [0; on_disk::IGNORE_PATTERNS_HASH_LEN], |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
409 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
410 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
411 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
412 #[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
413 pub fn new_v2( |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
414 on_disk: &'on_disk [u8], |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
415 ) -> Result<(Self, Option<DirstateParents>), DirstateError> { |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
416 Ok(on_disk::read(on_disk)?) |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
417 } |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
418 |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
419 #[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
420 pub fn new_v1( |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
421 on_disk: &'on_disk [u8], |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
422 ) -> Result<(Self, Option<DirstateParents>), DirstateError> { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
423 let mut map = Self::empty(on_disk); |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
424 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:
47193
diff
changeset
|
425 return Ok((map, None)); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
426 } |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
427 |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
428 let parents = parse_dirstate_entries( |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
429 map.on_disk, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
430 |path, entry, copy_source| { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
431 let tracked = entry.state.is_tracked(); |
47126
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
432 let node = Self::get_or_insert_node( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
433 map.on_disk, |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
434 &mut map.root, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
435 path, |
47126
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
436 WithBasename::to_cow_borrowed, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
437 |ancestor| { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
438 if tracked { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
439 ancestor.tracked_descendants_count += 1 |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
440 } |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
441 ancestor.descendants_with_entry_count += 1 |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
442 }, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
443 )?; |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
444 assert!( |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
445 !node.data.has_entry(), |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
446 "duplicate dirstate entry in read" |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
447 ); |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
448 assert!( |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
449 node.copy_source.is_none(), |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
450 "duplicate dirstate entry in read" |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
451 ); |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
452 node.data = NodeData::Entry(*entry); |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
453 node.copy_source = copy_source.map(Cow::Borrowed); |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
454 map.nodes_with_entry_count += 1; |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
455 if copy_source.is_some() { |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
456 map.nodes_with_copy_source_count += 1 |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
457 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
458 Ok(()) |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
459 }, |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
460 )?; |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
461 let parents = Some(parents.clone()); |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
462 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
463 Ok((map, parents)) |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
464 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
465 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
466 fn get_node<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
467 &'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
468 path: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
469 ) -> Result<Option<NodeRef<'tree, 'on_disk>>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
470 let mut children = self.root.as_ref(); |
47099
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
471 let mut components = path.components(); |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
472 let mut component = |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
473 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:
47098
diff
changeset
|
474 loop { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
475 if let Some(child) = children.get(component, self.on_disk)? { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
476 if let Some(next_component) = components.next() { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
477 component = next_component; |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
478 children = child.children(self.on_disk)?; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
479 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
480 return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
481 } |
47099
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
482 } else { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
483 return Ok(None); |
47099
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
484 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
485 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
486 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
487 |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
488 /// 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:
47105
diff
changeset
|
489 /// |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
490 /// 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:
47102
diff
changeset
|
491 /// other fields while the returned borrow is still valid |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
492 fn get_node_mut<'tree>( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
493 on_disk: &'on_disk [u8], |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
494 root: &'tree mut ChildNodes<'on_disk>, |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
495 path: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
496 ) -> Result<Option<&'tree mut Node<'on_disk>>, DirstateV2ParseError> { |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
497 let mut children = root; |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
498 let mut components = path.components(); |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
499 let mut component = |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
500 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:
47103
diff
changeset
|
501 loop { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
502 if let Some(child) = children.make_mut(on_disk)?.get_mut(component) |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
503 { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
504 if let Some(next_component) = components.next() { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
505 component = next_component; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
506 children = &mut child.children; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
507 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
508 return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
509 } |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
510 } else { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
511 return Ok(None); |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
512 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
513 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
514 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
515 |
47474
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
516 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:
47409
diff
changeset
|
517 &'tree mut self, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
518 path: &HgPath, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
519 ) -> 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:
47409
diff
changeset
|
520 Self::get_or_insert_node( |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
521 self.on_disk, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
522 &mut self.root, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
523 path, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
524 WithBasename::to_cow_owned, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
525 |_| {}, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
526 ) |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
527 } |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
528 |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
529 pub(super) fn get_or_insert_node<'tree, 'path>( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
530 on_disk: &'on_disk [u8], |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
531 root: &'tree mut ChildNodes<'on_disk>, |
47126
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
532 path: &'path HgPath, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
533 to_cow: impl Fn( |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
534 WithBasename<&'path HgPath>, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
535 ) -> WithBasename<Cow<'on_disk, HgPath>>, |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
536 mut each_ancestor: impl FnMut(&mut Node), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
537 ) -> Result<&'tree mut Node<'on_disk>, DirstateV2ParseError> { |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
538 let mut child_nodes = root; |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
539 let mut inclusive_ancestor_paths = |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
540 WithBasename::inclusive_ancestors_of(path); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
541 let mut ancestor_path = inclusive_ancestor_paths |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
542 .next() |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
543 .expect("expected at least one inclusive ancestor"); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
544 loop { |
47116
04bcba539c96
dirstate-tree: Avoid BTreeMap double-lookup when inserting a dirstate entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47113
diff
changeset
|
545 // 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:
47113
diff
changeset
|
546 // 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:
47113
diff
changeset
|
547 // lookup? |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
548 let child_node = child_nodes |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
549 .make_mut(on_disk)? |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
550 .entry(to_cow(ancestor_path)) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
551 .or_default(); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
552 if let Some(next) = inclusive_ancestor_paths.next() { |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
553 each_ancestor(child_node); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
554 ancestor_path = next; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
555 child_nodes = &mut child_node.children; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
556 } else { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
557 return Ok(child_node); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
558 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
559 } |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
560 } |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
561 |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
562 fn add_or_remove_file( |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
563 &mut self, |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
564 path: &HgPath, |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
565 old_state: EntryState, |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
566 new_entry: DirstateEntry, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
567 ) -> Result<(), DirstateV2ParseError> { |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
568 let had_entry = old_state != EntryState::Unknown; |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
569 let tracked_count_increment = |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
570 match (old_state.is_tracked(), new_entry.state.is_tracked()) { |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
571 (false, true) => 1, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
572 (true, false) => -1, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
573 _ => 0, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
574 }; |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
575 |
47126
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
576 let node = Self::get_or_insert_node( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
577 self.on_disk, |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
578 &mut self.root, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
579 path, |
47126
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
580 WithBasename::to_cow_owned, |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
581 |ancestor| { |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
582 if !had_entry { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
583 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:
47477
diff
changeset
|
584 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
585 |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
586 // 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:
47119
diff
changeset
|
587 // 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:
47119
diff
changeset
|
588 // through zero |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
589 match tracked_count_increment { |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
590 1 => ancestor.tracked_descendants_count += 1, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
591 -1 => ancestor.tracked_descendants_count -= 1, |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
592 _ => {} |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
593 } |
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
594 }, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
595 )?; |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
596 if !had_entry { |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
597 self.nodes_with_entry_count += 1 |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
598 } |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
599 node.data = NodeData::Entry(new_entry); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
600 Ok(()) |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
601 } |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
602 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
603 fn iter_nodes<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
604 &'tree self, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
605 ) -> impl Iterator< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
606 Item = Result<NodeRef<'tree, 'on_disk>, DirstateV2ParseError>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
607 > + 'tree { |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
608 // Depth first tree traversal. |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
609 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
610 // If we could afford internal iteration and recursion, |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
611 // this would look like: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
612 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
613 // ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
614 // fn traverse_children( |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
615 // children: &ChildNodes, |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
616 // each: &mut impl FnMut(&Node), |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
617 // ) { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
618 // for child in children.values() { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
619 // traverse_children(&child.children, each); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
620 // each(child); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
621 // } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
622 // } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
623 // ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
624 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
625 // 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:
47099
diff
changeset
|
626 // call stack. Use an explicit stack instead: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
627 let mut stack = Vec::new(); |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
628 let mut iter = self.root.as_ref().iter(); |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
629 std::iter::from_fn(move || { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
630 while let Some(child_node) = iter.next() { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
631 let children = match child_node.children(self.on_disk) { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
632 Ok(children) => children, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
633 Err(error) => return Some(Err(error)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
634 }; |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
635 // Pseudo-recursion |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
636 let new_iter = children.iter(); |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
637 let old_iter = std::mem::replace(&mut iter, new_iter); |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
638 stack.push((child_node, old_iter)); |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
639 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
640 // Found the end of a `children.iter()` iterator. |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
641 if let Some((child_node, next_iter)) = stack.pop() { |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
642 // "Return" from pseudo-recursion by restoring state from the |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
643 // explicit stack |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
644 iter = next_iter; |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
645 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
646 Some(Ok(child_node)) |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
647 } else { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
648 // Reached the bottom of the stack, we’re done |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
649 None |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
650 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
651 }) |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
652 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
653 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
654 fn clear_known_ambiguous_mtimes( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
655 &mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
656 paths: &[impl AsRef<HgPath>], |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
657 ) -> Result<(), DirstateV2ParseError> { |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
658 for path in paths { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
659 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:
47335
diff
changeset
|
660 self.on_disk, |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
661 &mut self.root, |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
662 path.as_ref(), |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
663 )? { |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
664 if let NodeData::Entry(entry) = &mut node.data { |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
665 entry.clear_mtime(); |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
666 } |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
667 } |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
668 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
669 Ok(()) |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
670 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
671 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
672 /// 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:
47334
diff
changeset
|
673 /// `entry` for which the given `predicate` returns true. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
674 /// |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
675 /// 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:
47334
diff
changeset
|
676 /// 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:
47334
diff
changeset
|
677 /// 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:
47334
diff
changeset
|
678 fn filter_full_paths<'tree>( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
679 &'tree self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
680 predicate: impl Fn(&DirstateEntry) -> bool + 'tree, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
681 ) -> impl Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + 'tree |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
682 { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
683 filter_map_results(self.iter_nodes(), move |node| { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
684 if let Some(entry) = node.entry()? { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
685 if predicate(&entry) { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
686 return Ok(Some(node.full_path(self.on_disk)?)); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
687 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
688 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
689 Ok(None) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
690 }) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
691 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
692 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
693 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
694 /// 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:
47334
diff
changeset
|
695 /// |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
696 /// 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:
47334
diff
changeset
|
697 /// 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:
47334
diff
changeset
|
698 /// 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:
47334
diff
changeset
|
699 /// `Result`. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
700 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:
47334
diff
changeset
|
701 iter: I, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
702 f: F, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
703 ) -> impl Iterator<Item = Result<B, E>> + 'a |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
704 where |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
705 I: Iterator<Item = Result<A, E>> + 'a, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
706 F: Fn(A) -> Result<Option<B>, E> + 'a, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
707 { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
708 iter.filter_map(move |result| match result { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
709 Ok(node) => f(node).transpose(), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
710 Err(e) => Some(Err(e)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
711 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
712 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
713 |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
714 impl<'on_disk> super::dispatch::DirstateMapMethods for DirstateMap<'on_disk> { |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
715 fn clear(&mut self) { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
716 self.root = Default::default(); |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
717 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:
47102
diff
changeset
|
718 self.nodes_with_copy_source_count = 0; |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
719 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
720 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
721 fn add_file( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
722 &mut self, |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
723 filename: &HgPath, |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
724 entry: DirstateEntry, |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
725 added: bool, |
47527
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
726 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
|
727 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
|
728 possibly_dirty: bool, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
729 ) -> Result<(), DirstateError> { |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
730 let mut entry = entry; |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
731 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
|
732 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
|
733 assert!(!from_p2); |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
734 entry.state = EntryState::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
|
735 entry.size = SIZE_NON_NORMAL; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
736 entry.mtime = MTIME_UNSET; |
47527
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
737 } else if merged { |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
738 assert!(!possibly_dirty); |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
739 assert!(!from_p2); |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
740 entry.state = EntryState::Merged; |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
741 entry.size = SIZE_FROM_OTHER_PARENT; |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
742 entry.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
|
743 } 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
|
744 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
|
745 entry.size = SIZE_FROM_OTHER_PARENT; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
746 entry.mtime = MTIME_UNSET; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
747 } else if 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
|
748 entry.size = SIZE_NON_NORMAL; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
749 entry.mtime = MTIME_UNSET; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
750 } else { |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
751 entry.size = entry.size & V1_RANGEMASK; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
752 entry.mtime = entry.mtime & V1_RANGEMASK; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
753 } |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
754 |
47524
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
755 let old_state = match self.get(filename)? { |
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
756 Some(e) => e.state, |
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
757 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
|
758 }; |
69a463a4f193
dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47521
diff
changeset
|
759 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
760 Ok(self.add_or_remove_file(filename, old_state, entry)?) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
761 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
762 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
763 fn remove_file( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
764 &mut self, |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
765 filename: &HgPath, |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
766 in_merge: bool, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
767 ) -> Result<(), DirstateError> { |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
768 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:
47478
diff
changeset
|
769 let old_state = match old_entry_opt { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
770 Some(e) => e.state, |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
771 None => EntryState::Unknown, |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
772 }; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
773 let mut size = 0; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
774 if in_merge { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
775 // 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:
47478
diff
changeset
|
776 // 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:
47478
diff
changeset
|
777 // 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:
47478
diff
changeset
|
778 // would be nice. |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
779 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:
47478
diff
changeset
|
780 // backup the previous state |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
781 if old_entry.state == EntryState::Merged { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
782 size = SIZE_NON_NORMAL; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
783 } else if old_entry.state == EntryState::Normal |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
784 && old_entry.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:
47478
diff
changeset
|
785 { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
786 // other parent |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
787 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:
47478
diff
changeset
|
788 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
789 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
790 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
791 if size == 0 { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47478
diff
changeset
|
792 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:
47478
diff
changeset
|
793 } |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
794 let entry = DirstateEntry { |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
795 state: EntryState::Removed, |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
796 mode: 0, |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
797 size, |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
798 mtime: 0, |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
799 }; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
800 Ok(self.add_or_remove_file(filename, old_state, entry)?) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
801 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
802 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
803 fn drop_file( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
804 &mut self, |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
805 filename: &HgPath, |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
806 old_state: EntryState, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
807 ) -> Result<bool, DirstateError> { |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
808 struct Dropped { |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
809 was_tracked: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
810 had_entry: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
811 had_copy_source: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
812 } |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
813 |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
814 /// 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:
47351
diff
changeset
|
815 /// |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
816 /// * `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:
47351
diff
changeset
|
817 /// * `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:
47351
diff
changeset
|
818 /// removed a node in `nodes`. |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
819 fn recur<'on_disk>( |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
820 on_disk: &'on_disk [u8], |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
821 nodes: &mut ChildNodes<'on_disk>, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
822 path: &HgPath, |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
823 ) -> Result<Option<(Dropped, bool)>, DirstateV2ParseError> { |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
824 let (first_path_component, rest_of_path) = |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
825 path.split_first_component(); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
826 let node = if let Some(node) = |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
827 nodes.make_mut(on_disk)?.get_mut(first_path_component) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
828 { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
829 node |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
830 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
831 return Ok(None); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
832 }; |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
833 let dropped; |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
834 if let Some(rest) = rest_of_path { |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
835 if let Some((d, removed)) = |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
836 recur(on_disk, &mut node.children, rest)? |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
837 { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
838 dropped = d; |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
839 if dropped.had_entry { |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
840 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:
47477
diff
changeset
|
841 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
842 if dropped.was_tracked { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
843 node.tracked_descendants_count -= 1; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
844 } |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
845 |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
846 // 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:
47351
diff
changeset
|
847 // child node |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
848 if removed { |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
849 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:
47351
diff
changeset
|
850 node.data = NodeData::None |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
851 } |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
852 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
853 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
854 return Ok(None); |
47120
7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
Simon Sapin <simon.sapin@octobus.net>
parents:
47119
diff
changeset
|
855 } |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
856 } else { |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
857 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:
47347
diff
changeset
|
858 if had_entry { |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
859 node.data = NodeData::None |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
860 } |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
861 dropped = Dropped { |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
862 was_tracked: node |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
863 .data |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
864 .as_entry() |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
865 .map_or(false, |entry| entry.state.is_tracked()), |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
866 had_entry, |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
867 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:
47126
diff
changeset
|
868 }; |
47193
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47192
diff
changeset
|
869 } |
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47192
diff
changeset
|
870 // 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:
47192
diff
changeset
|
871 // parent nodes, remove a node if it just became empty. |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
872 let remove = !node.data.has_entry() |
47193
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47192
diff
changeset
|
873 && node.copy_source.is_none() |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
874 && node.children.is_empty(); |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
875 if remove { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
876 nodes.make_mut(on_disk)?.remove(first_path_component); |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
877 } |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
878 Ok(Some((dropped, remove))) |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
879 } |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
880 |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
881 if let Some((dropped, _removed)) = |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
882 recur(self.on_disk, &mut self.root, filename)? |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
883 { |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
884 if dropped.had_entry { |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
885 self.nodes_with_entry_count -= 1 |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
886 } |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
887 if dropped.had_copy_source { |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
888 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:
47106
diff
changeset
|
889 } |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
890 Ok(dropped.had_entry) |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
891 } else { |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
892 debug_assert!(!old_state.is_tracked()); |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
893 Ok(false) |
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
894 } |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
895 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
896 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
897 fn clear_ambiguous_times( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
898 &mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
899 filenames: Vec<HgPathBuf>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
900 now: i32, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
901 ) -> Result<(), DirstateV2ParseError> { |
47105
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47104
diff
changeset
|
902 for filename in filenames { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
903 if let Some(node) = |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
904 Self::get_node_mut(self.on_disk, &mut self.root, &filename)? |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
905 { |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
906 if let NodeData::Entry(entry) = &mut node.data { |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
907 entry.clear_ambiguous_mtime(now); |
47105
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47104
diff
changeset
|
908 } |
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47104
diff
changeset
|
909 } |
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47104
diff
changeset
|
910 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
911 Ok(()) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
912 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
913 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
914 fn non_normal_entries_contains( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
915 &mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
916 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
917 ) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
918 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:
47334
diff
changeset
|
919 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:
47334
diff
changeset
|
920 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
921 false |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
922 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
923 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
924 |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
925 fn non_normal_entries_remove(&mut self, _key: &HgPath) { |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
926 // 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:
47107
diff
changeset
|
927 // entries" set that need to be kept up to date |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
928 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
929 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
930 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
|
931 &mut self, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
932 ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_> |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
933 { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
934 Box::new(self.filter_full_paths(|entry| { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
935 entry.is_non_normal() || entry.is_from_other_parent() |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
936 })) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
937 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
938 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
939 fn set_non_normal_other_parent_entries(&mut self, _force: bool) { |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
940 // 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:
47107
diff
changeset
|
941 // entries" and "from other parent" sets that need to be recomputed |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
942 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
943 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
944 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
|
945 &mut self, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
946 ) -> Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
947 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
948 > { |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
949 self.iter_non_normal_paths_panic() |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
950 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
951 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
952 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
|
953 &self, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
954 ) -> Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
955 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
956 > { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
957 Box::new(self.filter_full_paths(|entry| entry.is_non_normal())) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
958 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
959 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
960 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
|
961 &mut self, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
962 ) -> Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
963 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
964 > { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
965 Box::new(self.filter_full_paths(|entry| entry.is_from_other_parent())) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
966 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
967 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
968 fn has_tracked_dir( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
969 &mut self, |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
970 directory: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
971 ) -> Result<bool, DirstateError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
972 if let Some(node) = self.get_node(directory)? { |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
973 // 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:
47105
diff
changeset
|
974 // nodes, and is therefore a directory. |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
975 let state = node.state()?; |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
976 Ok(state.is_none() && node.tracked_descendants_count() > 0) |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
977 } else { |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
978 Ok(false) |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
979 } |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
980 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
981 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
982 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:
47334
diff
changeset
|
983 if let Some(node) = self.get_node(directory)? { |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
984 // 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:
47105
diff
changeset
|
985 // nodes, and is therefore a directory. |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
986 let state = node.state()?; |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
987 Ok(state.is_none() && node.descendants_with_entry_count() > 0) |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
988 } else { |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
989 Ok(false) |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
990 } |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
991 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
992 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
993 #[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
994 fn pack_v1( |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
995 &mut self, |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
996 parents: DirstateParents, |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
997 now: Timestamp, |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
998 ) -> Result<Vec<u8>, DirstateError> { |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
999 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:
47283
diff
changeset
|
1000 let mut ambiguous_mtimes = Vec::new(); |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1001 // Optizimation (to be measured?): pre-compute size to avoid `Vec` |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1002 // reallocations |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1003 let mut size = parents.as_bytes().len(); |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
1004 for node in self.iter_nodes() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1005 let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1006 if let Some(entry) = node.entry()? { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1007 size += packed_entry_size( |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1008 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:
47335
diff
changeset
|
1009 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:
47335
diff
changeset
|
1010 ); |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1011 if entry.mtime_is_ambiguous(now) { |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1012 ambiguous_mtimes.push( |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1013 node.full_path_borrowed(self.on_disk)? |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1014 .detach_from_tree(), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1015 ) |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1016 } |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1017 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1018 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1019 self.clear_known_ambiguous_mtimes(&ambiguous_mtimes)?; |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1020 |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1021 let mut packed = Vec::with_capacity(size); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1022 packed.extend(parents.as_bytes()); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1023 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
1024 for node in self.iter_nodes() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1025 let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1026 if let Some(entry) = node.entry()? { |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1027 pack_entry( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1028 node.full_path(self.on_disk)?, |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
1029 &entry, |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1030 node.copy_source(self.on_disk)?, |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1031 &mut packed, |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1032 ); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1033 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1034 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1035 Ok(packed) |
47095
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 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1038 #[timed] |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1039 fn pack_v2( |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1040 &mut self, |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1041 parents: DirstateParents, |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1042 now: Timestamp, |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1043 ) -> Result<Vec<u8>, DirstateError> { |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1044 // 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:
47283
diff
changeset
|
1045 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:
47283
diff
changeset
|
1046 let mut paths = Vec::new(); |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
1047 for node in self.iter_nodes() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1048 let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1049 if let Some(entry) = node.entry()? { |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1050 if entry.mtime_is_ambiguous(now) { |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1051 paths.push( |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1052 node.full_path_borrowed(self.on_disk)? |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1053 .detach_from_tree(), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
1054 ) |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1055 } |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1056 } |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1057 } |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1058 // 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:
47283
diff
changeset
|
1059 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1060 self.clear_known_ambiguous_mtimes(&paths)?; |
47330
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1061 |
73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
47283
diff
changeset
|
1062 on_disk::write(self, parents) |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1063 } |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1064 |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1065 fn status<'a>( |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1066 &'a mut self, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1067 matcher: &'a (dyn Matcher + Sync), |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1068 root_dir: PathBuf, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1069 ignore_files: Vec<PathBuf>, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1070 options: StatusOptions, |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
1071 ) -> 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:
47109
diff
changeset
|
1072 { |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1073 super::status::status(self, matcher, root_dir, ignore_files, options) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1074 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1075 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1076 fn copy_map_len(&self) -> usize { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
1077 self.nodes_with_copy_source_count as usize |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1078 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1079 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1080 fn copy_map_iter(&self) -> CopyMapIter<'_> { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1081 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:
47335
diff
changeset
|
1082 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:
47335
diff
changeset
|
1083 Some((node.full_path(self.on_disk)?, source)) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1084 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1085 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1086 }) |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1087 })) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1088 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1089 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1090 fn copy_map_contains_key( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1091 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1092 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1093 ) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1094 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:
47334
diff
changeset
|
1095 node.has_copy_source() |
47099
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
1096 } else { |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
1097 false |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1098 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1099 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1100 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1101 fn copy_map_get( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1102 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1103 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1104 ) -> Result<Option<&HgPath>, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1105 if let Some(node) = self.get_node(key)? { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1106 if let Some(source) = node.copy_source(self.on_disk)? { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1107 return Ok(Some(source)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1108 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1109 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1110 Ok(None) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1111 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1112 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1113 fn copy_map_remove( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1114 &mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1115 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1116 ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
1117 let count = &mut self.nodes_with_copy_source_count; |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1118 Ok( |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1119 Self::get_node_mut(self.on_disk, &mut self.root, key)?.and_then( |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1120 |node| { |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1121 if node.copy_source.is_some() { |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1122 *count -= 1 |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1123 } |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1124 node.copy_source.take().map(Cow::into_owned) |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1125 }, |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1126 ), |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1127 ) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1128 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1129 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1130 fn copy_map_insert( |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1131 &mut self, |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
1132 key: HgPathBuf, |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
1133 value: HgPathBuf, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1134 ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
47126
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
1135 let node = Self::get_or_insert_node( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1136 self.on_disk, |
47126
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
1137 &mut self.root, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
1138 &key, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
1139 WithBasename::to_cow_owned, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
1140 |_ancestor| {}, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1141 )?; |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
1142 if node.copy_source.is_none() { |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
1143 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:
47103
diff
changeset
|
1144 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1145 Ok(node.copy_source.replace(value.into()).map(Cow::into_owned)) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1146 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1147 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1148 fn len(&self) -> usize { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
1149 self.nodes_with_entry_count as usize |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1150 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1151 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1152 fn contains_key( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1153 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1154 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1155 ) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1156 Ok(self.get(key)?.is_some()) |
47095
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 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1159 fn get( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1160 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1161 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1162 ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1163 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:
47334
diff
changeset
|
1164 node.entry()? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1165 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1166 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1167 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1168 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1169 |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1170 fn iter(&self) -> StateMapIter<'_> { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1171 Box::new(filter_map_results(self.iter_nodes(), move |node| { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1172 Ok(if let Some(entry) = node.entry()? { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1173 Some((node.full_path(self.on_disk)?, entry)) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1174 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1175 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1176 }) |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1177 })) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1178 } |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1179 |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1180 fn iter_directories( |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1181 &self, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1182 ) -> Box< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1183 dyn Iterator< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1184 Item = Result< |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1185 (&HgPath, Option<Timestamp>), |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1186 DirstateV2ParseError, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1187 >, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1188 > + Send |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1189 + '_, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1190 > { |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1191 Box::new(filter_map_results(self.iter_nodes(), move |node| { |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1192 Ok(if node.state()?.is_none() { |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1193 Some(( |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1194 node.full_path(self.on_disk)?, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1195 node.cached_directory_mtime() |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1196 .map(|mtime| Timestamp(mtime.seconds())), |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1197 )) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1198 } else { |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1199 None |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1200 }) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1201 })) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1202 } |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1203 } |