##// END OF EJS Templates
dirstate-tree: Add copy_map_insert and copy_map_remove...
Simon Sapin -
r47874:fdf6cfa0 default
parent child Browse files
Show More
@@ -89,6 +89,25 b' impl DirstateMap {'
89
89
90 /// This takes `root` instead of `&mut self` so that callers can mutate
90 /// This takes `root` instead of `&mut self` so that callers can mutate
91 /// other fields while the returned borrow is still valid
91 /// other fields while the returned borrow is still valid
92 fn get_node_mut<'tree>(
93 root: &'tree mut ChildNodes,
94 path: &HgPath,
95 ) -> Option<&'tree mut Node> {
96 let mut children = root;
97 let mut components = path.components();
98 let mut component =
99 components.next().expect("expected at least one components");
100 loop {
101 let child = children.get_mut(component)?;
102 if let Some(next_component) = components.next() {
103 component = next_component;
104 children = &mut child.children;
105 } else {
106 return Some(child);
107 }
108 }
109 }
110
92 fn get_or_insert_node<'tree>(
111 fn get_or_insert_node<'tree>(
93 root: &'tree mut ChildNodes,
112 root: &'tree mut ChildNodes,
94 path: &HgPath,
113 path: &HgPath,
@@ -463,16 +482,26 b' impl super::dispatch::DirstateMapMethods'
463 self.get_node(key)?.copy_source.as_ref()
482 self.get_node(key)?.copy_source.as_ref()
464 }
483 }
465
484
466 fn copy_map_remove(&mut self, _key: &HgPath) -> Option<HgPathBuf> {
485 fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf> {
467 todo!()
486 let count = &mut self.nodes_with_copy_source_count;
487 Self::get_node_mut(&mut self.root, key).and_then(|node| {
488 if node.copy_source.is_some() {
489 *count -= 1
490 }
491 node.copy_source.take()
492 })
468 }
493 }
469
494
470 fn copy_map_insert(
495 fn copy_map_insert(
471 &mut self,
496 &mut self,
472 _key: HgPathBuf,
497 key: HgPathBuf,
473 _value: HgPathBuf,
498 value: HgPathBuf,
474 ) -> Option<HgPathBuf> {
499 ) -> Option<HgPathBuf> {
475 todo!()
500 let node = Self::get_or_insert_node(&mut self.root, &key);
501 if node.copy_source.is_none() {
502 self.nodes_with_copy_source_count += 1
503 }
504 node.copy_source.replace(value)
476 }
505 }
477
506
478 fn len(&self) -> usize {
507 fn len(&self) -> usize {
General Comments 0
You need to be logged in to leave comments. Login now