annotate rust/hg-core/src/dirstate/dirstate_map.rs @ 47332:4ee9f419c52e

rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs This will enable the tree-based DirstateMap to not always have an actual DirstateEntry in memory for all nodes, but construct it on demand. Differential Revision: https://phab.mercurial-scm.org/D10746
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 19 May 2021 13:15:00 +0200
parents 73f23e7610f8
children ed1583a845d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
1 // dirstate_map.rs
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
2 //
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
4 //
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
5 // This software may be used and distributed according to the terms of the
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
6 // GNU General Public License version 2 or any later version.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
7
47101
5d62243c7732 rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents: 47093
diff changeset
8 use crate::dirstate::parsers::Timestamp;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
9 use crate::{
47121
b6339a993b91 rust: Remove handling of `parents` in `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents: 47109
diff changeset
10 dirstate::EntryState,
42840
b1b984f9c01d rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents: 42802
diff changeset
11 pack_dirstate, parse_dirstate,
47109
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47108
diff changeset
12 utils::hg_path::{HgPath, HgPathBuf},
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
13 CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError,
47109
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47108
diff changeset
14 DirstateParents, StateMap,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
15 };
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
16 use micro_timer::timed;
43826
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
17 use std::collections::HashSet;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
18 use std::iter::FromIterator;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
19 use std::ops::Deref;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
20
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
21 #[derive(Default)]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
22 pub struct DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
23 state_map: StateMap,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
24 pub copy_map: CopyMap,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
25 pub dirs: Option<DirsMultiset>,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
26 pub all_dirs: Option<DirsMultiset>,
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
27 non_normal_set: Option<HashSet<HgPathBuf>>,
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
28 other_parent_set: Option<HashSet<HgPathBuf>>,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
29 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
30
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
31 /// Should only really be used in python interface code, for clarity
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
32 impl Deref for DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
33 type Target = StateMap;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
34
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
35 fn deref(&self) -> &Self::Target {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
36 &self.state_map
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
37 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
38 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
39
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
40 impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
41 fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
42 iter: I,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
43 ) -> Self {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
44 Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
45 state_map: iter.into_iter().collect(),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
46 ..Self::default()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
47 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
48 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
49 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
50
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
51 impl DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
52 pub fn new() -> Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
53 Self::default()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
54 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
55
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
56 pub fn clear(&mut self) {
45610
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
57 self.state_map = StateMap::default();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
58 self.copy_map.clear();
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
59 self.non_normal_set = None;
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
60 self.other_parent_set = None;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
61 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
62
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
63 /// Add a tracked file to the dirstate
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
64 pub fn add_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
65 &mut self,
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
66 filename: &HgPath,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
67 old_state: EntryState,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
68 entry: DirstateEntry,
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43605
diff changeset
69 ) -> Result<(), DirstateMapError> {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
70 if old_state == EntryState::Unknown || old_state == EntryState::Removed
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
71 {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
72 if let Some(ref mut dirs) = self.dirs {
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43605
diff changeset
73 dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
74 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
75 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
76 if old_state == EntryState::Unknown {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
77 if let Some(ref mut all_dirs) = self.all_dirs {
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43605
diff changeset
78 all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
79 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
80 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
81 self.state_map.insert(filename.to_owned(), entry.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
82
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
83 if entry.is_non_normal() {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
84 self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
85 .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
86 .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
87 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
88
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
89 if entry.is_from_other_parent() {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
90 self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
91 .1
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
92 .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
93 }
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43605
diff changeset
94 Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
95 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
96
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
97 /// Mark a file as removed in the dirstate.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
98 ///
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
99 /// The `size` parameter is used to store sentinel values that indicate
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
100 /// the file's previous state. In the future, we should refactor this
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
101 /// to be more explicit about what that state is.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
102 pub fn remove_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
103 &mut self,
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
104 filename: &HgPath,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
105 old_state: EntryState,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
106 size: i32,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
107 ) -> Result<(), DirstateMapError> {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
108 if old_state != EntryState::Unknown && old_state != EntryState::Removed
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
109 {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
110 if let Some(ref mut dirs) = self.dirs {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
111 dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
112 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
113 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
114 if old_state == EntryState::Unknown {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
115 if let Some(ref mut all_dirs) = self.all_dirs {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
116 all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
117 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
118 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
119
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
120 self.state_map.insert(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
121 filename.to_owned(),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
122 DirstateEntry {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
123 state: EntryState::Removed,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
124 mode: 0,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
125 size,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
126 mtime: 0,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
127 },
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
128 );
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
129 self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
130 .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
131 .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
132 Ok(())
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
133 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
134
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
135 /// Remove a file from the dirstate.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
136 /// Returns `true` if the file was previously recorded.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
137 pub fn drop_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
138 &mut self,
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
139 filename: &HgPath,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
140 old_state: EntryState,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
141 ) -> Result<bool, DirstateMapError> {
42795
8d2d5dfa07f5 rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents: 42753
diff changeset
142 let exists = self.state_map.remove(filename).is_some();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
143
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
144 if exists {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
145 if old_state != EntryState::Removed {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
146 if let Some(ref mut dirs) = self.dirs {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
147 dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
148 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
149 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
150 if let Some(ref mut all_dirs) = self.all_dirs {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
151 all_dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
152 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
153 }
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
154 self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
155 .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
156 .remove(filename);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
157
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
158 Ok(exists)
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
159 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
160
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
161 pub fn clear_ambiguous_times(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
162 &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
163 filenames: Vec<HgPathBuf>,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
164 now: i32,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
165 ) {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
166 for filename in filenames {
45610
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
167 if let Some(entry) = self.state_map.get_mut(&filename) {
47330
73f23e7610f8 dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents: 47124
diff changeset
168 if entry.clear_ambiguous_mtime(now) {
47105
ba17a2ee85ac dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
169 self.get_non_normal_other_parent_entries()
ba17a2ee85ac dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
170 .0
ba17a2ee85ac dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
171 .insert(filename.to_owned());
45610
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
172 }
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
173 }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
174 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
175 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
176
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
177 pub fn non_normal_entries_remove(&mut self, key: impl AsRef<HgPath>) {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
178 self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
179 .0
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
180 .remove(key.as_ref());
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
181 }
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
182
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
183 pub fn non_normal_entries_union(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
184 &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
185 other: HashSet<HgPathBuf>,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
186 ) -> Vec<HgPathBuf> {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
187 self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
188 .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
189 .union(&other)
44973
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44416
diff changeset
190 .map(ToOwned::to_owned)
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
191 .collect()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
192 }
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
193
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
194 pub fn get_non_normal_other_parent_entries(
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
195 &mut self,
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
196 ) -> (&mut HashSet<HgPathBuf>, &mut HashSet<HgPathBuf>) {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
197 self.set_non_normal_other_parent_entries(false);
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
198 (
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
199 self.non_normal_set.as_mut().unwrap(),
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
200 self.other_parent_set.as_mut().unwrap(),
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
201 )
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
202 }
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
203
44416
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
204 /// Useful to get immutable references to those sets in contexts where
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
205 /// you only have an immutable reference to the `DirstateMap`, like when
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
206 /// sharing references with Python.
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
207 ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
208 /// TODO, get rid of this along with the other "setter/getter" stuff when
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
209 /// a nice typestate plan is defined.
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
210 ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
211 /// # Panics
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
212 ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
213 /// Will panic if either set is `None`.
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
214 pub fn get_non_normal_other_parent_entries_panic(
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
215 &self,
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
216 ) -> (&HashSet<HgPathBuf>, &HashSet<HgPathBuf>) {
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
217 (
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
218 self.non_normal_set.as_ref().unwrap(),
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
219 self.other_parent_set.as_ref().unwrap(),
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
220 )
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
221 }
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
222
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
223 pub fn set_non_normal_other_parent_entries(&mut self, force: bool) {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
224 if !force
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
225 && self.non_normal_set.is_some()
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
226 && self.other_parent_set.is_some()
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
227 {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
228 return;
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
229 }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
230 let mut non_normal = HashSet::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
231 let mut other_parent = HashSet::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
232
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
233 for (filename, entry) in self.state_map.iter() {
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
234 if entry.is_non_normal() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
235 non_normal.insert(filename.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
236 }
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
237 if entry.is_from_other_parent() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
238 other_parent.insert(filename.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
239 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
240 }
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
241 self.non_normal_set = Some(non_normal);
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
242 self.other_parent_set = Some(other_parent);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
243 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
244
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
245 /// Both of these setters and their uses appear to be the simplest way to
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
246 /// emulate a Python lazy property, but it is ugly and unidiomatic.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
247 /// TODO One day, rewriting this struct using the typestate might be a
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
248 /// good idea.
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
249 pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
250 if self.all_dirs.is_none() {
47093
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
251 self.all_dirs = Some(DirsMultiset::from_dirstate(
47332
4ee9f419c52e rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
252 self.state_map.iter().map(|(k, v)| (k, *v)),
47093
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
253 None,
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
254 )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
255 }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
256 Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
257 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
258
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
259 pub fn set_dirs(&mut self) -> Result<(), DirstateMapError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
260 if self.dirs.is_none() {
42802
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42801
diff changeset
261 self.dirs = Some(DirsMultiset::from_dirstate(
47332
4ee9f419c52e rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
262 self.state_map.iter().map(|(k, v)| (k, *v)),
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
263 Some(EntryState::Removed),
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
264 )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
265 }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
266 Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
267 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
268
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
269 pub fn has_tracked_dir(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
270 &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
271 directory: &HgPath,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
272 ) -> Result<bool, DirstateMapError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
273 self.set_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
274 Ok(self.dirs.as_ref().unwrap().contains(directory))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
275 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
276
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
277 pub fn has_dir(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
278 &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
279 directory: &HgPath,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
280 ) -> Result<bool, DirstateMapError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
281 self.set_all_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
282 Ok(self.all_dirs.as_ref().unwrap().contains(directory))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
283 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
284
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
285 #[timed]
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
286 pub fn read(
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
287 &mut self,
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
288 file_contents: &[u8],
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
289 ) -> Result<Option<DirstateParents>, DirstateError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
290 if file_contents.is_empty() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
291 return Ok(None);
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
292 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
293
45357
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
294 let (parents, entries, copies) = parse_dirstate(file_contents)?;
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
295 self.state_map.extend(
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
296 entries
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
297 .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
298 .map(|(path, entry)| (path.to_owned(), entry)),
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
299 );
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
300 self.copy_map.extend(
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
301 copies
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
302 .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
303 .map(|(path, copy)| (path.to_owned(), copy.to_owned())),
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
304 );
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
305 Ok(Some(parents.clone()))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
306 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
307
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
308 pub fn pack(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
309 &mut self,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
310 parents: DirstateParents,
47101
5d62243c7732 rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents: 47093
diff changeset
311 now: Timestamp,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
312 ) -> Result<Vec<u8>, DirstateError> {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
313 let packed =
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
314 pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
315
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
316 self.set_non_normal_other_parent_entries(true);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
317 Ok(packed)
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
318 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
319 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
320
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
321 #[cfg(test)]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
322 mod tests {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
323 use super::*;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
324
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
325 #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
326 fn test_dirs_multiset() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
327 let mut map = DirstateMap::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
328 assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
329 assert!(map.all_dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
330
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
331 assert_eq!(map.has_dir(HgPath::new(b"nope")).unwrap(), false);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
332 assert!(map.all_dirs.is_some());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
333 assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
334
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
335 assert_eq!(map.has_tracked_dir(HgPath::new(b"nope")).unwrap(), false);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
336 assert!(map.dirs.is_some());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
337 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
338
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
339 #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
340 fn test_add_file() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
341 let mut map = DirstateMap::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
342
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
343 assert_eq!(0, map.len());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
344
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
345 map.add_file(
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
346 HgPath::new(b"meh"),
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
347 EntryState::Normal,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
348 DirstateEntry {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
349 state: EntryState::Normal,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
350 mode: 1337,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
351 mtime: 1337,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
352 size: 1337,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
353 },
43890
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
354 )
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
355 .unwrap();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
356
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
357 assert_eq!(1, map.len());
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
358 assert_eq!(0, map.get_non_normal_other_parent_entries().0.len());
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
359 assert_eq!(0, map.get_non_normal_other_parent_entries().1.len());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
360 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
361
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
362 #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
363 fn test_non_normal_other_parent_entries() {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
364 let mut map: DirstateMap = [
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
365 (b"f1", (EntryState::Removed, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
366 (b"f2", (EntryState::Normal, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
367 (b"f3", (EntryState::Normal, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
368 (b"f4", (EntryState::Normal, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
369 (b"f5", (EntryState::Added, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
370 (b"f6", (EntryState::Added, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
371 (b"f7", (EntryState::Merged, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
372 (b"f8", (EntryState::Merged, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
373 (b"f9", (EntryState::Merged, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
374 (b"fa", (EntryState::Added, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
375 (b"fb", (EntryState::Removed, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
376 ]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
377 .iter()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
378 .map(|(fname, (state, mode, size, mtime))| {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
379 (
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
380 HgPathBuf::from_bytes(fname.as_ref()),
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
381 DirstateEntry {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
382 state: *state,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
383 mode: *mode,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
384 size: *size,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
385 mtime: *mtime,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
386 },
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
387 )
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
388 })
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
389 .collect();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
390
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
391 let mut non_normal = [
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
392 b"f1", b"f2", b"f5", b"f6", b"f7", b"f8", b"f9", b"fa", b"fb",
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
393 ]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
394 .iter()
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
395 .map(|x| HgPathBuf::from_bytes(x.as_ref()))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
396 .collect();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
397
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
398 let mut other_parent = HashSet::new();
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
399 other_parent.insert(HgPathBuf::from_bytes(b"f4"));
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
400 let entries = map.get_non_normal_other_parent_entries();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
401
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
402 assert_eq!(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
403 (&mut non_normal, &mut other_parent),
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
404 (entries.0, entries.1)
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
405 );
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
406 }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
407 }