comparison rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47113:be579775c2d9

dirstate-tree: Add the new `status()` algorithm With the dirstate organized in a tree that mirrors the structure of the filesystem tree, we can traverse both trees at the same time in order to compare them. This is hopefully more efficient that building multiple big hashmaps for all of the repository’s contents. Differential Revision: https://phab.mercurial-scm.org/D10547
author Simon Sapin <simon.sapin@octobus.net>
date Fri, 16 Apr 2021 12:12:41 +0200
parents d5956136d19d
children 04bcba539c96
comparison
equal deleted inserted replaced
47112:d5956136d19d 47113:be579775c2d9
25 use crate::StatusOptions; 25 use crate::StatusOptions;
26 26
27 pub struct DirstateMap { 27 pub struct DirstateMap {
28 parents: Option<DirstateParents>, 28 parents: Option<DirstateParents>,
29 dirty_parents: bool, 29 dirty_parents: bool,
30 root: ChildNodes, 30 pub(super) root: ChildNodes,
31 31
32 /// Number of nodes anywhere in the tree that have `.entry.is_some()`. 32 /// Number of nodes anywhere in the tree that have `.entry.is_some()`.
33 nodes_with_entry_count: usize, 33 nodes_with_entry_count: usize,
34 34
35 /// Number of nodes anywhere in the tree that have 35 /// Number of nodes anywhere in the tree that have
40 /// Using a plain `HgPathBuf` of the full path from the repository root as a 40 /// Using a plain `HgPathBuf` of the full path from the repository root as a
41 /// map key would also work: all paths in a given map have the same parent 41 /// map key would also work: all paths in a given map have the same parent
42 /// path, so comparing full paths gives the same result as comparing base 42 /// path, so comparing full paths gives the same result as comparing base
43 /// names. However `BTreeMap` would waste time always re-comparing the same 43 /// names. However `BTreeMap` would waste time always re-comparing the same
44 /// string prefix. 44 /// string prefix.
45 type ChildNodes = BTreeMap<WithBasename<HgPathBuf>, Node>; 45 pub(super) type ChildNodes = BTreeMap<WithBasename<HgPathBuf>, Node>;
46 46
47 /// Represents a file or a directory 47 /// Represents a file or a directory
48 #[derive(Default)] 48 #[derive(Default)]
49 struct Node { 49 pub(super) struct Node {
50 /// `None` for directories 50 /// `None` for directories
51 entry: Option<DirstateEntry>, 51 pub(super) entry: Option<DirstateEntry>,
52 52
53 copy_source: Option<HgPathBuf>, 53 pub(super) copy_source: Option<HgPathBuf>,
54 54
55 children: ChildNodes, 55 pub(super) children: ChildNodes,
56 56
57 /// How many (non-inclusive) descendants of this node are tracked files 57 /// How many (non-inclusive) descendants of this node are tracked files
58 tracked_descendants_count: usize, 58 tracked_descendants_count: usize,
59 } 59 }
60 60
64 if let Some(entry) = &self.entry { 64 if let Some(entry) = &self.entry {
65 entry.state.is_tracked() 65 entry.state.is_tracked()
66 } else { 66 } else {
67 false 67 false
68 } 68 }
69 }
70
71 pub(super) fn state(&self) -> Option<EntryState> {
72 self.entry.as_ref().map(|entry| entry.state)
69 } 73 }
70 } 74 }
71 75
72 /// `(full_path, entry, copy_source)` 76 /// `(full_path, entry, copy_source)`
73 type NodeDataMut<'a> = ( 77 type NodeDataMut<'a> = (