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