Mercurial > hg
annotate rust/hg-core/src/dirstate/dirstate_map.rs @ 52303:b422acba55f1
rust-dirstate: remove star exports
This makes the crate's imports confusing and muddies the discovery of the
code.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 04 Nov 2024 11:07:05 +0100 |
parents | db065b33fa56 |
children | 04b9a56c2d25 |
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; |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
2 use std::borrow::Cow; |
52054
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
3 use std::fs::Metadata; |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
4 use std::os::unix::fs::MetadataExt; |
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; |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
9 use super::owning::OwningDirstateMap; |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
10 use super::path_with_basename::WithBasename; |
52303
b422acba55f1
rust-dirstate: remove star exports
Raphaël Gomès <rgomes@octobus.net>
parents:
52302
diff
changeset
|
11 use crate::dirstate::entry::{ |
b422acba55f1
rust-dirstate: remove star exports
Raphaël Gomès <rgomes@octobus.net>
parents:
52302
diff
changeset
|
12 DirstateEntry, DirstateV2Data, ParentFileData, TruncatedTimestamp, |
b422acba55f1
rust-dirstate: remove star exports
Raphaël Gomès <rgomes@octobus.net>
parents:
52302
diff
changeset
|
13 }; |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
14 use crate::dirstate::parsers::pack_entry; |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
15 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
|
16 use crate::dirstate::parsers::parse_dirstate_entries; |
48068
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
17 use crate::dirstate::CopyMapIter; |
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
18 use crate::dirstate::StateMapIter; |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
19 use crate::matchers::Matcher; |
49979
f5b168979626
rust: move `filter_map_results` to public util
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
20 use crate::utils::filter_map_results; |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
21 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
|
22 use crate::DirstateError; |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
23 use crate::DirstateMapError; |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
24 use crate::DirstateParents; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
25 use crate::DirstateStatus; |
48950
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48454
diff
changeset
|
26 use crate::FastHashbrownMap as 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::StatusError; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
29 use crate::StatusOptions; |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
30 |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
31 /// Append to an existing data file if the amount of unreachable data (not used |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
32 /// anymore) is less than this fraction of the total amount of existing data. |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
33 const ACCEPTABLE_UNREACHABLE_BYTES_RATIO: f32 = 0.5; |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
34 |
49337
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
35 #[derive(Debug, PartialEq, Eq)] |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
36 /// Version of the on-disk format |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
37 pub enum DirstateVersion { |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
38 V1, |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
39 V2, |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
40 } |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
41 |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
42 #[derive(Debug, PartialEq, Eq)] |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
43 pub enum DirstateMapWriteMode { |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
44 Auto, |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
45 ForceNewDataFile, |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
46 ForceAppend, |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
47 } |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
48 |
52054
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
49 /// Used to detect out-of-process changes in the dirstate |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
50 #[derive(Debug, Copy, Clone)] |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
51 pub struct DirstateIdentity { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
52 pub mode: u32, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
53 pub dev: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
54 pub ino: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
55 pub nlink: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
56 pub uid: u32, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
57 pub gid: u32, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
58 pub size: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
59 pub mtime: i64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
60 pub mtime_nsec: i64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
61 pub ctime: i64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
62 pub ctime_nsec: i64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
63 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
64 |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
65 impl From<Metadata> for DirstateIdentity { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
66 fn from(value: Metadata) -> Self { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
67 Self { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
68 mode: value.mode(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
69 dev: value.dev(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
70 ino: value.ino(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
71 nlink: value.nlink(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
72 uid: value.uid(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
73 gid: value.gid(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
74 size: value.size(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
75 mtime: value.mtime(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
76 mtime_nsec: value.mtime_nsec(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
77 ctime: value.ctime(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
78 ctime_nsec: value.ctime_nsec(), |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
79 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
80 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
81 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
82 |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
83 impl PartialEq for DirstateIdentity { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
84 fn eq(&self, other: &Self) -> bool { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
85 // Some platforms return 0 when they have no support for nanos. |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
86 // This shouldn't be a problem in practice because of how highly |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
87 // unlikely it is that we actually get exactly 0 nanos, and worst |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
88 // case scenario, we don't write out the dirstate in a non-wlocked |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
89 // situation like status. |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
90 let mtime_nanos_equal = (self.mtime_nsec == 0 |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
91 || other.mtime_nsec == 0) |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
92 || self.mtime_nsec == other.mtime_nsec; |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
93 let ctime_nanos_equal = (self.ctime_nsec == 0 |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
94 || other.ctime_nsec == 0) |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
95 || self.ctime_nsec == other.ctime_nsec; |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
96 |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
97 self.mode == other.mode |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
98 && self.dev == other.dev |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
99 && self.ino == other.ino |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
100 && self.nlink == other.nlink |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
101 && self.uid == other.uid |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
102 && self.gid == other.gid |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
103 && self.size == other.size |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
104 && self.mtime == other.mtime |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
105 && mtime_nanos_equal |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
106 && self.ctime == other.ctime |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
107 && ctime_nanos_equal |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
108 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
109 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
110 |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49124
diff
changeset
|
111 #[derive(Debug)] |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
112 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
|
113 /// 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
|
114 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
|
115 |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
116 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
|
117 |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
118 /// 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
|
119 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
|
120 |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
121 /// 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
|
122 /// `.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
|
123 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
|
124 |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47352
diff
changeset
|
125 /// See on_disk::Header |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47352
diff
changeset
|
126 pub(super) ignore_patterns_hash: on_disk::IgnorePatternsHash, |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
127 |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
128 /// How many bytes of `on_disk` are not used anymore |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
129 pub(super) unreachable_bytes: u32, |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
49003
diff
changeset
|
130 |
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
49003
diff
changeset
|
131 /// Size of the data used to first load this `DirstateMap`. Used in case |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
132 /// we need to write some new metadata, but no new data on disk, |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
133 /// as well as to detect writes that have happened in another process |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
134 /// since first read. |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
49003
diff
changeset
|
135 pub(super) old_data_size: usize, |
49337
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
136 |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
137 /// UUID used when first loading this `DirstateMap`. Used to check if |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
138 /// the UUID has been changed by another process since first read. |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
139 /// Can be `None` if using dirstate v1 or if it's a brand new dirstate. |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
140 pub(super) old_uuid: Option<Vec<u8>>, |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
141 |
50245
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
142 /// Identity of the dirstate file (for dirstate-v1) or the docket file |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
143 /// (v2). Used to detect if the file has changed from another process. |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
144 /// Since it's always written atomically, we can compare the inode to |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
145 /// check the file identity. |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
146 /// |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
147 /// TODO On non-Unix systems, something like hashing is a possibility? |
52054
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
148 pub(super) identity: Option<DirstateIdentity>, |
50245
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
149 |
49337
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
150 pub(super) dirstate_version: DirstateVersion, |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
151 |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
152 /// Controlled by config option `devel.dirstate.v2.data_update_mode` |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
153 pub(super) write_mode: DirstateMapWriteMode, |
52049
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
154 |
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
155 /// Controlled by config option `format.use-dirstate-tracked-hint` |
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
156 pub(super) use_tracked_hint: bool, |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
157 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
158 |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
159 /// 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
|
160 /// 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
|
161 /// 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
|
162 /// 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
|
163 /// 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
|
164 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
|
165 |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
166 /// 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
|
167 /// for on-disk nodes that don’t actually have a `Cow` to borrow. |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49124
diff
changeset
|
168 #[derive(Debug)] |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
169 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
|
170 InMemory(&'tree HgPathBuf), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
171 OnDisk(&'on_disk HgPath), |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
172 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
173 |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49124
diff
changeset
|
174 #[derive(Debug)] |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
175 pub(super) enum ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
176 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
|
177 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
|
178 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
179 |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49124
diff
changeset
|
180 #[derive(Debug)] |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
185 |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49124
diff
changeset
|
186 #[derive(Debug)] |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
191 |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
192 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
|
193 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
|
194 match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
195 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
|
196 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
|
197 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
198 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
199 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
200 |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
201 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
|
202 type Target = HgPath; |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
203 |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
204 fn deref(&self) -> &HgPath { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
205 match *self { |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
206 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
|
207 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
|
208 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
209 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
210 } |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
211 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
212 impl Default for ChildNodes<'_> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
213 fn default() -> Self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
214 ChildNodes::InMemory(Default::default()) |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
215 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
216 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
217 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
218 impl<'on_disk> ChildNodes<'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
219 pub(super) fn as_ref<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
220 &'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
221 ) -> ChildNodesRef<'tree, 'on_disk> { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
222 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
223 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
|
224 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
|
225 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
226 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
227 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
228 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
|
229 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
230 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
|
231 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
|
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 |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
235 fn make_mut( |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
236 &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
|
237 on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
238 unreachable_bytes: &mut u32, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
239 ) -> Result< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
240 &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
|
241 DirstateV2ParseError, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
242 > { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
243 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
244 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
|
245 ChildNodes::OnDisk(nodes) => { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
246 *unreachable_bytes += |
51120
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Raphaël Gomès <rgomes@octobus.net>
parents:
50863
diff
changeset
|
247 std::mem::size_of_val::<[on_disk::Node]>(*nodes) as u32; |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
248 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
|
249 .iter() |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
250 .map(|node| { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
251 Ok(( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
252 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
|
253 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
|
254 )) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
255 }) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
256 .collect::<Result<_, _>>()?; |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
257 *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
|
258 match self { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
259 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
|
260 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
|
261 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
262 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
263 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
264 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
265 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
266 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
267 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
|
268 pub(super) fn get( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
269 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
270 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
|
271 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
|
272 ) -> 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
|
273 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
274 ChildNodesRef::InMemory(nodes) => Ok(nodes |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
275 .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
|
276 .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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 Err(e) => { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
283 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
|
284 // 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
|
285 // 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
|
286 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
|
287 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
288 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
289 }); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
290 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
|
291 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
|
292 }) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
293 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
294 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
295 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
296 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
297 /// Iterate in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
298 pub(super) fn iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
299 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
300 ) -> 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
|
301 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
|
302 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
|
303 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
|
304 ), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
305 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
|
306 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
|
307 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
308 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
309 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
310 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
311 /// Iterate in parallel in undefined order |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
312 pub(super) fn par_iter( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
313 &self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
314 ) -> 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
|
315 { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
316 use rayon::prelude::*; |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 ), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
321 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
|
322 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
|
323 ), |
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 |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
327 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
|
328 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
329 ChildNodesRef::InMemory(nodes) => { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
330 let mut vec: Vec<_> = nodes |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
331 .iter() |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
332 .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
|
333 .collect(); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
334 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
|
335 match node { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
336 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
|
337 NodeRef::OnDisk(_) => unreachable!(), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
338 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
339 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
340 // `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
|
341 // 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
|
342 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
|
343 vec |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
344 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
345 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
|
346 // 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
|
347 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
|
348 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
349 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
350 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
351 } |
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 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
|
354 pub(super) fn full_path( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
355 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
356 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
|
357 ) -> Result<&'tree HgPath, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
358 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
359 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
|
360 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
|
361 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
362 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
363 |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
364 /// 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
|
365 /// HgPath>` detached from `'tree` |
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
366 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
|
367 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
368 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
|
369 ) -> 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
|
370 match self { |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
371 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
|
372 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
|
373 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
|
374 }, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
375 NodeRef::OnDisk(node) => { |
47347
73ddcedeaadf
dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
376 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
|
377 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
378 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
379 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
380 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
381 pub(super) fn base_name( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
382 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
383 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
|
384 ) -> Result<&'tree HgPath, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
385 match self { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
386 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
|
387 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
|
388 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
389 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
390 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
391 pub(super) fn children( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
392 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
393 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
|
394 ) -> 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
|
395 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
400 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
401 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
402 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
403 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
|
404 match self { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
405 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
|
406 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
|
407 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
408 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
409 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
410 pub(super) fn copy_source( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
411 &self, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
412 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
|
413 ) -> Result<Option<&'tree HgPath>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
414 match self { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
415 NodeRef::InMemory(_path, node) => Ok(node.copy_source.as_deref()), |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
416 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
|
417 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
418 } |
48454
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
419 /// Returns a `BorrowedPath`, which can be turned into a `Cow<'on_disk, |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
420 /// HgPath>` detached from `'tree` |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
421 pub(super) fn copy_source_borrowed( |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
422 &self, |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
423 on_disk: &'on_disk [u8], |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
424 ) -> Result<Option<BorrowedPath<'tree, 'on_disk>>, DirstateV2ParseError> |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
425 { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
426 Ok(match self { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
427 NodeRef::InMemory(_path, node) => { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
428 node.copy_source.as_ref().map(|source| match source { |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
429 Cow::Borrowed(on_disk) => BorrowedPath::OnDisk(on_disk), |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
430 Cow::Owned(in_memory) => BorrowedPath::InMemory(in_memory), |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
431 }) |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
432 } |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
433 NodeRef::OnDisk(node) => { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
434 node.copy_source(on_disk)?.map(BorrowedPath::OnDisk) |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
435 } |
48454
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
436 }) |
473af5cbc209
rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
437 } |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
438 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
439 pub(super) fn entry( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
440 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
441 ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
446 NodeRef::OnDisk(node) => node.entry(), |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
447 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
448 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
449 |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
450 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
|
451 &self, |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
452 ) -> Result<Option<TruncatedTimestamp>, DirstateV2ParseError> { |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
453 match self { |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
454 NodeRef::InMemory(_path, node) => Ok(match node.data { |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
455 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
|
456 _ => None, |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
457 }), |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
458 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
|
459 } |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
460 } |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
461 |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 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
|
466 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
467 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
|
468 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
469 } |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
470 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
471 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
|
472 match self { |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
473 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
|
474 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
|
475 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
476 } |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
477 } |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
478 |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
479 /// Represents a file or a directory |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49124
diff
changeset
|
480 #[derive(Default, Debug)] |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
481 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
|
482 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
|
483 |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
484 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
|
485 |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
486 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
|
487 |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
488 /// 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
|
489 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
|
490 |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
491 /// 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
|
492 /// 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
|
493 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
|
494 } |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
495 |
51707
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
496 #[derive(Debug, Default)] |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
497 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
|
498 Entry(DirstateEntry), |
51735
76c44ae8862e
rustfmt: apply formatting expected by newer nightly version
Raphaël Gomès <rgomes@octobus.net>
parents:
51707
diff
changeset
|
499 CachedDirectory { |
76c44ae8862e
rustfmt: apply formatting expected by newer nightly version
Raphaël Gomès <rgomes@octobus.net>
parents:
51707
diff
changeset
|
500 mtime: TruncatedTimestamp, |
76c44ae8862e
rustfmt: apply formatting expected by newer nightly version
Raphaël Gomès <rgomes@octobus.net>
parents:
51707
diff
changeset
|
501 }, |
51707
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
502 #[default] |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
503 None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
504 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
505 |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
506 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
|
507 fn has_entry(&self) -> bool { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
508 matches!(self, NodeData::Entry(_)) |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
509 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
510 |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
511 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
|
512 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
|
513 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
|
514 _ => None, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
515 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
516 } |
49106
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
517 |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
518 fn as_entry_mut(&mut self) -> Option<&mut DirstateEntry> { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
519 match self { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
520 NodeData::Entry(entry) => Some(entry), |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
521 _ => None, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
522 } |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
523 } |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
524 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
525 |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
526 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
|
527 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
|
528 Self { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
529 on_disk, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
530 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
|
531 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
|
532 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
|
533 ignore_patterns_hash: [0; on_disk::IGNORE_PATTERNS_HASH_LEN], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
534 unreachable_bytes: 0, |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
49003
diff
changeset
|
535 old_data_size: 0, |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
536 old_uuid: None, |
50245
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
537 identity: None, |
49337
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
538 dirstate_version: DirstateVersion::V1, |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
539 write_mode: DirstateMapWriteMode::Auto, |
52049
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
540 use_tracked_hint: false, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
541 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
542 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47282
diff
changeset
|
543 |
49913
c15b415d1bff
rust: use `logging_timer` instead of `micro_timer`
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
544 #[logging_timer::time("trace")] |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
545 pub fn new_v2( |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
546 on_disk: &'on_disk [u8], |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
547 data_size: usize, |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
548 metadata: &[u8], |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
549 uuid: Vec<u8>, |
52054
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
550 identity: Option<DirstateIdentity>, |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
551 ) -> Result<Self, DirstateError> { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
552 if let Some(data) = on_disk.get(..data_size) { |
50245
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
553 Ok(on_disk::read(data, metadata, uuid, identity)?) |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
554 } else { |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
555 Err(DirstateV2ParseError::new("not enough bytes on disk").into()) |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
556 } |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
557 } |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
558 |
49913
c15b415d1bff
rust: use `logging_timer` instead of `micro_timer`
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
559 #[logging_timer::time("trace")] |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
560 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
|
561 on_disk: &'on_disk [u8], |
52054
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Raphaël Gomès <rgomes@octobus.net>
parents:
52049
diff
changeset
|
562 identity: Option<DirstateIdentity>, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
563 ) -> 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
|
564 let mut map = Self::empty(on_disk); |
52033
88aa21d654e5
rust-dirstate: actually remember the identity
Raphaël Gomès <rgomes@octobus.net>
parents:
51735
diff
changeset
|
565 map.identity = identity; |
88aa21d654e5
rust-dirstate: actually remember the identity
Raphaël Gomès <rgomes@octobus.net>
parents:
51735
diff
changeset
|
566 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
567 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
|
568 return Ok((map, None)); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
569 } |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
570 |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
571 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
|
572 map.on_disk, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
573 |path, entry, copy_source| { |
49136
3f5e207f78be
rust: use `entry.tracked()` directly
Raphaël Gomès <rgomes@octobus.net>
parents:
49134
diff
changeset
|
574 let tracked = entry.tracked(); |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
575 let node = Self::get_or_insert_node_inner( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
576 map.on_disk, |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
577 &mut map.unreachable_bytes, |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
578 &mut map.root, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
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_borrowed, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
581 |ancestor| { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
582 if tracked { |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
583 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
|
584 } |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
585 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
|
586 }, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
587 )?; |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
588 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
|
589 !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
|
590 "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
|
591 ); |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
592 assert!( |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
593 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
|
594 "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
|
595 ); |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
596 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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
602 Ok(()) |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
603 }, |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
604 )?; |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
605 let parents = Some(*parents); |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
606 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
607 Ok((map, parents)) |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
608 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
609 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
610 /// Assuming dirstate-v2 format, returns whether the next write should |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
611 /// append to the existing data file that contains `self.on_disk` (true), |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
612 /// or create a new data file from scratch (false). |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
613 pub(super) fn write_should_append(&self) -> bool { |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
614 match self.write_mode { |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
615 DirstateMapWriteMode::ForceAppend => true, |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
616 DirstateMapWriteMode::ForceNewDataFile => false, |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
617 DirstateMapWriteMode::Auto => { |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
618 let ratio = |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
619 self.unreachable_bytes as f32 / self.on_disk.len() as f32; |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
620 ratio < ACCEPTABLE_UNREACHABLE_BYTES_RATIO |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
621 } |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
622 } |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
623 } |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
624 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
625 fn get_node<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
626 &'tree self, |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
627 path: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
628 ) -> 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
|
629 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
|
630 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
|
631 let mut component = |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
632 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
|
633 loop { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 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
|
638 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
639 return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
640 } |
47099
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
641 } else { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
642 return Ok(None); |
47099
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
643 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
644 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
645 } |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
646 |
50863
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
647 pub fn has_node( |
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
648 &self, |
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
649 path: &HgPath, |
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
650 ) -> Result<bool, DirstateV2ParseError> { |
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
651 let node = self.get_node(path)?; |
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
652 Ok(node.is_some()) |
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
653 } |
264072107105
rust-status: error on non-existent files in file_set
Spencer Baugh <sbaugh@janestreet.com>
parents:
50724
diff
changeset
|
654 |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
655 /// 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
|
656 /// |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
657 /// `each_ancestor` is a callback that is called for each ancestor node |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
658 /// when descending the tree. It is used to keep the different counters |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
659 /// of the `DirstateMap` up-to-date. |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
660 fn get_node_mut<'tree>( |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
661 &'tree mut self, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
662 path: &HgPath, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
663 each_ancestor: impl FnMut(&mut Node), |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
664 ) -> Result<Option<&'tree mut Node<'on_disk>>, DirstateV2ParseError> { |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
665 Self::get_node_mut_inner( |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
666 self.on_disk, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
667 &mut self.unreachable_bytes, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
668 &mut self.root, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
669 path, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
670 each_ancestor, |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
671 ) |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
672 } |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
673 |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
674 /// Lower-level version of `get_node_mut`. |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
675 /// |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
676 /// This takes `root` instead of `&mut self` so that callers can mutate |
49131
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
677 /// other fields while the returned borrow is still valid. |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
678 /// |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
679 /// `each_ancestor` is a callback that is called for each ancestor node |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
680 /// when descending the tree. It is used to keep the different counters |
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
681 /// of the `DirstateMap` up-to-date. |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
682 fn get_node_mut_inner<'tree>( |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
683 on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
684 unreachable_bytes: &mut u32, |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
685 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
|
686 path: &HgPath, |
49131
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
687 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
|
688 ) -> 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
|
689 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
|
690 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
|
691 let mut component = |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
692 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
|
693 loop { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
694 if let Some(child) = children |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
695 .make_mut(on_disk, unreachable_bytes)? |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
696 .get_mut(component) |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
697 { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
698 if let Some(next_component) = components.next() { |
49131
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
699 each_ancestor(child); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
700 component = next_component; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
701 children = &mut child.children; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
702 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
703 return Ok(Some(child)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
704 } |
47104
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
705 } else { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
706 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
|
707 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
708 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
709 } |
fdf6cfa0e254
dirstate-tree: Add copy_map_insert and copy_map_remove
Simon Sapin <simon.sapin@octobus.net>
parents:
47103
diff
changeset
|
710 |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
711 /// Get a mutable reference to the node at `path`, creating it if it does |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
712 /// not exist. |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
713 /// |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
714 /// `each_ancestor` is a callback that is called for each ancestor node |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
715 /// when descending the tree. It is used to keep the different counters |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
716 /// of the `DirstateMap` up-to-date. |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
717 fn get_or_insert_node<'tree, 'path>( |
47474
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
718 &'tree mut self, |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
719 path: &'path HgPath, |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
720 each_ancestor: impl FnMut(&mut Node), |
47474
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
721 ) -> Result<&'tree mut Node<'on_disk>, DirstateV2ParseError> { |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
722 Self::get_or_insert_node_inner( |
47474
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
723 self.on_disk, |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
724 &mut self.unreachable_bytes, |
47474
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
725 &mut self.root, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
726 path, |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
727 WithBasename::to_cow_owned, |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
728 each_ancestor, |
47474
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
729 ) |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
730 } |
c657beacdf2e
dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47409
diff
changeset
|
731 |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
732 /// Lower-level version of `get_or_insert_node_inner`, which is used when |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
733 /// parsing disk data to remove allocations for new nodes. |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
734 fn get_or_insert_node_inner<'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
|
735 on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
736 unreachable_bytes: &mut u32, |
47125
9be618452c3b
dirstate-tree: Borrow copy source paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
737 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
|
738 path: &'path HgPath, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
739 to_cow: impl Fn( |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
740 WithBasename<&'path HgPath>, |
ecfe0819ada5
dirstate-tree: Borrow paths from the "on disk" bytes
Simon Sapin <simon.sapin@octobus.net>
parents:
47125
diff
changeset
|
741 ) -> 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
|
742 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
|
743 ) -> 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
|
744 let mut child_nodes = root; |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
745 let mut inclusive_ancestor_paths = |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
746 WithBasename::inclusive_ancestors_of(path); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
747 let mut ancestor_path = inclusive_ancestor_paths |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
748 .next() |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
749 .expect("expected at least one inclusive ancestor"); |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
750 loop { |
48950
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48454
diff
changeset
|
751 let (_, child_node) = child_nodes |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
752 .make_mut(on_disk, unreachable_bytes)? |
48950
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48454
diff
changeset
|
753 .raw_entry_mut() |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48454
diff
changeset
|
754 .from_key(ancestor_path.base_name()) |
11c0411bf4e2
dirstate-tree: optimize HashMap lookups with raw_entry_mut
Simon Sapin <simon.sapin@octobus.net>
parents:
48454
diff
changeset
|
755 .or_insert_with(|| (to_cow(ancestor_path), Node::default())); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
756 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
|
757 each_ancestor(child_node); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
758 ancestor_path = next; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
759 child_nodes = &mut child_node.children; |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
760 } else { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
761 return Ok(child_node); |
47097
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
762 } |
e66ea29e2b1a
dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
763 } |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
764 } |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
765 |
49921
5fff90c7ea9d
rust-clippy: reassure `clippy` that 8 arguments is expected
Raphaël Gomès <rgomes@octobus.net>
parents:
49913
diff
changeset
|
766 #[allow(clippy::too_many_arguments)] |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
767 fn reset_state( |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
768 &mut self, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
769 filename: &HgPath, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
770 old_entry_opt: Option<DirstateEntry>, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
771 wc_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
772 p1_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
773 p2_info: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
774 has_meaningful_mtime: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
775 parent_file_data_opt: Option<ParentFileData>, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
776 ) -> Result<(), DirstateError> { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
777 let (had_entry, was_tracked) = match old_entry_opt { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
778 Some(old_entry) => (true, old_entry.tracked()), |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
779 None => (false, false), |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
780 }; |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
781 let node = self.get_or_insert_node(filename, |ancestor| { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
782 if !had_entry { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
783 ancestor.descendants_with_entry_count += 1; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
784 } |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
785 if was_tracked { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
786 if !wc_tracked { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
787 ancestor.tracked_descendants_count = ancestor |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
788 .tracked_descendants_count |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
789 .checked_sub(1) |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
790 .expect("tracked count to be >= 0"); |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
791 } |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
792 } else if wc_tracked { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
793 ancestor.tracked_descendants_count += 1; |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
794 } |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
795 })?; |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
796 |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
797 let v2_data = if let Some(parent_file_data) = parent_file_data_opt { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
798 DirstateV2Data { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
799 wc_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
800 p1_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
801 p2_info, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
802 mode_size: parent_file_data.mode_size, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
803 mtime: if has_meaningful_mtime { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
804 parent_file_data.mtime |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
805 } else { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
806 None |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
807 }, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
808 ..Default::default() |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
809 } |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
810 } else { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
811 DirstateV2Data { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
812 wc_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
813 p1_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
814 p2_info, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
815 ..Default::default() |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
816 } |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
817 }; |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
818 node.data = NodeData::Entry(DirstateEntry::from_v2_data(v2_data)); |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
819 if !had_entry { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
820 self.nodes_with_entry_count += 1; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
821 } |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
822 Ok(()) |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
823 } |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
824 |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
825 fn set_tracked( |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
826 &mut self, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
827 filename: &HgPath, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
828 old_entry_opt: Option<DirstateEntry>, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
829 ) -> Result<bool, DirstateV2ParseError> { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
830 let was_tracked = old_entry_opt.map_or(false, |e| e.tracked()); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
831 let had_entry = old_entry_opt.is_some(); |
51120
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Raphaël Gomès <rgomes@octobus.net>
parents:
50863
diff
changeset
|
832 let tracked_count_increment = u32::from(!was_tracked); |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
833 let mut new = false; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
834 |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
835 let node = self.get_or_insert_node(filename, |ancestor| { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
836 if !had_entry { |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
837 ancestor.descendants_with_entry_count += 1; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
838 } |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
839 |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
840 ancestor.tracked_descendants_count += tracked_count_increment; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
841 })?; |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
842 if let Some(old_entry) = old_entry_opt { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
843 let mut e = old_entry; |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
844 if e.tracked() { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
845 // XXX |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
846 // This is probably overkill for more case, but we need this to |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
847 // fully replace the `normallookup` call with `set_tracked` |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
848 // one. Consider smoothing this in the future. |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
849 e.set_possibly_dirty(); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
850 } else { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
851 new = true; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
852 e.set_tracked(); |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
853 } |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
854 node.data = NodeData::Entry(e) |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
855 } else { |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
856 node.data = NodeData::Entry(DirstateEntry::new_tracked()); |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
857 self.nodes_with_entry_count += 1; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
858 new = true; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
859 }; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
860 Ok(new) |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
861 } |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
862 |
49132
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
863 /// Set a node as untracked in the dirstate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
864 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
865 /// It is the responsibility of the caller to remove the copy source and/or |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
866 /// the entry itself if appropriate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
867 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
868 /// # Panics |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
869 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
870 /// Panics if the node does not exist. |
49108
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
871 fn set_untracked( |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
872 &mut self, |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
873 filename: &HgPath, |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
874 old_entry: DirstateEntry, |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
875 ) -> Result<(), DirstateV2ParseError> { |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
876 let node = self |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
877 .get_node_mut(filename, |ancestor| { |
49132
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
878 ancestor.tracked_descendants_count = ancestor |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
879 .tracked_descendants_count |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
880 .checked_sub(1) |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
881 .expect("tracked_descendants_count should be >= 0"); |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
882 })? |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
883 .expect("node should exist"); |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
884 let mut new_entry = old_entry; |
49108
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
885 new_entry.set_untracked(); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
886 node.data = NodeData::Entry(new_entry); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
887 Ok(()) |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
888 } |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
889 |
49132
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
890 /// Set a node as clean in the dirstate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
891 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
892 /// It is the responsibility of the caller to remove the copy source. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
893 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
894 /// # Panics |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
895 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
896 /// Panics if the node does not exist. |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
897 fn set_clean( |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
898 &mut self, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
899 filename: &HgPath, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
900 old_entry: DirstateEntry, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
901 mode: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
902 size: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
903 mtime: TruncatedTimestamp, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
904 ) -> Result<(), DirstateError> { |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
905 let node = self |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
906 .get_node_mut(filename, |ancestor| { |
49132
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
907 if !old_entry.tracked() { |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
908 ancestor.tracked_descendants_count += 1; |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
909 } |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
910 })? |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
911 .expect("node should exist"); |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
912 let mut new_entry = old_entry; |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
913 new_entry.set_clean(mode, size, mtime); |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
914 node.data = NodeData::Entry(new_entry); |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
915 Ok(()) |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
916 } |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
917 |
49132
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
918 /// Set a node as possibly dirty in the dirstate. |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
919 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
920 /// # Panics |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
921 /// |
7276a6007573
rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Raphaël Gomès <rgomes@octobus.net>
parents:
49131
diff
changeset
|
922 /// Panics if the node does not exist. |
49106
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
923 fn set_possibly_dirty( |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
924 &mut self, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
925 filename: &HgPath, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
926 ) -> Result<(), DirstateError> { |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
927 let node = self |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
928 .get_node_mut(filename, |_ancestor| {})? |
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
929 .expect("node should exist"); |
49106
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
930 let entry = node.data.as_entry_mut().expect("entry should exist"); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
931 entry.set_possibly_dirty(); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
932 node.data = NodeData::Entry(*entry); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
933 Ok(()) |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
934 } |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
935 |
49127
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
936 /// Clears the cached mtime for the (potential) folder at `path`. |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
937 pub(super) fn clear_cached_mtime( |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
938 &mut self, |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
939 path: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
940 ) -> Result<(), DirstateV2ParseError> { |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
941 let node = match self.get_node_mut(path, |_ancestor| {})? { |
49127
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
942 Some(node) => node, |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
943 None => return Ok(()), |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
944 }; |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
945 if let NodeData::CachedDirectory { .. } = &node.data { |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
946 node.data = NodeData::None |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
947 } |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
948 Ok(()) |
f3e8b0b0a8c2
rust-dirstatemap: add `clear_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49126
diff
changeset
|
949 } |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
950 |
49128
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
951 /// Sets the cached mtime for the (potential) folder at `path`. |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
952 pub(super) fn set_cached_mtime( |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
953 &mut self, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
954 path: &HgPath, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
955 mtime: TruncatedTimestamp, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
956 ) -> Result<(), DirstateV2ParseError> { |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
957 let node = match self.get_node_mut(path, |_ancestor| {})? { |
49128
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
958 Some(node) => node, |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
959 None => return Ok(()), |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
960 }; |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
961 match &node.data { |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
962 NodeData::Entry(_) => {} // Don’t overwrite an entry |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
963 NodeData::CachedDirectory { .. } | NodeData::None => { |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
964 node.data = NodeData::CachedDirectory { mtime } |
464747faef14
rust-dirstatemap: add `set_cached_mtime` helper method
Raphaël Gomès <rgomes@octobus.net>
parents:
49127
diff
changeset
|
965 } |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
966 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
967 Ok(()) |
47103
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
968 } |
214ae40e136b
dirstate-tree: Maintain a counter of DirstateEntry’s and copy sources
Simon Sapin <simon.sapin@octobus.net>
parents:
47102
diff
changeset
|
969 |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
970 fn iter_nodes<'tree>( |
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
971 &'tree self, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
972 ) -> impl Iterator< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
973 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
|
974 > + 'tree { |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
975 // Depth first tree traversal. |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
976 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
977 // 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
|
978 // this would look like: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
979 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
980 // ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
981 // fn traverse_children( |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
982 // children: &ChildNodes, |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
983 // each: &mut impl FnMut(&Node), |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
984 // ) { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
985 // for child in children.values() { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
986 // traverse_children(&child.children, each); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
987 // each(child); |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
988 // } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
989 // } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
990 // ``` |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
991 // |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
992 // 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
|
993 // call stack. Use an explicit stack instead: |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
994 let mut stack = Vec::new(); |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
995 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
|
996 std::iter::from_fn(move || { |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
997 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
|
998 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
|
999 Ok(children) => children, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1000 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
|
1001 }; |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1002 // Pseudo-recursion |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1003 let new_iter = children.iter(); |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1004 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
|
1005 stack.push((child_node, old_iter)); |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1006 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1007 // 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
|
1008 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
|
1009 // "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
|
1010 // explicit stack |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1011 iter = next_iter; |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1012 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1013 Some(Ok(child_node)) |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1014 } else { |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1015 // 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
|
1016 None |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1017 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1018 }) |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1019 } |
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1020 |
49922
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1021 fn count_dropped_path(unreachable_bytes: &mut u32, path: Cow<HgPath>) { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1022 if let Cow::Borrowed(path) = path { |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1023 *unreachable_bytes += path.len() as u32 |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1024 } |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1025 } |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
1026 |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
1027 pub(crate) fn set_write_mode(&mut self, write_mode: DirstateMapWriteMode) { |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
1028 self.write_mode = write_mode; |
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
1029 } |
52049
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
1030 |
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
1031 pub(crate) fn set_tracked_hint(&mut self, tracked_hint: bool) { |
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
1032 self.use_tracked_hint = tracked_hint; |
a8cf6a852f11
rust-dirstate: pass dirstate tracked key from the requirements
Raphaël Gomès <rgomes@octobus.net>
parents:
52044
diff
changeset
|
1033 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1034 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1035 |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1036 /// Sets the parameters for resetting a dirstate entry |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1037 pub struct DirstateEntryReset<'a> { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1038 /// Which entry are we resetting |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1039 pub filename: &'a HgPath, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1040 /// Whether the entry is tracked in the working copy |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1041 pub wc_tracked: bool, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1042 /// Whether the entry is tracked in p1 |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1043 pub p1_tracked: bool, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1044 /// Whether the entry has merge information |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1045 pub p2_info: bool, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1046 /// Whether the entry's mtime should be trusted |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1047 pub has_meaningful_mtime: bool, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1048 /// Information from the parent file data (from the manifest) |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1049 pub parent_file_data_opt: Option<ParentFileData>, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1050 /// Set this to `true` if you are *certain* that there is no old entry for |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1051 /// this filename. Yield better performance in cases where we do a lot |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1052 /// of additions to the dirstate. |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1053 pub from_empty: bool, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1054 } |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1055 |
49924
66ffe3749a48
rust-clippy: simplify return type of debug function
Raphaël Gomès <rgomes@octobus.net>
parents:
49923
diff
changeset
|
1056 type DebugDirstateTuple<'a> = (&'a HgPath, (u8, i32, i32, i32)); |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1057 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1058 impl OwningDirstateMap { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1059 pub fn clear(&mut self) { |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1060 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1061 map.root = Default::default(); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1062 map.nodes_with_entry_count = 0; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1063 map.nodes_with_copy_source_count = 0; |
50724
a10d823a8e3d
dirstate: avoid leaking disk space in `hg debugrebuilddirstate`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50252
diff
changeset
|
1064 map.unreachable_bytes = map.on_disk.len() as u32; |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1065 }); |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1066 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1067 |
49097
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1068 pub fn set_tracked( |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1069 &mut self, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1070 filename: &HgPath, |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1071 ) -> Result<bool, DirstateV2ParseError> { |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1072 let old_entry_opt = self.get(filename)?; |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1073 self.with_dmap_mut(|map| map.set_tracked(filename, old_entry_opt)) |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1074 } |
791430b0b2d2
rust-dirstatemap: add `set_tracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49045
diff
changeset
|
1075 |
49108
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1076 pub fn set_untracked( |
48047
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48046
diff
changeset
|
1077 &mut self, |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48046
diff
changeset
|
1078 filename: &HgPath, |
49108
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1079 ) -> Result<bool, DirstateError> { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1080 let old_entry_opt = self.get(filename)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1081 match old_entry_opt { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1082 None => Ok(false), |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1083 Some(old_entry) => { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1084 if !old_entry.tracked() { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1085 // `DirstateMap::set_untracked` is not a noop if |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1086 // already not tracked as it will decrement the |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1087 // tracked counters while going down. |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1088 return Ok(true); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1089 } |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1090 if old_entry.added() { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1091 // Untracking an "added" entry will just result in a |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1092 // worthless entry (and other parts of the code will |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1093 // complain about it), just drop it entirely. |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1094 self.drop_entry_and_copy_source(filename)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1095 return Ok(true); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1096 } |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1097 if !old_entry.p2_info() { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1098 self.copy_map_remove(filename)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1099 } |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1100 |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1101 self.with_dmap_mut(|map| { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1102 map.set_untracked(filename, old_entry)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1103 Ok(true) |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1104 }) |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1105 } |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49106
diff
changeset
|
1106 } |
47692
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47683
diff
changeset
|
1107 } |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47683
diff
changeset
|
1108 |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1109 pub fn set_clean( |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1110 &mut self, |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
1111 filename: &HgPath, |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1112 mode: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1113 size: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1114 mtime: TruncatedTimestamp, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1115 ) -> Result<(), DirstateError> { |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1116 let old_entry = match self.get(filename)? { |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1117 None => { |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1118 return Err( |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1119 DirstateMapError::PathNotFound(filename.into()).into() |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1120 ) |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1121 } |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1122 Some(e) => e, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1123 }; |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1124 self.copy_map_remove(filename)?; |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1125 self.with_dmap_mut(|map| { |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49101
diff
changeset
|
1126 map.set_clean(filename, old_entry, mode, size, mtime) |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
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 |
49106
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1130 pub fn set_possibly_dirty( |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1131 &mut self, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1132 filename: &HgPath, |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1133 ) -> Result<(), DirstateError> { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1134 if self.get(filename)?.is_none() { |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1135 return Err(DirstateMapError::PathNotFound(filename.into()).into()); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1136 } |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1137 self.with_dmap_mut(|map| map.set_possibly_dirty(filename)) |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1138 } |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents:
49104
diff
changeset
|
1139 |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
1140 pub fn reset_state( |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1141 &mut self, |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1142 reset: DirstateEntryReset, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1143 ) -> Result<(), DirstateError> { |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1144 if !(reset.p1_tracked || reset.p2_info || reset.wc_tracked) { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1145 self.drop_entry_and_copy_source(reset.filename)?; |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
1146 return Ok(()); |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
1147 } |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1148 if !reset.from_empty { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1149 self.copy_map_remove(reset.filename)?; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1150 } |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1151 |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1152 let old_entry_opt = if reset.from_empty { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1153 None |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1154 } else { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1155 self.get(reset.filename)? |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1156 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1157 |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1158 self.with_dmap_mut(|map| { |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
1159 map.reset_state( |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1160 reset.filename, |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
1161 old_entry_opt, |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1162 reset.wc_tracked, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1163 reset.p1_tracked, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1164 reset.p2_info, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1165 reset.has_meaningful_mtime, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1166 reset.parent_file_data_opt, |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
49097
diff
changeset
|
1167 ) |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1168 }) |
47095
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 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1171 pub fn drop_entry_and_copy_source( |
48050
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48048
diff
changeset
|
1172 &mut self, |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48048
diff
changeset
|
1173 filename: &HgPath, |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48048
diff
changeset
|
1174 ) -> Result<(), DirstateError> { |
49123
afe60def963d
rust-dirstatemap: use `DirstateEntry::tracked` directly
Raphaël Gomès <rgomes@octobus.net>
parents:
49121
diff
changeset
|
1175 let was_tracked = self.get(filename)?.map_or(false, |e| e.tracked()); |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1176 struct Dropped { |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1177 was_tracked: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1178 had_entry: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1179 had_copy_source: bool, |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1180 } |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1181 |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1182 /// 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
|
1183 /// |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1184 /// * `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
|
1185 /// * `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
|
1186 /// 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
|
1187 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
|
1188 on_disk: &'on_disk [u8], |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1189 unreachable_bytes: &mut u32, |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1190 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
|
1191 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
|
1192 ) -> 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
|
1193 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
|
1194 path.split_first_component(); |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1195 let nodes = nodes.make_mut(on_disk, unreachable_bytes)?; |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1196 let node = if let Some(node) = nodes.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
|
1197 { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1198 node |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1199 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1200 return Ok(None); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1201 }; |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1202 let dropped; |
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1203 if let Some(rest) = rest_of_path { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1204 if let Some((d, removed)) = recur( |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1205 on_disk, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1206 unreachable_bytes, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1207 &mut node.children, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1208 rest, |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1209 )? { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1210 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
|
1211 if dropped.had_entry { |
49001
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1212 node.descendants_with_entry_count = node |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1213 .descendants_with_entry_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1214 .checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1215 .expect( |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1216 "descendants_with_entry_count should be >= 0", |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1217 ); |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47477
diff
changeset
|
1218 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1219 if dropped.was_tracked { |
49001
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1220 node.tracked_descendants_count = node |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1221 .tracked_descendants_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1222 .checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1223 .expect( |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1224 "tracked_descendants_count should be >= 0", |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1225 ); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1226 } |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1227 |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1228 // 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
|
1229 // child node |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1230 if removed { |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1231 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
|
1232 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
|
1233 } |
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1234 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1235 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1236 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
|
1237 } |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1238 } else { |
49002
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
49001
diff
changeset
|
1239 let entry = node.data.as_entry(); |
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
49001
diff
changeset
|
1240 let was_tracked = entry.map_or(false, |entry| entry.tracked()); |
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
49001
diff
changeset
|
1241 let had_entry = entry.is_some(); |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47347
diff
changeset
|
1242 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
|
1243 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
|
1244 } |
49003
ce919b1a1063
rust-dirstatemap: correctly decrement the copies counter
Raphaël Gomès <rgomes@octobus.net>
parents:
49002
diff
changeset
|
1245 let mut had_copy_source = false; |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1246 if let Some(source) = &node.copy_source { |
49922
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1247 DirstateMap::count_dropped_path( |
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1248 unreachable_bytes, |
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1249 Cow::Borrowed(source), |
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1250 ); |
49003
ce919b1a1063
rust-dirstatemap: correctly decrement the copies counter
Raphaël Gomès <rgomes@octobus.net>
parents:
49002
diff
changeset
|
1251 had_copy_source = true; |
48050
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48048
diff
changeset
|
1252 node.copy_source = None |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1253 } |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1254 dropped = Dropped { |
49002
fbc02ccc207e
rust-dirstatemap: properly decrement counter for tracked descendants
Raphaël Gomès <rgomes@octobus.net>
parents:
49001
diff
changeset
|
1255 was_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
|
1256 had_entry, |
49003
ce919b1a1063
rust-dirstatemap: correctly decrement the copies counter
Raphaël Gomès <rgomes@octobus.net>
parents:
49002
diff
changeset
|
1257 had_copy_source, |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1258 }; |
47193
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47192
diff
changeset
|
1259 } |
47ccab19bf9f
dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry`
Simon Sapin <simon.sapin@octobus.net>
parents:
47192
diff
changeset
|
1260 // 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
|
1261 // 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
|
1262 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
|
1263 && 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
|
1264 && 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
|
1265 if remove { |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1266 let (key, _) = |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1267 nodes.remove_entry(first_path_component).unwrap(); |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1268 DirstateMap::count_dropped_path( |
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1269 unreachable_bytes, |
49922
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1270 Cow::Borrowed(key.full_path()), |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
1271 ) |
47192
1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
Simon Sapin <simon.sapin@octobus.net>
parents:
47126
diff
changeset
|
1272 } |
47352
9d58e54b5966
dirstate-v2: Drop parent directory cache when removing a dirstate node
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
1273 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
|
1274 } |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
1275 |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1276 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1277 if let Some((dropped, _removed)) = recur( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1278 map.on_disk, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1279 &mut map.unreachable_bytes, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1280 &mut map.root, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1281 filename, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1282 )? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1283 if dropped.had_entry { |
49001
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1284 map.nodes_with_entry_count = map |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1285 .nodes_with_entry_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1286 .checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1287 .expect("nodes_with_entry_count should be >= 0"); |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1288 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1289 if dropped.had_copy_source { |
49001
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1290 map.nodes_with_copy_source_count = map |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1291 .nodes_with_copy_source_count |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1292 .checked_sub(1) |
2593873cda0f
rust-dirstate: panic if the DirstateMap counters go below 0
Raphaël Gomès <rgomes@octobus.net>
parents:
49000
diff
changeset
|
1293 .expect("nodes_with_copy_source_count should be >= 0"); |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1294 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1295 } else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1296 debug_assert!(!was_tracked); |
47107
7dfc598ddcfe
dirstate-tree: Add add_file, remove_file, and drop_file
Simon Sapin <simon.sapin@octobus.net>
parents:
47106
diff
changeset
|
1297 } |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1298 Ok(()) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1299 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1300 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1301 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1302 pub fn has_tracked_dir( |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1303 &mut self, |
47106
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
1304 directory: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1305 ) -> Result<bool, DirstateError> { |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1306 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1307 if let Some(node) = map.get_node(directory)? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1308 // A node without a `DirstateEntry` was created to hold child |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1309 // nodes, and is therefore a directory. |
49140
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49136
diff
changeset
|
1310 let is_dir = node.entry()?.is_none(); |
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49136
diff
changeset
|
1311 Ok(is_dir && node.tracked_descendants_count() > 0) |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1312 } else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1313 Ok(false) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1314 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1315 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1316 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1317 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1318 pub fn has_dir( |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1319 &mut self, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1320 directory: &HgPath, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1321 ) -> Result<bool, DirstateError> { |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1322 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1323 if let Some(node) = map.get_node(directory)? { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1324 // A node without a `DirstateEntry` was created to hold child |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1325 // nodes, and is therefore a directory. |
49140
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49136
diff
changeset
|
1326 let is_dir = node.entry()?.is_none(); |
748ac6400eaa
rust-dirstatemap: stop using `state()` in the cache logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49136
diff
changeset
|
1327 Ok(is_dir && node.descendants_with_entry_count() > 0) |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1328 } else { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1329 Ok(false) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1330 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1331 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1332 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1333 |
49913
c15b415d1bff
rust: use `logging_timer` instead of `micro_timer`
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
1334 #[logging_timer::time("trace")] |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1335 pub fn pack_v1( |
48416
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48392
diff
changeset
|
1336 &self, |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1337 parents: DirstateParents, |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1338 ) -> Result<Vec<u8>, DirstateError> { |
48416
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48392
diff
changeset
|
1339 let map = self.get_map(); |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1340 // 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
|
1341 // reallocations |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1342 let mut size = parents.as_bytes().len(); |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1343 for node in map.iter_nodes() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1344 let node = node?; |
48392
434de12918fd
dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48260
diff
changeset
|
1345 if node.entry()?.is_some() { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1346 size += packed_entry_size( |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1347 node.full_path(map.on_disk)?, |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1348 node.copy_source(map.on_disk)?, |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
1349 ); |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1350 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1351 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1352 |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1353 let mut packed = Vec::with_capacity(size); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1354 packed.extend(parents.as_bytes()); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1355 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1356 for node in map.iter_nodes() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1357 let node = node?; |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1358 if let Some(entry) = node.entry()? { |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1359 pack_entry( |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1360 node.full_path(map.on_disk)?, |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
1361 &entry, |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1362 node.copy_source(map.on_disk)?, |
47102
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1363 &mut packed, |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1364 ); |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1365 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1366 } |
d6c94ca40863
dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
1367 Ok(packed) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1368 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1369 |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1370 /// Returns new data and metadata together with whether that data should be |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
1371 /// appended to the existing data file whose content is at |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1372 /// `map.on_disk` (true), instead of written to a new data file |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
49003
diff
changeset
|
1373 /// (false), and the previous size of data on disk. |
49913
c15b415d1bff
rust: use `logging_timer` instead of `micro_timer`
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
1374 #[logging_timer::time("trace")] |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1375 pub fn pack_v2( |
48416
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48392
diff
changeset
|
1376 &self, |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
1377 write_mode: DirstateMapWriteMode, |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
49003
diff
changeset
|
1378 ) -> Result<(Vec<u8>, on_disk::TreeMetadata, bool, usize), DirstateError> |
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
49003
diff
changeset
|
1379 { |
48416
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48392
diff
changeset
|
1380 let map = self.get_map(); |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
1381 on_disk::write(map, write_mode) |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1382 } |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47193
diff
changeset
|
1383 |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1384 /// `callback` allows the caller to process and do something with the |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1385 /// results of the status. This is needed to do so efficiently (i.e. |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1386 /// without cloning the `DirstateStatus` object with its paths) because |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1387 /// we need to borrow from `Self`. |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1388 pub fn with_status<R>( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1389 &mut self, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1390 matcher: &(dyn Matcher + Sync), |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1391 root_dir: PathBuf, |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
1392 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
|
1393 options: StatusOptions, |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1394 callback: impl for<'r> FnOnce( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1395 Result<(DirstateStatus<'r>, Vec<PatternFileWarning>), StatusError>, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1396 ) -> R, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1397 ) -> R { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1398 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1399 callback(super::status::status( |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1400 map, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1401 matcher, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1402 root_dir, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1403 ignore_files, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1404 options, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1405 )) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1406 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1407 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1408 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1409 pub fn copy_map_len(&self) -> usize { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1410 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1411 map.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
|
1412 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1413 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1414 pub fn copy_map_iter(&self) -> CopyMapIter<'_> { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1415 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1416 Box::new(filter_map_results(map.iter_nodes(), move |node| { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1417 Ok(if let Some(source) = node.copy_source(map.on_disk)? { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1418 Some((node.full_path(map.on_disk)?, source)) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1419 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1420 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1421 }) |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1422 })) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1423 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1424 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1425 pub fn copy_map_contains_key( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1426 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1427 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1428 ) -> Result<bool, DirstateV2ParseError> { |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1429 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1430 Ok(if let Some(node) = map.get_node(key)? { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1431 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
|
1432 } else { |
3da19db33cbc
dirstate-tree: Add map `get` and `contains_key` methods
Simon Sapin <simon.sapin@octobus.net>
parents:
47098
diff
changeset
|
1433 false |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1434 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1435 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1436 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1437 pub fn copy_map_get( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1438 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1439 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1440 ) -> Result<Option<&HgPath>, DirstateV2ParseError> { |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1441 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1442 if let Some(node) = map.get_node(key)? { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1443 if let Some(source) = node.copy_source(map.on_disk)? { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1444 return Ok(Some(source)); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1445 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1446 } |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1447 Ok(None) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1448 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1449 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1450 pub fn copy_map_remove( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1451 &mut self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1452 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1453 ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1454 self.with_dmap_mut(|map| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1455 let count = &mut map.nodes_with_copy_source_count; |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1456 let unreachable_bytes = &mut map.unreachable_bytes; |
49133
23a5659125c8
rust-dirstatemap: add simpler version of `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49132
diff
changeset
|
1457 Ok(DirstateMap::get_node_mut_inner( |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1458 map.on_disk, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1459 unreachable_bytes, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1460 &mut map.root, |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1461 key, |
49131
fcf6f943a142
rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`
Raphaël Gomès <rgomes@octobus.net>
parents:
49130
diff
changeset
|
1462 |_ancestor| {}, |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1463 )? |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1464 .and_then(|node| { |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1465 if let Some(source) = &node.copy_source { |
49134
8c59d8adcf5b
rust-dirstatemap: use a checked sub instead of a potentially underflowing one
Raphaël Gomès <rgomes@octobus.net>
parents:
49133
diff
changeset
|
1466 *count = count |
8c59d8adcf5b
rust-dirstatemap: use a checked sub instead of a potentially underflowing one
Raphaël Gomès <rgomes@octobus.net>
parents:
49133
diff
changeset
|
1467 .checked_sub(1) |
8c59d8adcf5b
rust-dirstatemap: use a checked sub instead of a potentially underflowing one
Raphaël Gomès <rgomes@octobus.net>
parents:
49133
diff
changeset
|
1468 .expect("nodes_with_copy_source_count should be >= 0"); |
49922
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1469 DirstateMap::count_dropped_path( |
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1470 unreachable_bytes, |
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1471 Cow::Borrowed(source), |
b6dc4802e7ef
rust: don't use a reference to a `Cow`
Raphaël Gomès <rgomes@octobus.net>
parents:
49921
diff
changeset
|
1472 ); |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1473 } |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1474 node.copy_source.take().map(Cow::into_owned) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1475 })) |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1476 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1477 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1478 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1479 pub fn copy_map_insert( |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1480 &mut self, |
49124
d9a66d62c604
rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents:
49123
diff
changeset
|
1481 key: &HgPath, |
d9a66d62c604
rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents:
49123
diff
changeset
|
1482 value: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1483 ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1484 self.with_dmap_mut(|map| { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
1485 let node = map.get_or_insert_node(key, |_ancestor| {})?; |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1486 let had_copy_source = node.copy_source.is_none(); |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1487 let old = node |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1488 .copy_source |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1489 .replace(value.to_owned().into()) |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1490 .map(Cow::into_owned); |
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1491 if had_copy_source { |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1492 map.nodes_with_copy_source_count += 1 |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1493 } |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1494 Ok(old) |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1495 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1496 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1497 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1498 pub fn len(&self) -> usize { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1499 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1500 map.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
|
1501 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1502 |
49923
547d6817e0c3
rust-clippy: add `is_empty` method to please the `clippy` gods
Raphaël Gomès <rgomes@octobus.net>
parents:
49922
diff
changeset
|
1503 pub fn is_empty(&self) -> bool { |
547d6817e0c3
rust-clippy: add `is_empty` method to please the `clippy` gods
Raphaël Gomès <rgomes@octobus.net>
parents:
49922
diff
changeset
|
1504 self.len() == 0 |
547d6817e0c3
rust-clippy: add `is_empty` method to please the `clippy` gods
Raphaël Gomès <rgomes@octobus.net>
parents:
49922
diff
changeset
|
1505 } |
547d6817e0c3
rust-clippy: add `is_empty` method to please the `clippy` gods
Raphaël Gomès <rgomes@octobus.net>
parents:
49922
diff
changeset
|
1506 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1507 pub fn contains_key( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1508 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1509 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1510 ) -> Result<bool, DirstateV2ParseError> { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1511 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
|
1512 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1513 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1514 pub fn get( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1515 &self, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1516 key: &HgPath, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1517 ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1518 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1519 Ok(if let Some(node) = map.get_node(key)? { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1520 node.entry()? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1521 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1522 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1523 }) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1524 } |
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1525 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1526 pub fn iter(&self) -> StateMapIter<'_> { |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1527 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1528 Box::new(filter_map_results(map.iter_nodes(), move |node| { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1529 Ok(if let Some(entry) = node.entry()? { |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1530 Some((node.full_path(map.on_disk)?, entry)) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1531 } else { |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1532 None |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
1533 }) |
47100
caa3031c9ed5
dirstate-tree: Add tree traversal/iteration
Simon Sapin <simon.sapin@octobus.net>
parents:
47099
diff
changeset
|
1534 })) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1535 } |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1536 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1537 pub fn iter_tracked_dirs( |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1538 &mut self, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1539 ) -> Result< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1540 Box< |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1541 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1542 + Send |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1543 + '_, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1544 >, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1545 DirstateError, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1546 > { |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents:
48454
diff
changeset
|
1547 let map = self.get_map(); |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1548 let on_disk = map.on_disk; |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1549 Ok(Box::new(filter_map_results( |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1550 map.iter_nodes(), |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1551 move |node| { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1552 Ok(if node.tracked_descendants_count() > 0 { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1553 Some(node.full_path(on_disk)?) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1554 } else { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1555 None |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1556 }) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1557 }, |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1558 ))) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1559 } |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1560 |
49120
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1561 /// Only public because it needs to be exposed to the Python layer. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1562 /// It is not the full `setparents` logic, only the parts that mutate the |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1563 /// entries. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1564 pub fn setparents_fixup( |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1565 &mut self, |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1566 ) -> Result<Vec<(HgPathBuf, HgPathBuf)>, DirstateV2ParseError> { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1567 // XXX |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1568 // All the copying and re-querying is quite inefficient, but this is |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1569 // still a lot better than doing it from Python. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1570 // |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1571 // The better solution is to develop a mechanism for `iter_mut`, |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1572 // which will be a lot more involved: we're dealing with a lazy, |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1573 // append-mostly, tree-like data structure. This will do for now. |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1574 let mut copies = vec![]; |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1575 let mut files_with_p2_info = vec![]; |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1576 for res in self.iter() { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1577 let (path, entry) = res?; |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1578 if entry.p2_info() { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1579 files_with_p2_info.push(path.to_owned()) |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1580 } |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1581 } |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1582 self.with_dmap_mut(|map| { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1583 for path in files_with_p2_info.iter() { |
49130
3926bfef28e4
rust-dirstatemap: add simpler method `get_or_insert_node` for the common case
Raphaël Gomès <rgomes@octobus.net>
parents:
49129
diff
changeset
|
1584 let node = map.get_or_insert_node(path, |_| {})?; |
49120
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1585 let entry = |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1586 node.data.as_entry_mut().expect("entry should exist"); |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1587 entry.drop_merge_data(); |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1588 if let Some(source) = node.copy_source.take().as_deref() { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1589 copies.push((path.to_owned(), source.to_owned())); |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1590 } |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1591 } |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1592 Ok(copies) |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1593 }) |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1594 } |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents:
49112
diff
changeset
|
1595 |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1596 pub fn debug_iter( |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1597 &self, |
48023
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
1598 all: bool, |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1599 ) -> Box< |
49924
66ffe3749a48
rust-clippy: simplify return type of debug function
Raphaël Gomès <rgomes@octobus.net>
parents:
49923
diff
changeset
|
1600 dyn Iterator<Item = Result<DebugDirstateTuple, DirstateV2ParseError>> |
66ffe3749a48
rust-clippy: simplify return type of debug function
Raphaël Gomès <rgomes@octobus.net>
parents:
49923
diff
changeset
|
1601 + Send |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1602 + '_, |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1603 > { |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1604 let map = self.get_map(); |
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1605 Box::new(filter_map_results(map.iter_nodes(), move |node| { |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1606 let debug_tuple = if let Some(entry) = node.entry()? { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1607 entry.debug_tuple() |
48023
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
1608 } else if !all { |
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
1609 return Ok(None); |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
1610 } else if let Some(mtime) = node.cached_directory_mtime()? { |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
1611 (b' ', 0, -1, mtime.truncated_seconds() as i32) |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1612 } else { |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1613 (b' ', 0, -1, -1) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
1614 }; |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
1615 Ok(Some((node.full_path(map.on_disk)?, debug_tuple))) |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1616 })) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47349
diff
changeset
|
1617 } |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1618 } |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1619 #[cfg(test)] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1620 mod tests { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1621 use super::*; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1622 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1623 /// Shortcut to return tracked descendants of a path. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1624 /// Panics if the path does not exist. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1625 fn tracked_descendants(map: &OwningDirstateMap, path: &[u8]) -> u32 { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1626 let path = dbg!(HgPath::new(path)); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1627 let node = map.get_map().get_node(path); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1628 node.unwrap().unwrap().tracked_descendants_count() |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1629 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1630 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1631 /// Shortcut to return descendants with an entry. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1632 /// Panics if the path does not exist. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1633 fn descendants_with_an_entry(map: &OwningDirstateMap, path: &[u8]) -> u32 { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1634 let path = dbg!(HgPath::new(path)); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1635 let node = map.get_map().get_node(path); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1636 node.unwrap().unwrap().descendants_with_entry_count() |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1637 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1638 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1639 fn assert_does_not_exist(map: &OwningDirstateMap, path: &[u8]) { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1640 let path = dbg!(HgPath::new(path)); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1641 let node = map.get_map().get_node(path); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1642 assert!(node.unwrap().is_none()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1643 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1644 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1645 /// Shortcut for path creation in tests |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1646 fn p(b: &[u8]) -> &HgPath { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1647 HgPath::new(b) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1648 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1649 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1650 /// Test the very simple case a single tracked file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1651 #[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1652 fn test_tracked_descendants_simple() -> Result<(), DirstateError> { |
52033
88aa21d654e5
rust-dirstate: actually remember the identity
Raphaël Gomès <rgomes@octobus.net>
parents:
51735
diff
changeset
|
1653 let mut map = OwningDirstateMap::new_empty(vec![], None); |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1654 assert_eq!(map.len(), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1655 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1656 map.set_tracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1657 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1658 assert_eq!(map.len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1659 assert_eq!(tracked_descendants(&map, b"some"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1660 assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1661 assert_eq!(tracked_descendants(&map, b"some/nested/path"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1662 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1663 map.set_untracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1664 assert_eq!(map.len(), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1665 assert!(map.get_map().get_node(p(b"some"))?.is_none()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1666 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1667 Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1668 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1669 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1670 /// Test the simple case of all tracked, but multiple files |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1671 #[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1672 fn test_tracked_descendants_multiple() -> Result<(), DirstateError> { |
52033
88aa21d654e5
rust-dirstate: actually remember the identity
Raphaël Gomès <rgomes@octobus.net>
parents:
51735
diff
changeset
|
1673 let mut map = OwningDirstateMap::new_empty(vec![], None); |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1674 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1675 map.set_tracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1676 map.set_tracked(p(b"some/nested/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1677 // one layer without any files to test deletion cascade |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1678 map.set_tracked(p(b"some/other/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1679 map.set_tracked(p(b"root_file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1680 map.set_tracked(p(b"some/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1681 map.set_tracked(p(b"some/file2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1682 map.set_tracked(p(b"some/file3"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1683 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1684 assert_eq!(map.len(), 7); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1685 assert_eq!(tracked_descendants(&map, b"some"), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1686 assert_eq!(tracked_descendants(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1687 assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1688 assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1689 assert_eq!(tracked_descendants(&map, b"some/nested/path"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1690 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1691 map.set_untracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1692 assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1693 assert_eq!(tracked_descendants(&map, b"some"), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1694 assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1695 assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1696 assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1697 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1698 map.set_untracked(p(b"some/nested/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1699 assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1700 assert_eq!(tracked_descendants(&map, b"some"), 4); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1701 assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1702 assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1703 assert_does_not_exist(&map, b"some_nested"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1704 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1705 map.set_untracked(p(b"some/other/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1706 assert_eq!(map.len(), 4); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1707 assert_eq!(tracked_descendants(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1708 assert_does_not_exist(&map, b"some/other"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1709 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1710 map.set_untracked(p(b"root_file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1711 assert_eq!(map.len(), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1712 assert_eq!(tracked_descendants(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1713 assert_does_not_exist(&map, b"root_file"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1714 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1715 map.set_untracked(p(b"some/file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1716 assert_eq!(map.len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1717 assert_eq!(tracked_descendants(&map, b"some"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1718 assert_does_not_exist(&map, b"some/file"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1719 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1720 map.set_untracked(p(b"some/file2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1721 assert_eq!(map.len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1722 assert_eq!(tracked_descendants(&map, b"some"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1723 assert_does_not_exist(&map, b"some/file2"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1724 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1725 map.set_untracked(p(b"some/file3"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1726 assert_eq!(map.len(), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1727 assert_does_not_exist(&map, b"some/file3"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1728 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1729 Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1730 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1731 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1732 /// Check with a mix of tracked and non-tracked items |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1733 #[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1734 fn test_tracked_descendants_different() -> Result<(), DirstateError> { |
52033
88aa21d654e5
rust-dirstate: actually remember the identity
Raphaël Gomès <rgomes@octobus.net>
parents:
51735
diff
changeset
|
1735 let mut map = OwningDirstateMap::new_empty(vec![], None); |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1736 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1737 // A file that was just added |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1738 map.set_tracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1739 // This has no information, the dirstate should ignore it |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1740 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1741 filename: p(b"some/file"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1742 wc_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1743 p1_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1744 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1745 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1746 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1747 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1748 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1749 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1750 assert_does_not_exist(&map, b"some/file"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1751 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1752 // A file that was removed |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1753 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1754 filename: p(b"some/nested/file"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1755 wc_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1756 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1757 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1758 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1759 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1760 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1761 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1762 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1763 assert!(!map.get(p(b"some/nested/file"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1764 // Only present in p2 |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1765 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1766 filename: p(b"some/file3"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1767 wc_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1768 p1_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1769 p2_info: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1770 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1771 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1772 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1773 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1774 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1775 assert!(!map.get(p(b"some/file3"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1776 // A file that was merged |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1777 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1778 filename: p(b"root_file"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1779 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1780 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1781 p2_info: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1782 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1783 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1784 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1785 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1786 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1787 assert!(map.get(p(b"root_file"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1788 // A file that is added, with info from p2 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1789 // XXX is that actually possible? |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1790 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1791 filename: p(b"some/file2"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1792 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1793 p1_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1794 p2_info: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1795 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1796 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1797 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1798 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1799 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1800 assert!(map.get(p(b"some/file2"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1801 // A clean file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1802 // One layer without any files to test deletion cascade |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1803 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1804 filename: p(b"some/other/nested/path"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1805 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1806 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1807 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1808 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1809 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1810 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1811 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1812 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1813 assert!(map.get(p(b"some/other/nested/path"))?.unwrap().tracked()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1814 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1815 assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1816 assert_eq!(tracked_descendants(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1817 assert_eq!(descendants_with_an_entry(&map, b"some"), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1818 assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1819 assert_eq!(descendants_with_an_entry(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1820 assert_eq!(tracked_descendants(&map, b"some/other/nested/path"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1821 assert_eq!( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1822 descendants_with_an_entry(&map, b"some/other/nested/path"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1823 0 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1824 ); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1825 assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1826 assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1827 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1828 // might as well check this |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1829 map.set_untracked(p(b"path/does/not/exist"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1830 assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1831 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1832 map.set_untracked(p(b"some/other/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1833 // It is set untracked but not deleted since it held other information |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1834 assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1835 assert_eq!(tracked_descendants(&map, b"some"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1836 assert_eq!(descendants_with_an_entry(&map, b"some"), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1837 assert_eq!(descendants_with_an_entry(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1838 assert_eq!(descendants_with_an_entry(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1839 assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1840 assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1841 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1842 map.set_untracked(p(b"some/nested/path"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1843 // It is set untracked *and* deleted since it was only added |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1844 assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1845 assert_eq!(tracked_descendants(&map, b"some"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1846 assert_eq!(descendants_with_an_entry(&map, b"some"), 4); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1847 assert_eq!(tracked_descendants(&map, b"some/nested"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1848 assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1849 assert_does_not_exist(&map, b"some/nested/path"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1850 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1851 map.set_untracked(p(b"root_file"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1852 // Untracked but not deleted |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1853 assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1854 assert!(map.get(p(b"root_file"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1855 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1856 map.set_untracked(p(b"some/file2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1857 assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1858 assert_eq!(tracked_descendants(&map, b"some"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1859 assert!(map.get(p(b"some/file2"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1860 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1861 map.set_untracked(p(b"some/file3"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1862 assert_eq!(map.len(), 5); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1863 assert_eq!(tracked_descendants(&map, b"some"), 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1864 assert!(map.get(p(b"some/file3"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1865 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1866 Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1867 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1868 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1869 /// Check that copies counter is correctly updated |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1870 #[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1871 fn test_copy_source() -> Result<(), DirstateError> { |
52033
88aa21d654e5
rust-dirstate: actually remember the identity
Raphaël Gomès <rgomes@octobus.net>
parents:
51735
diff
changeset
|
1872 let mut map = OwningDirstateMap::new_empty(vec![], None); |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1873 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1874 // Clean file |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1875 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1876 filename: p(b"files/clean"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1877 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1878 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1879 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1880 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1881 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1882 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1883 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1884 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1885 // Merged file |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1886 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1887 filename: p(b"files/from_p2"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1888 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1889 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1890 p2_info: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1891 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1892 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1893 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1894 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1895 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1896 // Removed file |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1897 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1898 filename: p(b"removed"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1899 wc_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1900 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1901 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1902 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1903 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1904 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1905 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1906 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1907 // Added file |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1908 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1909 filename: p(b"files/added"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1910 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1911 p1_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1912 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1913 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1914 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1915 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1916 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1917 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1918 // Add copy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1919 map.copy_map_insert(p(b"files/clean"), p(b"clean_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1920 assert_eq!(map.copy_map_len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1921 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1922 // Copy override |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1923 map.copy_map_insert(p(b"files/clean"), p(b"other_clean_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1924 assert_eq!(map.copy_map_len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1925 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1926 // Multiple copies |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1927 map.copy_map_insert(p(b"removed"), p(b"removed_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1928 assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1929 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1930 map.copy_map_insert(p(b"files/added"), p(b"added_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1931 assert_eq!(map.copy_map_len(), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1932 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1933 // Added, so the entry is completely removed |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1934 map.set_untracked(p(b"files/added"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1935 assert_does_not_exist(&map, b"files/added"); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1936 assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1937 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1938 // Removed, so the entry is kept around, so is its copy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1939 map.set_untracked(p(b"removed"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1940 assert!(map.get(p(b"removed"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1941 assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1942 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1943 // Clean, so the entry is kept around, but not its copy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1944 map.set_untracked(p(b"files/clean"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1945 assert!(map.get(p(b"files/clean"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1946 assert_eq!(map.copy_map_len(), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1947 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1948 map.copy_map_insert(p(b"files/from_p2"), p(b"from_p2_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1949 assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1950 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1951 // Info from p2, so its copy source info is kept around |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1952 map.set_untracked(p(b"files/from_p2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1953 assert!(map.get(p(b"files/from_p2"))?.is_some()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1954 assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1955 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1956 Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1957 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1958 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1959 /// Test with "on disk" data. For the sake of this test, the "on disk" data |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1960 /// does not actually come from the disk, but it's opaque to the code being |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1961 /// tested. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1962 #[test] |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1963 fn test_on_disk() -> Result<(), DirstateError> { |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1964 // First let's create some data to put "on disk" |
52033
88aa21d654e5
rust-dirstate: actually remember the identity
Raphaël Gomès <rgomes@octobus.net>
parents:
51735
diff
changeset
|
1965 let mut map = OwningDirstateMap::new_empty(vec![], None); |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1966 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1967 // A file that was just added |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1968 map.set_tracked(p(b"some/nested/added"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1969 map.copy_map_insert(p(b"some/nested/added"), p(b"added_copy_source"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1970 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1971 // A file that was removed |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1972 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1973 filename: p(b"some/nested/removed"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1974 wc_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1975 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1976 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1977 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1978 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1979 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1980 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1981 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1982 // Only present in p2 |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1983 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1984 filename: p(b"other/p2_info_only"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1985 wc_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1986 p1_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1987 p2_info: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1988 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1989 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1990 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1991 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1992 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1993 map.copy_map_insert( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1994 p(b"other/p2_info_only"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1995 p(b"other/p2_info_copy_source"), |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1996 )?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
1997 // A file that was merged |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1998 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
1999 filename: p(b"merged"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2000 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2001 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2002 p2_info: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2003 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2004 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2005 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2006 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2007 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2008 // A file that is added, with info from p2 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2009 // XXX is that actually possible? |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2010 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2011 filename: p(b"other/added_with_p2"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2012 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2013 p1_tracked: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2014 p2_info: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2015 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2016 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2017 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2018 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2019 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2020 // One layer without any files to test deletion cascade |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2021 // A clean file |
52044
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2022 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2023 filename: p(b"some/other/nested/clean"), |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2024 wc_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2025 p1_tracked: true, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2026 p2_info: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2027 has_meaningful_mtime: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2028 parent_file_data_opt: None, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2029 from_empty: false, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2030 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents:
52033
diff
changeset
|
2031 map.reset_state(reset)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2032 |
49147 | 2033 let (packed, metadata, _should_append, _old_data_size) = |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49373
diff
changeset
|
2034 map.pack_v2(DirstateMapWriteMode::ForceNewDataFile)?; |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2035 let packed_len = packed.len(); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2036 assert!(packed_len > 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2037 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2038 // Recreate "from disk" |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2039 let mut map = OwningDirstateMap::new_v2( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2040 packed, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2041 packed_len, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2042 metadata.as_bytes(), |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
2043 vec![], |
50245
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
50243
diff
changeset
|
2044 None, |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2045 )?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2046 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2047 // Check that everything is accounted for |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2048 assert!(map.contains_key(p(b"some/nested/added"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2049 assert!(map.contains_key(p(b"some/nested/removed"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2050 assert!(map.contains_key(p(b"merged"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2051 assert!(map.contains_key(p(b"other/p2_info_only"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2052 assert!(map.contains_key(p(b"other/added_with_p2"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2053 assert!(map.contains_key(p(b"some/other/nested/clean"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2054 assert_eq!( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2055 map.copy_map_get(p(b"some/nested/added"))?, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2056 Some(p(b"added_copy_source")) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2057 ); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2058 assert_eq!( |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2059 map.copy_map_get(p(b"other/p2_info_only"))?, |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2060 Some(p(b"other/p2_info_copy_source")) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2061 ); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2062 assert_eq!(tracked_descendants(&map, b"some"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2063 assert_eq!(descendants_with_an_entry(&map, b"some"), 3); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2064 assert_eq!(tracked_descendants(&map, b"other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2065 assert_eq!(descendants_with_an_entry(&map, b"other"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2066 assert_eq!(tracked_descendants(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2067 assert_eq!(descendants_with_an_entry(&map, b"some/other"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2068 assert_eq!(tracked_descendants(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2069 assert_eq!(descendants_with_an_entry(&map, b"some/other/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2070 assert_eq!(tracked_descendants(&map, b"some/nested"), 1); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2071 assert_eq!(descendants_with_an_entry(&map, b"some/nested"), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2072 assert_eq!(map.len(), 6); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2073 assert_eq!(map.get_map().unreachable_bytes, 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2074 assert_eq!(map.copy_map_len(), 2); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2075 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2076 // Shouldn't change anything since it's already not tracked |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2077 map.set_untracked(p(b"some/nested/removed"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2078 assert_eq!(map.get_map().unreachable_bytes, 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2079 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2080 if let ChildNodes::InMemory(_) = map.get_map().root { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2081 panic!("root should not have been mutated") |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2082 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2083 // We haven't mutated enough (nothing, actually), we should still be in |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2084 // the append strategy |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2085 assert!(map.get_map().write_should_append()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2086 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2087 // But this mutates the structure, so there should be unreachable_bytes |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2088 assert!(map.set_untracked(p(b"some/nested/added"))?); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2089 let unreachable_bytes = map.get_map().unreachable_bytes; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2090 assert!(unreachable_bytes > 0); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2091 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2092 if let ChildNodes::OnDisk(_) = map.get_map().root { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2093 panic!("root should have been mutated") |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2094 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2095 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2096 // This should not mutate the structure either, since `root` has |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2097 // already been mutated along with its direct children. |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2098 map.set_untracked(p(b"merged"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2099 assert_eq!(map.get_map().unreachable_bytes, unreachable_bytes); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2100 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2101 if let NodeRef::InMemory(_, _) = |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2102 map.get_map().get_node(p(b"other/added_with_p2"))?.unwrap() |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2103 { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2104 panic!("'other/added_with_p2' should not have been mutated") |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2105 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2106 // But this should, since it's in a different path |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2107 // than `<root>some/nested/add` |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2108 map.set_untracked(p(b"other/added_with_p2"))?; |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2109 assert!(map.get_map().unreachable_bytes > unreachable_bytes); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2110 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2111 if let NodeRef::OnDisk(_) = |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2112 map.get_map().get_node(p(b"other/added_with_p2"))?.unwrap() |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2113 { |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49924
diff
changeset
|
2114 panic!("'other/added_with_p2' should have been mutated") |
49126
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2115 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2116 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2117 // We have rewritten most of the tree, we should create a new file |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2118 assert!(!map.get_map().write_should_append()); |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2119 |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2120 Ok(()) |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2121 } |
e7b74bb602a4
rust-dirstatemap: add unit tests
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
2122 } |