Mercurial > hg
annotate rust/hg-core/src/dirstate/dirstate_map.rs @ 48050:2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Those removing a DirstateItem and a copy source are always done together
Differential Revision: https://phab.mercurial-scm.org/D11493
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 23 Sep 2021 15:36:43 +0200 |
parents | 76f1c76186a1 |
children | 98c0408324e6 |
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, |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
11 dirstate::MTIME_UNSET, |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
12 dirstate::SIZE_FROM_OTHER_PARENT, |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
13 dirstate::SIZE_NON_NORMAL, |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
14 dirstate::V1_RANGEMASK, |
42840
b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents:
42802
diff
changeset
|
15 pack_dirstate, parse_dirstate, |
47109
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47108
diff
changeset
|
16 utils::hg_path::{HgPath, HgPathBuf}, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
17 CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
18 StateMap, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 }; |
45558
80bf7b1ada15
rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents:
45531
diff
changeset
|
20 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
|
21 use std::collections::HashSet; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 use std::iter::FromIterator; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 use std::ops::Deref; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 #[derive(Default)] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 pub struct DirstateMap { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 state_map: StateMap, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 pub copy_map: CopyMap, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 pub dirs: Option<DirsMultiset>, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 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
|
31 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
|
32 other_parent_set: Option<HashSet<HgPathBuf>>, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 } |
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 /// 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
|
36 impl Deref for DirstateMap { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 type Target = StateMap; |
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 fn deref(&self) -> &Self::Target { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 &self.state_map |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
44 impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap { |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
45 fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>( |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
46 iter: I, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
47 ) -> Self { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 Self { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 state_map: iter.into_iter().collect(), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 ..Self::default() |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 } |
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 impl DirstateMap { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 pub fn new() -> Self { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 Self::default() |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 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
|
61 self.state_map = StateMap::default(); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 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
|
63 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
|
64 self.other_parent_set = None; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
48045
32ef647821b2
dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
67 pub fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { |
47692
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
68 self.state_map.insert(filename.to_owned(), entry); |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
69 } |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
70 |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 /// Add a tracked file to the dirstate |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 pub fn add_file( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 &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
|
74 filename: &HgPath, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 entry: DirstateEntry, |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
76 // XXX once the dust settle this should probably become an enum |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
77 added: bool, |
47527
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
78 merged: bool, |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
79 from_p2: bool, |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
80 possibly_dirty: bool, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
81 ) -> Result<(), DirstateError> { |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
82 let state; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
83 let size; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
84 let mtime; |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
85 if added { |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
86 assert!(!possibly_dirty); |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
87 assert!(!from_p2); |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
88 state = EntryState::Added; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
89 size = SIZE_NON_NORMAL; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
90 mtime = MTIME_UNSET; |
47527
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
91 } else if merged { |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
92 assert!(!possibly_dirty); |
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
93 assert!(!from_p2); |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
94 state = EntryState::Merged; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
95 size = SIZE_FROM_OTHER_PARENT; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
96 mtime = MTIME_UNSET; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
97 } else if from_p2 { |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
98 assert!(!possibly_dirty); |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
99 state = EntryState::Normal; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
100 size = SIZE_FROM_OTHER_PARENT; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
101 mtime = MTIME_UNSET; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
102 } else if possibly_dirty { |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
103 state = EntryState::Normal; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
104 size = SIZE_NON_NORMAL; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
105 mtime = MTIME_UNSET; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
106 } else { |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
107 state = EntryState::Normal; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
108 size = entry.size() & V1_RANGEMASK; |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
109 mtime = entry.mtime() & V1_RANGEMASK; |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
110 } |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
111 let mode = entry.mode(); |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
112 let entry = DirstateEntry::from_v1_data(state, mode, size, mtime); |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
113 |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
114 let old_state = self.get(filename).map(|e| e.state()); |
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
115 if old_state.is_none() || old_state == Some(EntryState::Removed) { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 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
|
117 dirs.add_path(filename)?; |
42753
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 } |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
120 if old_state.is_none() { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 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
|
122 all_dirs.add_path(filename)?; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 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
|
126 |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
127 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
|
128 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
|
129 .0 |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
130 .insert(filename.to_owned()); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
133 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
|
134 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
|
135 .1 |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
136 .insert(filename.to_owned()); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 } |
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
|
138 Ok(()) |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 /// 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
|
142 /// |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
143 /// 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
|
144 /// 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
|
145 /// 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
|
146 pub fn remove_file( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 &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
|
148 filename: &HgPath, |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
149 in_merge: bool, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
150 ) -> Result<(), DirstateError> { |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
151 let old_entry_opt = self.get(filename); |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
152 let old_state = old_entry_opt.map(|e| e.state()); |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
153 let mut size = 0; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
154 if in_merge { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
155 // XXX we should not be able to have 'm' state and 'FROM_P2' if not |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
156 // during a merge. So I (marmoute) am not sure we need the |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
157 // conditionnal at all. Adding double checking this with assert |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
158 // would be nice. |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
159 if let Some(old_entry) = old_entry_opt { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
160 // backup the previous state |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
161 if old_entry.state() == EntryState::Merged { |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
162 size = SIZE_NON_NORMAL; |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
163 } else if old_entry.state() == EntryState::Normal |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
164 && old_entry.size() == SIZE_FROM_OTHER_PARENT |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
165 { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
166 // other parent |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
167 size = SIZE_FROM_OTHER_PARENT; |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
168 self.get_non_normal_other_parent_entries() |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
169 .1 |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
170 .insert(filename.to_owned()); |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
171 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
172 } |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
173 } |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
174 if old_state.is_some() && old_state != Some(EntryState::Removed) { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
175 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
|
176 dirs.delete_path(filename)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
177 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
178 } |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
179 if old_state.is_none() { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 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
|
181 all_dirs.add_path(filename)?; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 } |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
184 if size == 0 { |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
185 self.copy_map.remove(filename); |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47335
diff
changeset
|
186 } |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
188 self.state_map |
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
189 .insert(filename.to_owned(), DirstateEntry::new_removed(size)); |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
190 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
|
191 .0 |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
192 .insert(filename.to_owned()); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 Ok(()) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 /// Remove a file from the dirstate. |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 /// Returns `true` if the file was previously recorded. |
48050
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48048
diff
changeset
|
198 pub fn drop_entry_and_copy_source( |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 &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
|
200 filename: &HgPath, |
48048
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
201 ) -> Result<(), DirstateError> { |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
202 let old_state = self.get(filename).map(|e| e.state()); |
42795
8d2d5dfa07f5
rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents:
42753
diff
changeset
|
203 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
|
204 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 if exists { |
48026
1b2ee68e85f9
rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
206 if old_state != Some(EntryState::Removed) { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
207 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
|
208 dirs.delete_path(filename)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 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
|
212 all_dirs.delete_path(filename)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
214 } |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
215 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
|
216 .0 |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
217 .remove(filename); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
218 |
48050
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48048
diff
changeset
|
219 self.copy_map.remove(filename); |
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48048
diff
changeset
|
220 |
48048
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48045
diff
changeset
|
221 Ok(()) |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
222 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
224 pub fn clear_ambiguous_times( |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
225 &mut self, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
226 filenames: Vec<HgPathBuf>, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
227 now: i32, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
228 ) { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 .0 |
ba17a2ee85ac
dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
234 .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
|
235 } |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45588
diff
changeset
|
236 } |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
239 |
47692
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
240 pub fn non_normal_entries_remove( |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
241 &mut self, |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
242 key: impl AsRef<HgPath>, |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
243 ) -> bool { |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
244 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
|
245 .0 |
47692
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
246 .remove(key.as_ref()) |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
247 } |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
248 |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
249 pub fn non_normal_entries_add(&mut self, key: impl AsRef<HgPath>) { |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
250 self.get_non_normal_other_parent_entries() |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
251 .0 |
e5fb14a07866
dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47535
diff
changeset
|
252 .insert(key.as_ref().into()); |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
253 } |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
254 |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
255 pub fn non_normal_entries_union( |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
256 &mut self, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
257 other: HashSet<HgPathBuf>, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
258 ) -> Vec<HgPathBuf> { |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
259 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
|
260 .0 |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
261 .union(&other) |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44416
diff
changeset
|
262 .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
|
263 .collect() |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
264 } |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
265 |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
266 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
|
267 &mut self, |
44362
c089a0947f3e
rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents:
44293
diff
changeset
|
268 ) -> (&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
|
269 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
|
270 ( |
c089a0947f3e
rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents:
44293
diff
changeset
|
271 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
|
272 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
|
273 ) |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
274 } |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
275 |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
276 /// 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
|
277 /// 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
|
278 /// 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
|
279 /// |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
280 /// 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
|
281 /// 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
|
282 /// |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
283 /// # Panics |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
284 /// |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
285 /// 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
|
286 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
|
287 &self, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
288 ) -> (&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
|
289 ( |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
290 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
|
291 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
|
292 ) |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
293 } |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
294 |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
295 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
|
296 if !force |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
297 && self.non_normal_set.is_some() |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
298 && self.other_parent_set.is_some() |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
299 { |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
300 return; |
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
301 } |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 let mut non_normal = HashSet::new(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
303 let mut other_parent = HashSet::new(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
304 |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
305 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
|
306 if entry.is_non_normal() { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
307 non_normal.insert(filename.to_owned()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 } |
47108
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47105
diff
changeset
|
309 if entry.is_from_other_parent() { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
310 other_parent.insert(filename.to_owned()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
311 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
312 } |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
313 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
|
314 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
|
315 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 /// 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
|
318 /// 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
|
319 /// 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
|
320 /// good idea. |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
321 pub fn set_all_dirs(&mut self) -> Result<(), DirstateError> { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 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
|
323 self.all_dirs = Some(DirsMultiset::from_dirstate( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
324 self.state_map.iter().map(|(k, v)| Ok((k, *v))), |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47692
diff
changeset
|
325 false, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
326 )?); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 } |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
328 Ok(()) |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
329 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
330 |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
331 pub fn set_dirs(&mut self) -> Result<(), DirstateError> { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 if self.dirs.is_none() { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
333 self.dirs = Some(DirsMultiset::from_dirstate( |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
334 self.state_map.iter().map(|(k, v)| Ok((k, *v))), |
47944
e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47692
diff
changeset
|
335 true, |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
336 )?); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 } |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
338 Ok(()) |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
341 pub fn has_tracked_dir( |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
342 &mut self, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
343 directory: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
344 ) -> Result<bool, DirstateError> { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
345 self.set_dirs()?; |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
346 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
|
347 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
348 |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
349 pub fn has_dir( |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
350 &mut self, |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
351 directory: &HgPath, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
352 ) -> Result<bool, DirstateError> { |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
353 self.set_all_dirs()?; |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
354 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
|
355 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
356 |
45558
80bf7b1ada15
rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents:
45531
diff
changeset
|
357 #[timed] |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
358 pub fn read( |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
359 &mut self, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
360 file_contents: &[u8], |
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
361 ) -> Result<Option<DirstateParents>, DirstateError> { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 if file_contents.is_empty() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 return Ok(None); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
364 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
365 |
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
366 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
|
367 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
|
368 entries |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
369 .into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
370 .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
|
371 ); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
372 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
|
373 copies |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
374 .into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
375 .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
|
376 ); |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
377 Ok(Some(parents.clone())) |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
378 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
380 pub fn pack( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 &mut self, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 parents: DirstateParents, |
47101
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
383 now: Timestamp, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 ) -> Result<Vec<u8>, DirstateError> { |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
385 let packed = |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
386 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
|
387 |
44293
83b2b829c94e
rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents:
43890
diff
changeset
|
388 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
|
389 Ok(packed) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
390 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
393 #[cfg(test)] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
394 mod tests { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 use super::*; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
396 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
397 #[test] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
398 fn test_dirs_multiset() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
399 let mut map = DirstateMap::new(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
400 assert!(map.dirs.is_none()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
401 assert!(map.all_dirs.is_none()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
402 |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
403 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
|
404 assert!(map.all_dirs.is_some()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
405 assert!(map.dirs.is_none()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
406 |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
407 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
|
408 assert!(map.dirs.is_some()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 #[test] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
412 fn test_add_file() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
413 let mut map = DirstateMap::new(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
414 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
415 assert_eq!(0, map.len()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
416 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 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
|
418 HgPath::new(b"meh"), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
419 DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337), |
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
420 false, |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
421 false, |
47525
fe4641cf9b72
dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47524
diff
changeset
|
422 false, |
47527
c6b91a9c242a
dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47525
diff
changeset
|
423 false, |
43890
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
424 ) |
d8a96cebf75d
rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
425 .unwrap(); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
426 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
431 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
432 #[test] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
433 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
|
434 let mut map: DirstateMap = [ |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
435 (b"f1", (EntryState::Removed, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
436 (b"f2", (EntryState::Normal, 1337, 1337, -1)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
437 (b"f3", (EntryState::Normal, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
438 (b"f4", (EntryState::Normal, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
439 (b"f5", (EntryState::Added, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
440 (b"f6", (EntryState::Added, 1337, 1337, -1)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
441 (b"f7", (EntryState::Merged, 1337, 1337, -1)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
442 (b"f8", (EntryState::Merged, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
443 (b"f9", (EntryState::Merged, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
444 (b"fa", (EntryState::Added, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
445 (b"fb", (EntryState::Removed, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
446 ] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
447 .iter() |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
448 .map(|(fname, (state, mode, size, mtime))| { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
449 ( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
450 HgPathBuf::from_bytes(fname.as_ref()), |
48022
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
47944
diff
changeset
|
451 DirstateEntry::from_v1_data(*state, *mode, *size, *mtime), |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
452 ) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
453 }) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
454 .collect(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
455 |
44362
c089a0947f3e
rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents:
44293
diff
changeset
|
456 let mut non_normal = [ |
48042
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
457 b"f1", b"f2", b"f4", b"f5", b"f6", b"f7", b"f8", b"f9", b"fa", |
008959fcbfb2
rust: Align DirstateEntry internals with Python/C DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48026
diff
changeset
|
458 b"fb", |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
459 ] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
460 .iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
461 .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
|
462 .collect(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
463 |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 |
45588
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
468 assert_eq!( |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
469 (&mut non_normal, &mut other_parent), |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
470 (entries.0, entries.1) |
c35db907363d
rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents:
45558
diff
changeset
|
471 ); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
472 } |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
473 } |