699 } |
699 } |
700 } |
700 } |
701 Ok(()) |
701 Ok(()) |
702 } |
702 } |
703 |
703 |
704 /// Return a faillilble iterator of full paths of nodes that have an |
|
705 /// `entry` for which the given `predicate` returns true. |
|
706 /// |
|
707 /// Fallibility means that each iterator item is a `Result`, which may |
|
708 /// indicate a parse error of the on-disk dirstate-v2 format. Such errors |
|
709 /// should only happen if Mercurial is buggy or a repository is corrupted. |
|
710 fn filter_full_paths<'tree>( |
|
711 &'tree self, |
|
712 predicate: impl Fn(&DirstateEntry) -> bool + 'tree, |
|
713 ) -> impl Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + 'tree |
|
714 { |
|
715 filter_map_results(self.iter_nodes(), move |node| { |
|
716 if let Some(entry) = node.entry()? { |
|
717 if predicate(&entry) { |
|
718 return Ok(Some(node.full_path(self.on_disk)?)); |
|
719 } |
|
720 } |
|
721 Ok(None) |
|
722 }) |
|
723 } |
|
724 |
|
725 fn count_dropped_path(unreachable_bytes: &mut u32, path: &Cow<HgPath>) { |
704 fn count_dropped_path(unreachable_bytes: &mut u32, path: &Cow<HgPath>) { |
726 if let Cow::Borrowed(path) = path { |
705 if let Cow::Borrowed(path) = path { |
727 *unreachable_bytes += path.len() as u32 |
706 *unreachable_bytes += path.len() as u32 |
728 } |
707 } |
729 } |
708 } |
915 debug_assert!(!was_tracked); |
894 debug_assert!(!was_tracked); |
916 } |
895 } |
917 Ok(()) |
896 Ok(()) |
918 } |
897 } |
919 |
898 |
920 fn non_normal_entries_contains( |
|
921 &mut self, |
|
922 key: &HgPath, |
|
923 ) -> Result<bool, DirstateV2ParseError> { |
|
924 Ok(if let Some(node) = self.get_node(key)? { |
|
925 node.entry()?.map_or(false, |entry| entry.is_non_normal()) |
|
926 } else { |
|
927 false |
|
928 }) |
|
929 } |
|
930 |
|
931 fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool { |
|
932 // Do nothing, this `DirstateMap` does not have a separate "non normal |
|
933 // entries" set that need to be kept up to date. |
|
934 if let Ok(Some(v)) = self.get(key) { |
|
935 return v.is_non_normal(); |
|
936 } |
|
937 false |
|
938 } |
|
939 |
|
940 fn non_normal_entries_add(&mut self, _key: &HgPath) { |
|
941 // Do nothing, this `DirstateMap` does not have a separate "non normal |
|
942 // entries" set that need to be kept up to date |
|
943 } |
|
944 |
|
945 fn non_normal_or_other_parent_paths( |
|
946 &mut self, |
|
947 ) -> Box<dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + '_> |
|
948 { |
|
949 Box::new(self.filter_full_paths(|entry| { |
|
950 entry.is_non_normal() || entry.is_from_other_parent() |
|
951 })) |
|
952 } |
|
953 |
|
954 fn set_non_normal_other_parent_entries(&mut self, _force: bool) { |
|
955 // Do nothing, this `DirstateMap` does not have a separate "non normal |
|
956 // entries" and "from other parent" sets that need to be recomputed |
|
957 } |
|
958 |
|
959 fn iter_non_normal_paths( |
|
960 &mut self, |
|
961 ) -> Box< |
|
962 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
963 > { |
|
964 self.iter_non_normal_paths_panic() |
|
965 } |
|
966 |
|
967 fn iter_non_normal_paths_panic( |
|
968 &self, |
|
969 ) -> Box< |
|
970 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
971 > { |
|
972 Box::new(self.filter_full_paths(|entry| entry.is_non_normal())) |
|
973 } |
|
974 |
|
975 fn iter_other_parent_paths( |
|
976 &mut self, |
|
977 ) -> Box< |
|
978 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> + Send + '_, |
|
979 > { |
|
980 Box::new(self.filter_full_paths(|entry| entry.is_from_other_parent())) |
|
981 } |
|
982 |
|
983 fn has_tracked_dir( |
899 fn has_tracked_dir( |
984 &mut self, |
900 &mut self, |
985 directory: &HgPath, |
901 directory: &HgPath, |
986 ) -> Result<bool, DirstateError> { |
902 ) -> Result<bool, DirstateError> { |
987 if let Some(node) = self.get_node(directory)? { |
903 if let Some(node) = self.get_node(directory)? { |