Show More
@@ -1,573 +1,558 b'' | |||||
1 | use std::path::PathBuf; |
|
1 | use std::path::PathBuf; | |
2 |
|
2 | |||
3 | use crate::dirstate::parsers::Timestamp; |
|
3 | use crate::dirstate::parsers::Timestamp; | |
4 | use crate::dirstate_tree::on_disk::DirstateV2ParseError; |
|
4 | use crate::dirstate_tree::on_disk::DirstateV2ParseError; | |
5 | use crate::matchers::Matcher; |
|
5 | use crate::matchers::Matcher; | |
6 | use crate::utils::hg_path::{HgPath, HgPathBuf}; |
|
6 | use crate::utils::hg_path::{HgPath, HgPathBuf}; | |
7 | use crate::CopyMapIter; |
|
7 | use crate::CopyMapIter; | |
8 | use crate::DirstateEntry; |
|
8 | use crate::DirstateEntry; | |
9 | use crate::DirstateError; |
|
9 | use crate::DirstateError; | |
10 | use crate::DirstateMap; |
|
10 | use crate::DirstateMap; | |
11 | use crate::DirstateParents; |
|
11 | use crate::DirstateParents; | |
12 | use crate::DirstateStatus; |
|
12 | use crate::DirstateStatus; | |
13 | use crate::PatternFileWarning; |
|
13 | use crate::PatternFileWarning; | |
14 | use crate::StateMapIter; |
|
14 | use crate::StateMapIter; | |
15 | use crate::StatusError; |
|
15 | use crate::StatusError; | |
16 | use crate::StatusOptions; |
|
16 | use crate::StatusOptions; | |
17 |
|
17 | |||
18 | /// `rust/hg-cpython/src/dirstate/dirstate_map.rs` implements in Rust a |
|
18 | /// `rust/hg-cpython/src/dirstate/dirstate_map.rs` implements in Rust a | |
19 | /// `DirstateMap` Python class that wraps `Box<dyn DirstateMapMethods + Send>`, |
|
19 | /// `DirstateMap` Python class that wraps `Box<dyn DirstateMapMethods + Send>`, | |
20 | /// a trait object of this trait. Except for constructors, this trait defines |
|
20 | /// a trait object of this trait. Except for constructors, this trait defines | |
21 | /// all APIs that the class needs to interact with its inner dirstate map. |
|
21 | /// all APIs that the class needs to interact with its inner dirstate map. | |
22 | /// |
|
22 | /// | |
23 | /// A trait object is used to support two different concrete types: |
|
23 | /// A trait object is used to support two different concrete types: | |
24 | /// |
|
24 | /// | |
25 | /// * `rust/hg-core/src/dirstate/dirstate_map.rs` defines the "flat dirstate |
|
25 | /// * `rust/hg-core/src/dirstate/dirstate_map.rs` defines the "flat dirstate | |
26 | /// map" which is based on a few large `HgPath`-keyed `HashMap` and `HashSet` |
|
26 | /// map" which is based on a few large `HgPath`-keyed `HashMap` and `HashSet` | |
27 | /// fields. |
|
27 | /// fields. | |
28 | /// * `rust/hg-core/src/dirstate_tree/dirstate_map.rs` defines the "tree |
|
28 | /// * `rust/hg-core/src/dirstate_tree/dirstate_map.rs` defines the "tree | |
29 | /// dirstate map" based on a tree data struture with nodes for directories |
|
29 | /// dirstate map" based on a tree data struture with nodes for directories | |
30 | /// containing child nodes for their files and sub-directories. This tree |
|
30 | /// containing child nodes for their files and sub-directories. This tree | |
31 | /// enables a more efficient algorithm for `hg status`, but its details are |
|
31 | /// enables a more efficient algorithm for `hg status`, but its details are | |
32 | /// abstracted in this trait. |
|
32 | /// abstracted in this trait. | |
33 | /// |
|
33 | /// | |
34 | /// The dirstate map associates paths of files in the working directory to |
|
34 | /// The dirstate map associates paths of files in the working directory to | |
35 | /// various information about the state of those files. |
|
35 | /// various information about the state of those files. | |
36 | pub trait DirstateMapMethods { |
|
36 | pub trait DirstateMapMethods { | |
37 | /// Remove information about all files in this map |
|
37 | /// Remove information about all files in this map | |
38 | fn clear(&mut self); |
|
38 | fn clear(&mut self); | |
39 |
|
39 | |||
40 | /// Add the given filename to the map if it is not already there, and |
|
40 | /// Add the given filename to the map if it is not already there, and | |
41 | /// associate the given entry with it. |
|
41 | /// associate the given entry with it. | |
42 | fn set_entry( |
|
42 | fn set_entry( | |
43 | &mut self, |
|
43 | &mut self, | |
44 | filename: &HgPath, |
|
44 | filename: &HgPath, | |
45 | entry: DirstateEntry, |
|
45 | entry: DirstateEntry, | |
46 | ) -> Result<(), DirstateV2ParseError>; |
|
46 | ) -> Result<(), DirstateV2ParseError>; | |
47 |
|
47 | |||
48 | /// Add or change the information associated to a given file. |
|
48 | /// Add or change the information associated to a given file. | |
49 | /// |
|
|||
50 | /// `old_state` is the state in the entry that `get` would have returned |
|
|||
51 | /// before this call, or `EntryState::Unknown` if there was no such entry. |
|
|||
52 | /// |
|
|||
53 | /// `entry.state` should never be `EntryState::Unknown`. |
|
|||
54 | fn add_file( |
|
49 | fn add_file( | |
55 | &mut self, |
|
50 | &mut self, | |
56 | filename: &HgPath, |
|
51 | filename: &HgPath, | |
57 | entry: DirstateEntry, |
|
52 | entry: DirstateEntry, | |
58 | added: bool, |
|
53 | added: bool, | |
59 | merged: bool, |
|
54 | merged: bool, | |
60 | from_p2: bool, |
|
55 | from_p2: bool, | |
61 | possibly_dirty: bool, |
|
56 | possibly_dirty: bool, | |
62 | ) -> Result<(), DirstateError>; |
|
57 | ) -> Result<(), DirstateError>; | |
63 |
|
58 | |||
64 | /// Mark a file as "removed" (as in `hg rm`). |
|
59 | /// Mark a file as "removed" (as in `hg rm`). | |
65 | /// |
|
|||
66 | /// `old_state` is the state in the entry that `get` would have returned |
|
|||
67 | /// before this call, or `EntryState::Unknown` if there was no such entry. |
|
|||
68 | /// |
|
|||
69 | /// `size` is not actually a size but the 0 or -1 or -2 value that would be |
|
|||
70 | /// put in the size field in the dirstate-v1Β format. |
|
|||
71 | fn remove_file( |
|
60 | fn remove_file( | |
72 | &mut self, |
|
61 | &mut self, | |
73 | filename: &HgPath, |
|
62 | filename: &HgPath, | |
74 | in_merge: bool, |
|
63 | in_merge: bool, | |
75 | ) -> Result<(), DirstateError>; |
|
64 | ) -> Result<(), DirstateError>; | |
76 |
|
65 | |||
77 |
/// Drop information about this file from the map if any |
|
66 | /// Drop information about this file from the map if any. | |
78 | /// whether there was any. |
|
|||
79 | /// |
|
67 | /// | |
80 | /// `get` will now return `None` for this filename. |
|
68 | /// `get` will now return `None` for this filename. | |
81 | /// |
|
|||
82 | /// `old_state` is the state in the entry that `get` would have returned |
|
|||
83 | /// before this call, or `EntryState::Unknown` if there was no such entry. |
|
|||
84 | fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError>; |
|
69 | fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError>; | |
85 |
|
70 | |||
86 | /// Among given files, mark the stored `mtime` as ambiguous if there is one |
|
71 | /// Among given files, mark the stored `mtime` as ambiguous if there is one | |
87 | /// (if `state == EntryState::Normal`) equal to the given current Unix |
|
72 | /// (if `state == EntryState::Normal`) equal to the given current Unix | |
88 | /// timestamp. |
|
73 | /// timestamp. | |
89 | fn clear_ambiguous_times( |
|
74 | fn clear_ambiguous_times( | |
90 | &mut self, |
|
75 | &mut self, | |
91 | filenames: Vec<HgPathBuf>, |
|
76 | filenames: Vec<HgPathBuf>, | |
92 | now: i32, |
|
77 | now: i32, | |
93 | ) -> Result<(), DirstateV2ParseError>; |
|
78 | ) -> Result<(), DirstateV2ParseError>; | |
94 |
|
79 | |||
95 | /// Return whether the map has an "non-normal" entry for the given |
|
80 | /// Return whether the map has an "non-normal" entry for the given | |
96 | /// filename. That is, any entry with a `state` other than |
|
81 | /// filename. That is, any entry with a `state` other than | |
97 | /// `EntryState::Normal` or with an ambiguous `mtime`. |
|
82 | /// `EntryState::Normal` or with an ambiguous `mtime`. | |
98 | fn non_normal_entries_contains( |
|
83 | fn non_normal_entries_contains( | |
99 | &mut self, |
|
84 | &mut self, | |
100 | key: &HgPath, |
|
85 | key: &HgPath, | |
101 | ) -> Result<bool, DirstateV2ParseError>; |
|
86 | ) -> Result<bool, DirstateV2ParseError>; | |
102 |
|
87 | |||
103 | /// Mark the given path as "normal" file. This is only relevant in the flat |
|
88 | /// Mark the given path as "normal" file. This is only relevant in the flat | |
104 | /// dirstate map where there is a separate `HashSet` that needs to be kept |
|
89 | /// dirstate map where there is a separate `HashSet` that needs to be kept | |
105 | /// up to date. |
|
90 | /// up to date. | |
106 | /// Returns whether the key was present in the set. |
|
91 | /// Returns whether the key was present in the set. | |
107 | fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool; |
|
92 | fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool; | |
108 |
|
93 | |||
109 | /// Mark the given path as "non-normal" file. |
|
94 | /// Mark the given path as "non-normal" file. | |
110 | /// This is only relevant in the flat dirstate map where there is a |
|
95 | /// This is only relevant in the flat dirstate map where there is a | |
111 | /// separate `HashSet` that needs to be kept up to date. |
|
96 | /// separate `HashSet` that needs to be kept up to date. | |
112 | fn non_normal_entries_add(&mut self, key: &HgPath); |
|
97 | fn non_normal_entries_add(&mut self, key: &HgPath); | |
113 |
|
98 | |||
114 | /// Return an iterator of paths whose respective entry are either |
|
99 | /// Return an iterator of paths whose respective entry are either | |
115 | /// "non-normal" (see `non_normal_entries_contains`) or "from other |
|
100 | /// "non-normal" (see `non_normal_entries_contains`) or "from other | |
116 | /// parent". |
|
101 | /// parent". | |
117 | /// |
|
102 | /// | |
118 | /// If that information is cached, create the cache as needed. |
|
103 | /// If that information is cached, create the cache as needed. | |
119 | /// |
|
104 | /// | |
120 | /// "From other parent" is defined as `state == Normal && size == -2`. |
|
105 | /// "From other parent" is defined as `state == Normal && size == -2`. | |
121 | /// |
|
106 | /// | |
122 | /// Because parse errors can happen during iteration, the iterated items |
|
107 | /// Because parse errors can happen during iteration, the iterated items | |
123 | /// are `Result`s. |
|
108 | /// are `Result`s. | |
124 | fn non_normal_or_other_parent_paths( |
|
109 | fn non_normal_or_other_parent_paths( | |
125 | &mut self, |
|
110 | &mut self, | |
126 | ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_>; |
|
111 | ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_>; | |
127 |
|
112 | |||
128 | /// Create the cache for `non_normal_or_other_parent_paths` if needed. |
|
113 | /// Create the cache for `non_normal_or_other_parent_paths` if needed. | |
129 | /// |
|
114 | /// | |
130 | /// If `force` is true, the cache is re-created even if it already exists. |
|
115 | /// If `force` is true, the cache is re-created even if it already exists. | |
131 | fn set_non_normal_other_parent_entries(&mut self, force: bool); |
|
116 | fn set_non_normal_other_parent_entries(&mut self, force: bool); | |
132 |
|
117 | |||
133 | /// Return an iterator of paths whose respective entry are "non-normal" |
|
118 | /// Return an iterator of paths whose respective entry are "non-normal" | |
134 | /// (see `non_normal_entries_contains`). |
|
119 | /// (see `non_normal_entries_contains`). | |
135 | /// |
|
120 | /// | |
136 | /// If that information is cached, create the cache as needed. |
|
121 | /// If that information is cached, create the cache as needed. | |
137 | /// |
|
122 | /// | |
138 | /// Because parse errors can happen during iteration, the iterated items |
|
123 | /// Because parse errors can happen during iteration, the iterated items | |
139 | /// are `Result`s. |
|
124 | /// are `Result`s. | |
140 | fn iter_non_normal_paths( |
|
125 | fn iter_non_normal_paths( | |
141 | &mut self, |
|
126 | &mut self, | |
142 | ) -> Box< |
|
127 | ) -> Box< | |
143 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
128 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, | |
144 | >; |
|
129 | >; | |
145 |
|
130 | |||
146 | /// Same as `iter_non_normal_paths`, but takes `&self` instead of `&mut |
|
131 | /// Same as `iter_non_normal_paths`, but takes `&self` instead of `&mut | |
147 | /// self`. |
|
132 | /// self`. | |
148 | /// |
|
133 | /// | |
149 | /// Panics if a cache is necessary but does not exist yet. |
|
134 | /// Panics if a cache is necessary but does not exist yet. | |
150 | fn iter_non_normal_paths_panic( |
|
135 | fn iter_non_normal_paths_panic( | |
151 | &self, |
|
136 | &self, | |
152 | ) -> Box< |
|
137 | ) -> Box< | |
153 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
138 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, | |
154 | >; |
|
139 | >; | |
155 |
|
140 | |||
156 | /// Return an iterator of paths whose respective entry are "from other |
|
141 | /// Return an iterator of paths whose respective entry are "from other | |
157 | /// parent". |
|
142 | /// parent". | |
158 | /// |
|
143 | /// | |
159 | /// If that information is cached, create the cache as needed. |
|
144 | /// If that information is cached, create the cache as needed. | |
160 | /// |
|
145 | /// | |
161 | /// "From other parent" is defined as `state == Normal && size == -2`. |
|
146 | /// "From other parent" is defined as `state == Normal && size == -2`. | |
162 | /// |
|
147 | /// | |
163 | /// Because parse errors can happen during iteration, the iterated items |
|
148 | /// Because parse errors can happen during iteration, the iterated items | |
164 | /// are `Result`s. |
|
149 | /// are `Result`s. | |
165 | fn iter_other_parent_paths( |
|
150 | fn iter_other_parent_paths( | |
166 | &mut self, |
|
151 | &mut self, | |
167 | ) -> Box< |
|
152 | ) -> Box< | |
168 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
153 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, | |
169 | >; |
|
154 | >; | |
170 |
|
155 | |||
171 | /// Returns whether the sub-tree rooted at the given directory contains any |
|
156 | /// Returns whether the sub-tree rooted at the given directory contains any | |
172 | /// tracked file. |
|
157 | /// tracked file. | |
173 | /// |
|
158 | /// | |
174 | /// A file is tracked if it has a `state` other than `EntryState::Removed`. |
|
159 | /// A file is tracked if it has a `state` other than `EntryState::Removed`. | |
175 | fn has_tracked_dir( |
|
160 | fn has_tracked_dir( | |
176 | &mut self, |
|
161 | &mut self, | |
177 | directory: &HgPath, |
|
162 | directory: &HgPath, | |
178 | ) -> Result<bool, DirstateError>; |
|
163 | ) -> Result<bool, DirstateError>; | |
179 |
|
164 | |||
180 | /// Returns whether the sub-tree rooted at the given directory contains any |
|
165 | /// Returns whether the sub-tree rooted at the given directory contains any | |
181 | /// file with a dirstate entry. |
|
166 | /// file with a dirstate entry. | |
182 | fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateError>; |
|
167 | fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateError>; | |
183 |
|
168 | |||
184 | /// Clear mtimes that are ambigous with `now` (similar to |
|
169 | /// Clear mtimes that are ambigous with `now` (similar to | |
185 | /// `clear_ambiguous_times` but for all files in the dirstate map), and |
|
170 | /// `clear_ambiguous_times` but for all files in the dirstate map), and | |
186 | /// serialize bytes to write the `.hg/dirstate` file to disk in dirstate-v1 |
|
171 | /// serialize bytes to write the `.hg/dirstate` file to disk in dirstate-v1 | |
187 | /// format. |
|
172 | /// format. | |
188 | fn pack_v1( |
|
173 | fn pack_v1( | |
189 | &mut self, |
|
174 | &mut self, | |
190 | parents: DirstateParents, |
|
175 | parents: DirstateParents, | |
191 | now: Timestamp, |
|
176 | now: Timestamp, | |
192 | ) -> Result<Vec<u8>, DirstateError>; |
|
177 | ) -> Result<Vec<u8>, DirstateError>; | |
193 |
|
178 | |||
194 | /// Clear mtimes that are ambigous with `now` (similar to |
|
179 | /// Clear mtimes that are ambigous with `now` (similar to | |
195 | /// `clear_ambiguous_times` but for all files in the dirstate map), and |
|
180 | /// `clear_ambiguous_times` but for all files in the dirstate map), and | |
196 | /// serialize bytes to write a dirstate data file to disk in dirstate-v2 |
|
181 | /// serialize bytes to write a dirstate data file to disk in dirstate-v2 | |
197 | /// format. |
|
182 | /// format. | |
198 | /// |
|
183 | /// | |
199 | /// Returns new data and metadata together with whether that data should be |
|
184 | /// Returns new data and metadata together with whether that data should be | |
200 | /// appended to the existing data file whose content is at |
|
185 | /// appended to the existing data file whose content is at | |
201 | /// `self.on_disk` (true), instead of written to a new data file |
|
186 | /// `self.on_disk` (true), instead of written to a new data file | |
202 | /// (false). |
|
187 | /// (false). | |
203 | /// |
|
188 | /// | |
204 | /// Note: this is only supported by the tree dirstate map. |
|
189 | /// Note: this is only supported by the tree dirstate map. | |
205 | fn pack_v2( |
|
190 | fn pack_v2( | |
206 | &mut self, |
|
191 | &mut self, | |
207 | now: Timestamp, |
|
192 | now: Timestamp, | |
208 | can_append: bool, |
|
193 | can_append: bool, | |
209 | ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError>; |
|
194 | ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError>; | |
210 |
|
195 | |||
211 | /// Run the status algorithm. |
|
196 | /// Run the status algorithm. | |
212 | /// |
|
197 | /// | |
213 | /// This is not sematically a method of the dirstate map, but a different |
|
198 | /// This is not sematically a method of the dirstate map, but a different | |
214 | /// algorithm is used for the flat v.s. tree dirstate map so having it in |
|
199 | /// algorithm is used for the flat v.s. tree dirstate map so having it in | |
215 | /// this trait enables the same dynamic dispatch as with other methods. |
|
200 | /// this trait enables the same dynamic dispatch as with other methods. | |
216 | fn status<'a>( |
|
201 | fn status<'a>( | |
217 | &'a mut self, |
|
202 | &'a mut self, | |
218 | matcher: &'a (dyn Matcher + Sync), |
|
203 | matcher: &'a (dyn Matcher + Sync), | |
219 | root_dir: PathBuf, |
|
204 | root_dir: PathBuf, | |
220 | ignore_files: Vec<PathBuf>, |
|
205 | ignore_files: Vec<PathBuf>, | |
221 | options: StatusOptions, |
|
206 | options: StatusOptions, | |
222 | ) -> Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError>; |
|
207 | ) -> Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError>; | |
223 |
|
208 | |||
224 | /// Returns how many files in the dirstate map have a recorded copy source. |
|
209 | /// Returns how many files in the dirstate map have a recorded copy source. | |
225 | fn copy_map_len(&self) -> usize; |
|
210 | fn copy_map_len(&self) -> usize; | |
226 |
|
211 | |||
227 | /// Returns an iterator of `(path, copy_source)` for all files that have a |
|
212 | /// Returns an iterator of `(path, copy_source)` for all files that have a | |
228 | /// copy source. |
|
213 | /// copy source. | |
229 | fn copy_map_iter(&self) -> CopyMapIter<'_>; |
|
214 | fn copy_map_iter(&self) -> CopyMapIter<'_>; | |
230 |
|
215 | |||
231 | /// Returns whether the givef file has a copy source. |
|
216 | /// Returns whether the givef file has a copy source. | |
232 | fn copy_map_contains_key( |
|
217 | fn copy_map_contains_key( | |
233 | &self, |
|
218 | &self, | |
234 | key: &HgPath, |
|
219 | key: &HgPath, | |
235 | ) -> Result<bool, DirstateV2ParseError>; |
|
220 | ) -> Result<bool, DirstateV2ParseError>; | |
236 |
|
221 | |||
237 | /// Returns the copy source for the given file. |
|
222 | /// Returns the copy source for the given file. | |
238 | fn copy_map_get( |
|
223 | fn copy_map_get( | |
239 | &self, |
|
224 | &self, | |
240 | key: &HgPath, |
|
225 | key: &HgPath, | |
241 | ) -> Result<Option<&HgPath>, DirstateV2ParseError>; |
|
226 | ) -> Result<Option<&HgPath>, DirstateV2ParseError>; | |
242 |
|
227 | |||
243 | /// Removes the recorded copy source if any for the given file, and returns |
|
228 | /// Removes the recorded copy source if any for the given file, and returns | |
244 | /// it. |
|
229 | /// it. | |
245 | fn copy_map_remove( |
|
230 | fn copy_map_remove( | |
246 | &mut self, |
|
231 | &mut self, | |
247 | key: &HgPath, |
|
232 | key: &HgPath, | |
248 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError>; |
|
233 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError>; | |
249 |
|
234 | |||
250 | /// Set the given `value` copy source for the given `key` file. |
|
235 | /// Set the given `value` copy source for the given `key` file. | |
251 | fn copy_map_insert( |
|
236 | fn copy_map_insert( | |
252 | &mut self, |
|
237 | &mut self, | |
253 | key: HgPathBuf, |
|
238 | key: HgPathBuf, | |
254 | value: HgPathBuf, |
|
239 | value: HgPathBuf, | |
255 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError>; |
|
240 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError>; | |
256 |
|
241 | |||
257 | /// Returns the number of files that have an entry. |
|
242 | /// Returns the number of files that have an entry. | |
258 | fn len(&self) -> usize; |
|
243 | fn len(&self) -> usize; | |
259 |
|
244 | |||
260 | /// Returns whether the given file has an entry. |
|
245 | /// Returns whether the given file has an entry. | |
261 | fn contains_key(&self, key: &HgPath) |
|
246 | fn contains_key(&self, key: &HgPath) | |
262 | -> Result<bool, DirstateV2ParseError>; |
|
247 | -> Result<bool, DirstateV2ParseError>; | |
263 |
|
248 | |||
264 | /// Returns the entry, if any, for the given file. |
|
249 | /// Returns the entry, if any, for the given file. | |
265 | fn get( |
|
250 | fn get( | |
266 | &self, |
|
251 | &self, | |
267 | key: &HgPath, |
|
252 | key: &HgPath, | |
268 | ) -> Result<Option<DirstateEntry>, DirstateV2ParseError>; |
|
253 | ) -> Result<Option<DirstateEntry>, DirstateV2ParseError>; | |
269 |
|
254 | |||
270 | /// Returns a `(path, entry)` iterator of files that have an entry. |
|
255 | /// Returns a `(path, entry)` iterator of files that have an entry. | |
271 | /// |
|
256 | /// | |
272 | /// Because parse errors can happen during iteration, the iterated items |
|
257 | /// Because parse errors can happen during iteration, the iterated items | |
273 | /// are `Result`s. |
|
258 | /// are `Result`s. | |
274 | fn iter(&self) -> StateMapIter<'_>; |
|
259 | fn iter(&self) -> StateMapIter<'_>; | |
275 |
|
260 | |||
276 | /// Returns an iterator of tracked directories. |
|
261 | /// Returns an iterator of tracked directories. | |
277 | /// |
|
262 | /// | |
278 | /// This is the paths for which `has_tracked_dir` would return true. |
|
263 | /// This is the paths for which `has_tracked_dir` would return true. | |
279 | /// Or, in other words, the union of ancestor paths of all paths that have |
|
264 | /// Or, in other words, the union of ancestor paths of all paths that have | |
280 | /// an associated entry in a "tracked" state in this dirstate map. |
|
265 | /// an associated entry in a "tracked" state in this dirstate map. | |
281 | /// |
|
266 | /// | |
282 | /// Because parse errors can happen during iteration, the iterated items |
|
267 | /// Because parse errors can happen during iteration, the iterated items | |
283 | /// are `Result`s. |
|
268 | /// are `Result`s. | |
284 | fn iter_tracked_dirs( |
|
269 | fn iter_tracked_dirs( | |
285 | &mut self, |
|
270 | &mut self, | |
286 | ) -> Result< |
|
271 | ) -> Result< | |
287 | Box< |
|
272 | Box< | |
288 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> |
|
273 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> | |
289 | + Send |
|
274 | + Send | |
290 | + '_, |
|
275 | + '_, | |
291 | >, |
|
276 | >, | |
292 | DirstateError, |
|
277 | DirstateError, | |
293 | >; |
|
278 | >; | |
294 |
|
279 | |||
295 | /// Return an iterator of `(path, (state, mode, size, mtime))` for every |
|
280 | /// Return an iterator of `(path, (state, mode, size, mtime))` for every | |
296 | /// node stored in this dirstate map, for the purpose of the `hg |
|
281 | /// node stored in this dirstate map, for the purpose of the `hg | |
297 | /// debugdirstate` command. |
|
282 | /// debugdirstate` command. | |
298 | /// |
|
283 | /// | |
299 | /// If `all` is true, include nodes that donβt have an entry. |
|
284 | /// If `all` is true, include nodes that donβt have an entry. | |
300 | /// For such nodes `state` is the ASCII space. |
|
285 | /// For such nodes `state` is the ASCII space. | |
301 | /// An `mtime` may still be present. It is used to optimize `status`. |
|
286 | /// An `mtime` may still be present. It is used to optimize `status`. | |
302 | /// |
|
287 | /// | |
303 | /// Because parse errors can happen during iteration, the iterated items |
|
288 | /// Because parse errors can happen during iteration, the iterated items | |
304 | /// are `Result`s. |
|
289 | /// are `Result`s. | |
305 | fn debug_iter( |
|
290 | fn debug_iter( | |
306 | &self, |
|
291 | &self, | |
307 | all: bool, |
|
292 | all: bool, | |
308 | ) -> Box< |
|
293 | ) -> Box< | |
309 | dyn Iterator< |
|
294 | dyn Iterator< | |
310 | Item = Result< |
|
295 | Item = Result< | |
311 | (&HgPath, (u8, i32, i32, i32)), |
|
296 | (&HgPath, (u8, i32, i32, i32)), | |
312 | DirstateV2ParseError, |
|
297 | DirstateV2ParseError, | |
313 | >, |
|
298 | >, | |
314 | > + Send |
|
299 | > + Send | |
315 | + '_, |
|
300 | + '_, | |
316 | >; |
|
301 | >; | |
317 | } |
|
302 | } | |
318 |
|
303 | |||
319 | impl DirstateMapMethods for DirstateMap { |
|
304 | impl DirstateMapMethods for DirstateMap { | |
320 | fn clear(&mut self) { |
|
305 | fn clear(&mut self) { | |
321 | self.clear() |
|
306 | self.clear() | |
322 | } |
|
307 | } | |
323 |
|
308 | |||
324 | /// Used to set a value directory. |
|
309 | /// Used to set a value directory. | |
325 | /// |
|
310 | /// | |
326 | /// XXX Is temporary during a refactor of V1 dirstate and will disappear |
|
311 | /// XXX Is temporary during a refactor of V1 dirstate and will disappear | |
327 | /// shortly. |
|
312 | /// shortly. | |
328 | fn set_entry( |
|
313 | fn set_entry( | |
329 | &mut self, |
|
314 | &mut self, | |
330 | filename: &HgPath, |
|
315 | filename: &HgPath, | |
331 | entry: DirstateEntry, |
|
316 | entry: DirstateEntry, | |
332 | ) -> Result<(), DirstateV2ParseError> { |
|
317 | ) -> Result<(), DirstateV2ParseError> { | |
333 | self.set_entry(&filename, entry); |
|
318 | self.set_entry(&filename, entry); | |
334 | Ok(()) |
|
319 | Ok(()) | |
335 | } |
|
320 | } | |
336 |
|
321 | |||
337 | fn add_file( |
|
322 | fn add_file( | |
338 | &mut self, |
|
323 | &mut self, | |
339 | filename: &HgPath, |
|
324 | filename: &HgPath, | |
340 | entry: DirstateEntry, |
|
325 | entry: DirstateEntry, | |
341 | added: bool, |
|
326 | added: bool, | |
342 | merged: bool, |
|
327 | merged: bool, | |
343 | from_p2: bool, |
|
328 | from_p2: bool, | |
344 | possibly_dirty: bool, |
|
329 | possibly_dirty: bool, | |
345 | ) -> Result<(), DirstateError> { |
|
330 | ) -> Result<(), DirstateError> { | |
346 | self.add_file(filename, entry, added, merged, from_p2, possibly_dirty) |
|
331 | self.add_file(filename, entry, added, merged, from_p2, possibly_dirty) | |
347 | } |
|
332 | } | |
348 |
|
333 | |||
349 | fn remove_file( |
|
334 | fn remove_file( | |
350 | &mut self, |
|
335 | &mut self, | |
351 | filename: &HgPath, |
|
336 | filename: &HgPath, | |
352 | in_merge: bool, |
|
337 | in_merge: bool, | |
353 | ) -> Result<(), DirstateError> { |
|
338 | ) -> Result<(), DirstateError> { | |
354 | self.remove_file(filename, in_merge) |
|
339 | self.remove_file(filename, in_merge) | |
355 | } |
|
340 | } | |
356 |
|
341 | |||
357 | fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError> { |
|
342 | fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError> { | |
358 | self.drop_file(filename) |
|
343 | self.drop_file(filename) | |
359 | } |
|
344 | } | |
360 |
|
345 | |||
361 | fn clear_ambiguous_times( |
|
346 | fn clear_ambiguous_times( | |
362 | &mut self, |
|
347 | &mut self, | |
363 | filenames: Vec<HgPathBuf>, |
|
348 | filenames: Vec<HgPathBuf>, | |
364 | now: i32, |
|
349 | now: i32, | |
365 | ) -> Result<(), DirstateV2ParseError> { |
|
350 | ) -> Result<(), DirstateV2ParseError> { | |
366 | Ok(self.clear_ambiguous_times(filenames, now)) |
|
351 | Ok(self.clear_ambiguous_times(filenames, now)) | |
367 | } |
|
352 | } | |
368 |
|
353 | |||
369 | fn non_normal_entries_contains( |
|
354 | fn non_normal_entries_contains( | |
370 | &mut self, |
|
355 | &mut self, | |
371 | key: &HgPath, |
|
356 | key: &HgPath, | |
372 | ) -> Result<bool, DirstateV2ParseError> { |
|
357 | ) -> Result<bool, DirstateV2ParseError> { | |
373 | let (non_normal, _other_parent) = |
|
358 | let (non_normal, _other_parent) = | |
374 | self.get_non_normal_other_parent_entries(); |
|
359 | self.get_non_normal_other_parent_entries(); | |
375 | Ok(non_normal.contains(key)) |
|
360 | Ok(non_normal.contains(key)) | |
376 | } |
|
361 | } | |
377 |
|
362 | |||
378 | fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool { |
|
363 | fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool { | |
379 | self.non_normal_entries_remove(key) |
|
364 | self.non_normal_entries_remove(key) | |
380 | } |
|
365 | } | |
381 |
|
366 | |||
382 | fn non_normal_entries_add(&mut self, key: &HgPath) { |
|
367 | fn non_normal_entries_add(&mut self, key: &HgPath) { | |
383 | self.non_normal_entries_add(key) |
|
368 | self.non_normal_entries_add(key) | |
384 | } |
|
369 | } | |
385 |
|
370 | |||
386 | fn non_normal_or_other_parent_paths( |
|
371 | fn non_normal_or_other_parent_paths( | |
387 | &mut self, |
|
372 | &mut self, | |
388 | ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_> |
|
373 | ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_> | |
389 | { |
|
374 | { | |
390 | let (non_normal, other_parent) = |
|
375 | let (non_normal, other_parent) = | |
391 | self.get_non_normal_other_parent_entries(); |
|
376 | self.get_non_normal_other_parent_entries(); | |
392 | Box::new(non_normal.union(other_parent).map(|p| Ok(&**p))) |
|
377 | Box::new(non_normal.union(other_parent).map(|p| Ok(&**p))) | |
393 | } |
|
378 | } | |
394 |
|
379 | |||
395 | fn set_non_normal_other_parent_entries(&mut self, force: bool) { |
|
380 | fn set_non_normal_other_parent_entries(&mut self, force: bool) { | |
396 | self.set_non_normal_other_parent_entries(force) |
|
381 | self.set_non_normal_other_parent_entries(force) | |
397 | } |
|
382 | } | |
398 |
|
383 | |||
399 | fn iter_non_normal_paths( |
|
384 | fn iter_non_normal_paths( | |
400 | &mut self, |
|
385 | &mut self, | |
401 | ) -> Box< |
|
386 | ) -> Box< | |
402 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
387 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, | |
403 | > { |
|
388 | > { | |
404 | let (non_normal, _other_parent) = |
|
389 | let (non_normal, _other_parent) = | |
405 | self.get_non_normal_other_parent_entries(); |
|
390 | self.get_non_normal_other_parent_entries(); | |
406 | Box::new(non_normal.iter().map(|p| Ok(&**p))) |
|
391 | Box::new(non_normal.iter().map(|p| Ok(&**p))) | |
407 | } |
|
392 | } | |
408 |
|
393 | |||
409 | fn iter_non_normal_paths_panic( |
|
394 | fn iter_non_normal_paths_panic( | |
410 | &self, |
|
395 | &self, | |
411 | ) -> Box< |
|
396 | ) -> Box< | |
412 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
397 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, | |
413 | > { |
|
398 | > { | |
414 | let (non_normal, _other_parent) = |
|
399 | let (non_normal, _other_parent) = | |
415 | self.get_non_normal_other_parent_entries_panic(); |
|
400 | self.get_non_normal_other_parent_entries_panic(); | |
416 | Box::new(non_normal.iter().map(|p| Ok(&**p))) |
|
401 | Box::new(non_normal.iter().map(|p| Ok(&**p))) | |
417 | } |
|
402 | } | |
418 |
|
403 | |||
419 | fn iter_other_parent_paths( |
|
404 | fn iter_other_parent_paths( | |
420 | &mut self, |
|
405 | &mut self, | |
421 | ) -> Box< |
|
406 | ) -> Box< | |
422 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
407 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, | |
423 | > { |
|
408 | > { | |
424 | let (_non_normal, other_parent) = |
|
409 | let (_non_normal, other_parent) = | |
425 | self.get_non_normal_other_parent_entries(); |
|
410 | self.get_non_normal_other_parent_entries(); | |
426 | Box::new(other_parent.iter().map(|p| Ok(&**p))) |
|
411 | Box::new(other_parent.iter().map(|p| Ok(&**p))) | |
427 | } |
|
412 | } | |
428 |
|
413 | |||
429 | fn has_tracked_dir( |
|
414 | fn has_tracked_dir( | |
430 | &mut self, |
|
415 | &mut self, | |
431 | directory: &HgPath, |
|
416 | directory: &HgPath, | |
432 | ) -> Result<bool, DirstateError> { |
|
417 | ) -> Result<bool, DirstateError> { | |
433 | self.has_tracked_dir(directory) |
|
418 | self.has_tracked_dir(directory) | |
434 | } |
|
419 | } | |
435 |
|
420 | |||
436 | fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateError> { |
|
421 | fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateError> { | |
437 | self.has_dir(directory) |
|
422 | self.has_dir(directory) | |
438 | } |
|
423 | } | |
439 |
|
424 | |||
440 | fn pack_v1( |
|
425 | fn pack_v1( | |
441 | &mut self, |
|
426 | &mut self, | |
442 | parents: DirstateParents, |
|
427 | parents: DirstateParents, | |
443 | now: Timestamp, |
|
428 | now: Timestamp, | |
444 | ) -> Result<Vec<u8>, DirstateError> { |
|
429 | ) -> Result<Vec<u8>, DirstateError> { | |
445 | self.pack(parents, now) |
|
430 | self.pack(parents, now) | |
446 | } |
|
431 | } | |
447 |
|
432 | |||
448 | fn pack_v2( |
|
433 | fn pack_v2( | |
449 | &mut self, |
|
434 | &mut self, | |
450 | _now: Timestamp, |
|
435 | _now: Timestamp, | |
451 | _can_append: bool, |
|
436 | _can_append: bool, | |
452 | ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> { |
|
437 | ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> { | |
453 | panic!( |
|
438 | panic!( | |
454 | "should have used dirstate_tree::DirstateMap to use the v2 format" |
|
439 | "should have used dirstate_tree::DirstateMap to use the v2 format" | |
455 | ) |
|
440 | ) | |
456 | } |
|
441 | } | |
457 |
|
442 | |||
458 | fn status<'a>( |
|
443 | fn status<'a>( | |
459 | &'a mut self, |
|
444 | &'a mut self, | |
460 | matcher: &'a (dyn Matcher + Sync), |
|
445 | matcher: &'a (dyn Matcher + Sync), | |
461 | root_dir: PathBuf, |
|
446 | root_dir: PathBuf, | |
462 | ignore_files: Vec<PathBuf>, |
|
447 | ignore_files: Vec<PathBuf>, | |
463 | options: StatusOptions, |
|
448 | options: StatusOptions, | |
464 | ) -> Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError> |
|
449 | ) -> Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError> | |
465 | { |
|
450 | { | |
466 | crate::status(self, matcher, root_dir, ignore_files, options) |
|
451 | crate::status(self, matcher, root_dir, ignore_files, options) | |
467 | } |
|
452 | } | |
468 |
|
453 | |||
469 | fn copy_map_len(&self) -> usize { |
|
454 | fn copy_map_len(&self) -> usize { | |
470 | self.copy_map.len() |
|
455 | self.copy_map.len() | |
471 | } |
|
456 | } | |
472 |
|
457 | |||
473 | fn copy_map_iter(&self) -> CopyMapIter<'_> { |
|
458 | fn copy_map_iter(&self) -> CopyMapIter<'_> { | |
474 | Box::new( |
|
459 | Box::new( | |
475 | self.copy_map |
|
460 | self.copy_map | |
476 | .iter() |
|
461 | .iter() | |
477 | .map(|(key, value)| Ok((&**key, &**value))), |
|
462 | .map(|(key, value)| Ok((&**key, &**value))), | |
478 | ) |
|
463 | ) | |
479 | } |
|
464 | } | |
480 |
|
465 | |||
481 | fn copy_map_contains_key( |
|
466 | fn copy_map_contains_key( | |
482 | &self, |
|
467 | &self, | |
483 | key: &HgPath, |
|
468 | key: &HgPath, | |
484 | ) -> Result<bool, DirstateV2ParseError> { |
|
469 | ) -> Result<bool, DirstateV2ParseError> { | |
485 | Ok(self.copy_map.contains_key(key)) |
|
470 | Ok(self.copy_map.contains_key(key)) | |
486 | } |
|
471 | } | |
487 |
|
472 | |||
488 | fn copy_map_get( |
|
473 | fn copy_map_get( | |
489 | &self, |
|
474 | &self, | |
490 | key: &HgPath, |
|
475 | key: &HgPath, | |
491 | ) -> Result<Option<&HgPath>, DirstateV2ParseError> { |
|
476 | ) -> Result<Option<&HgPath>, DirstateV2ParseError> { | |
492 | Ok(self.copy_map.get(key).map(|p| &**p)) |
|
477 | Ok(self.copy_map.get(key).map(|p| &**p)) | |
493 | } |
|
478 | } | |
494 |
|
479 | |||
495 | fn copy_map_remove( |
|
480 | fn copy_map_remove( | |
496 | &mut self, |
|
481 | &mut self, | |
497 | key: &HgPath, |
|
482 | key: &HgPath, | |
498 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
|
483 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { | |
499 | Ok(self.copy_map.remove(key)) |
|
484 | Ok(self.copy_map.remove(key)) | |
500 | } |
|
485 | } | |
501 |
|
486 | |||
502 | fn copy_map_insert( |
|
487 | fn copy_map_insert( | |
503 | &mut self, |
|
488 | &mut self, | |
504 | key: HgPathBuf, |
|
489 | key: HgPathBuf, | |
505 | value: HgPathBuf, |
|
490 | value: HgPathBuf, | |
506 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { |
|
491 | ) -> Result<Option<HgPathBuf>, DirstateV2ParseError> { | |
507 | Ok(self.copy_map.insert(key, value)) |
|
492 | Ok(self.copy_map.insert(key, value)) | |
508 | } |
|
493 | } | |
509 |
|
494 | |||
510 | fn len(&self) -> usize { |
|
495 | fn len(&self) -> usize { | |
511 | (&**self).len() |
|
496 | (&**self).len() | |
512 | } |
|
497 | } | |
513 |
|
498 | |||
514 | fn contains_key( |
|
499 | fn contains_key( | |
515 | &self, |
|
500 | &self, | |
516 | key: &HgPath, |
|
501 | key: &HgPath, | |
517 | ) -> Result<bool, DirstateV2ParseError> { |
|
502 | ) -> Result<bool, DirstateV2ParseError> { | |
518 | Ok((&**self).contains_key(key)) |
|
503 | Ok((&**self).contains_key(key)) | |
519 | } |
|
504 | } | |
520 |
|
505 | |||
521 | fn get( |
|
506 | fn get( | |
522 | &self, |
|
507 | &self, | |
523 | key: &HgPath, |
|
508 | key: &HgPath, | |
524 | ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
|
509 | ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { | |
525 | Ok((&**self).get(key).cloned()) |
|
510 | Ok((&**self).get(key).cloned()) | |
526 | } |
|
511 | } | |
527 |
|
512 | |||
528 | fn iter(&self) -> StateMapIter<'_> { |
|
513 | fn iter(&self) -> StateMapIter<'_> { | |
529 | Box::new((&**self).iter().map(|(key, value)| Ok((&**key, *value)))) |
|
514 | Box::new((&**self).iter().map(|(key, value)| Ok((&**key, *value)))) | |
530 | } |
|
515 | } | |
531 |
|
516 | |||
532 | fn iter_tracked_dirs( |
|
517 | fn iter_tracked_dirs( | |
533 | &mut self, |
|
518 | &mut self, | |
534 | ) -> Result< |
|
519 | ) -> Result< | |
535 | Box< |
|
520 | Box< | |
536 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> |
|
521 | dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> | |
537 | + Send |
|
522 | + Send | |
538 | + '_, |
|
523 | + '_, | |
539 | >, |
|
524 | >, | |
540 | DirstateError, |
|
525 | DirstateError, | |
541 | > { |
|
526 | > { | |
542 | self.set_all_dirs()?; |
|
527 | self.set_all_dirs()?; | |
543 | Ok(Box::new( |
|
528 | Ok(Box::new( | |
544 | self.all_dirs |
|
529 | self.all_dirs | |
545 | .as_ref() |
|
530 | .as_ref() | |
546 | .unwrap() |
|
531 | .unwrap() | |
547 | .iter() |
|
532 | .iter() | |
548 | .map(|path| Ok(&**path)), |
|
533 | .map(|path| Ok(&**path)), | |
549 | )) |
|
534 | )) | |
550 | } |
|
535 | } | |
551 |
|
536 | |||
552 | fn debug_iter( |
|
537 | fn debug_iter( | |
553 | &self, |
|
538 | &self, | |
554 | all: bool, |
|
539 | all: bool, | |
555 | ) -> Box< |
|
540 | ) -> Box< | |
556 | dyn Iterator< |
|
541 | dyn Iterator< | |
557 | Item = Result< |
|
542 | Item = Result< | |
558 | (&HgPath, (u8, i32, i32, i32)), |
|
543 | (&HgPath, (u8, i32, i32, i32)), | |
559 | DirstateV2ParseError, |
|
544 | DirstateV2ParseError, | |
560 | >, |
|
545 | >, | |
561 | > + Send |
|
546 | > + Send | |
562 | + '_, |
|
547 | + '_, | |
563 | > { |
|
548 | > { | |
564 | // Not used for the flat (not tree-based) DirstateMap |
|
549 | // Not used for the flat (not tree-based) DirstateMap | |
565 | let _ = all; |
|
550 | let _ = all; | |
566 |
|
551 | |||
567 | Box::new( |
|
552 | Box::new( | |
568 | (&**self) |
|
553 | (&**self) | |
569 | .iter() |
|
554 | .iter() | |
570 | .map(|(path, entry)| Ok((&**path, entry.debug_tuple()))), |
|
555 | .map(|(path, entry)| Ok((&**path, entry.debug_tuple()))), | |
571 | ) |
|
556 | ) | |
572 | } |
|
557 | } | |
573 | } |
|
558 | } |
General Comments 0
You need to be logged in to leave comments.
Login now