##// END OF EJS Templates
dirstate-tree: Add "non normal" and "from other parent" sets...
Simon Sapin -
r47878:e3cebe96 default
parent child Browse files
Show More
@@ -34,6 +34,16 b' pub struct DirstateEntry {'
34 pub size: i32,
34 pub size: i32,
35 }
35 }
36
36
37 impl DirstateEntry {
38 pub fn is_non_normal(&self) -> bool {
39 self.state != EntryState::Normal || self.mtime == MTIME_UNSET
40 }
41
42 pub fn is_from_other_parent(&self) -> bool {
43 self.state == EntryState::Normal && self.size == SIZE_FROM_OTHER_PARENT
44 }
45 }
46
37 #[derive(BytesCast)]
47 #[derive(BytesCast)]
38 #[repr(C)]
48 #[repr(C)]
39 struct RawEntry {
49 struct RawEntry {
@@ -44,6 +54,8 b' struct RawEntry {'
44 length: unaligned::I32Be,
54 length: unaligned::I32Be,
45 }
55 }
46
56
57 const MTIME_UNSET: i32 = -1;
58
47 /// A `DirstateEntry` with a size of `-2` means that it was merged from the
59 /// A `DirstateEntry` with a size of `-2` means that it was merged from the
48 /// other parent. This allows revert to pick the right status back during a
60 /// other parent. This allows revert to pick the right status back during a
49 /// merge.
61 /// merge.
@@ -10,7 +10,7 b' use crate::dirstate::parsers::Timestamp;'
10 use crate::errors::HgError;
10 use crate::errors::HgError;
11 use crate::revlog::node::NULL_NODE;
11 use crate::revlog::node::NULL_NODE;
12 use crate::{
12 use crate::{
13 dirstate::{parsers::PARENT_SIZE, EntryState, SIZE_FROM_OTHER_PARENT},
13 dirstate::{parsers::PARENT_SIZE, EntryState},
14 pack_dirstate, parse_dirstate,
14 pack_dirstate, parse_dirstate,
15 utils::{
15 utils::{
16 files::normalize_case,
16 files::normalize_case,
@@ -27,8 +27,6 b' use std::ops::Deref;'
27
27
28 pub type FileFoldMap = FastHashMap<HgPathBuf, HgPathBuf>;
28 pub type FileFoldMap = FastHashMap<HgPathBuf, HgPathBuf>;
29
29
30 const MTIME_UNSET: i32 = -1;
31
32 #[derive(Default)]
30 #[derive(Default)]
33 pub struct DirstateMap {
31 pub struct DirstateMap {
34 state_map: StateMap,
32 state_map: StateMap,
@@ -99,13 +97,13 b' impl DirstateMap {'
99 }
97 }
100 self.state_map.insert(filename.to_owned(), entry.to_owned());
98 self.state_map.insert(filename.to_owned(), entry.to_owned());
101
99
102 if entry.state != EntryState::Normal || entry.mtime == MTIME_UNSET {
100 if entry.is_non_normal() {
103 self.get_non_normal_other_parent_entries()
101 self.get_non_normal_other_parent_entries()
104 .0
102 .0
105 .insert(filename.to_owned());
103 .insert(filename.to_owned());
106 }
104 }
107
105
108 if entry.size == SIZE_FROM_OTHER_PARENT {
106 if entry.is_from_other_parent() {
109 self.get_non_normal_other_parent_entries()
107 self.get_non_normal_other_parent_entries()
110 .1
108 .1
111 .insert(filename.to_owned());
109 .insert(filename.to_owned());
@@ -199,14 +197,12 b' impl DirstateMap {'
199 }
197 }
200 }
198 }
201
199
202 pub fn non_normal_entries_remove(
200 pub fn non_normal_entries_remove(&mut self, key: impl AsRef<HgPath>) {
203 &mut self,
204 key: impl AsRef<HgPath>,
205 ) -> bool {
206 self.get_non_normal_other_parent_entries()
201 self.get_non_normal_other_parent_entries()
207 .0
202 .0
208 .remove(key.as_ref())
203 .remove(key.as_ref());
209 }
204 }
205
210 pub fn non_normal_entries_union(
206 pub fn non_normal_entries_union(
211 &mut self,
207 &mut self,
212 other: HashSet<HgPathBuf>,
208 other: HashSet<HgPathBuf>,
@@ -257,18 +253,11 b' impl DirstateMap {'
257 let mut non_normal = HashSet::new();
253 let mut non_normal = HashSet::new();
258 let mut other_parent = HashSet::new();
254 let mut other_parent = HashSet::new();
259
255
260 for (
256 for (filename, entry) in self.state_map.iter() {
261 filename,
257 if entry.is_non_normal() {
262 DirstateEntry {
263 state, size, mtime, ..
264 },
265 ) in self.state_map.iter()
266 {
267 if *state != EntryState::Normal || *mtime == MTIME_UNSET {
268 non_normal.insert(filename.to_owned());
258 non_normal.insert(filename.to_owned());
269 }
259 }
270 if *state == EntryState::Normal && *size == SIZE_FROM_OTHER_PARENT
260 if entry.is_from_other_parent() {
271 {
272 other_parent.insert(filename.to_owned());
261 other_parent.insert(filename.to_owned());
273 }
262 }
274 }
263 }
@@ -397,40 +397,61 b' impl super::dispatch::DirstateMapMethods'
397 }
397 }
398 }
398 }
399
399
400 fn non_normal_entries_contains(&mut self, _key: &HgPath) -> bool {
400 fn non_normal_entries_contains(&mut self, key: &HgPath) -> bool {
401 todo!()
401 self.get_node(key)
402 .and_then(|node| node.entry.as_ref())
403 .map_or(false, DirstateEntry::is_non_normal)
402 }
404 }
403
405
404 fn non_normal_entries_remove(&mut self, _key: &HgPath) -> bool {
406 fn non_normal_entries_remove(&mut self, _key: &HgPath) {
405 todo!()
407 // Do nothing, this `DirstateMap` does not have a separate "non normal
408 // entries" set that need to be kept up to date
406 }
409 }
407
410
408 fn non_normal_or_other_parent_paths(
411 fn non_normal_or_other_parent_paths(
409 &mut self,
412 &mut self,
410 ) -> Box<dyn Iterator<Item = &HgPathBuf> + '_> {
413 ) -> Box<dyn Iterator<Item = &HgPathBuf> + '_> {
411 todo!()
414 Box::new(self.iter_nodes().filter_map(|(path, node)| {
415 node.entry
416 .as_ref()
417 .filter(|entry| {
418 entry.is_non_normal() || entry.is_from_other_parent()
419 })
420 .map(|_| path.full_path())
421 }))
412 }
422 }
413
423
414 fn set_non_normal_other_parent_entries(&mut self, _force: bool) {
424 fn set_non_normal_other_parent_entries(&mut self, _force: bool) {
415 todo!()
425 // Do nothing, this `DirstateMap` does not have a separate "non normal
426 // entries" and "from other parent" sets that need to be recomputed
416 }
427 }
417
428
418 fn iter_non_normal_paths(
429 fn iter_non_normal_paths(
419 &mut self,
430 &mut self,
420 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
431 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
421 todo!()
432 self.iter_non_normal_paths_panic()
422 }
433 }
423
434
424 fn iter_non_normal_paths_panic(
435 fn iter_non_normal_paths_panic(
425 &self,
436 &self,
426 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
437 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
427 todo!()
438 Box::new(self.iter_nodes().filter_map(|(path, node)| {
439 node.entry
440 .as_ref()
441 .filter(|entry| entry.is_non_normal())
442 .map(|_| path.full_path())
443 }))
428 }
444 }
429
445
430 fn iter_other_parent_paths(
446 fn iter_other_parent_paths(
431 &mut self,
447 &mut self,
432 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
448 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
433 todo!()
449 Box::new(self.iter_nodes().filter_map(|(path, node)| {
450 node.entry
451 .as_ref()
452 .filter(|entry| entry.is_from_other_parent())
453 .map(|_| path.full_path())
454 }))
434 }
455 }
435
456
436 fn has_tracked_dir(
457 fn has_tracked_dir(
@@ -45,7 +45,7 b' pub trait DirstateMapMethods {'
45
45
46 fn non_normal_entries_contains(&mut self, key: &HgPath) -> bool;
46 fn non_normal_entries_contains(&mut self, key: &HgPath) -> bool;
47
47
48 fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool;
48 fn non_normal_entries_remove(&mut self, key: &HgPath);
49
49
50 fn non_normal_or_other_parent_paths(
50 fn non_normal_or_other_parent_paths(
51 &mut self,
51 &mut self,
@@ -179,7 +179,7 b' impl DirstateMapMethods for DirstateMap '
179 non_normal.contains(key)
179 non_normal.contains(key)
180 }
180 }
181
181
182 fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool {
182 fn non_normal_entries_remove(&mut self, key: &HgPath) {
183 self.non_normal_entries_remove(key)
183 self.non_normal_entries_remove(key)
184 }
184 }
185
185
General Comments 0
You need to be logged in to leave comments. Login now