675 None |
675 None |
676 } |
676 } |
677 }) |
677 }) |
678 } |
678 } |
679 |
679 |
680 fn clear_known_ambiguous_mtimes( |
|
681 &mut self, |
|
682 paths: &[impl AsRef<HgPath>], |
|
683 ) -> Result<(), DirstateV2ParseError> { |
|
684 for path in paths { |
|
685 if let Some(node) = Self::get_node_mut( |
|
686 self.on_disk, |
|
687 &mut self.unreachable_bytes, |
|
688 &mut self.root, |
|
689 path.as_ref(), |
|
690 )? { |
|
691 if let NodeData::Entry(entry) = &mut node.data { |
|
692 entry.set_possibly_dirty(); |
|
693 } |
|
694 } |
|
695 } |
|
696 Ok(()) |
|
697 } |
|
698 |
|
699 fn count_dropped_path(unreachable_bytes: &mut u32, path: &Cow<HgPath>) { |
680 fn count_dropped_path(unreachable_bytes: &mut u32, path: &Cow<HgPath>) { |
700 if let Cow::Borrowed(path) = path { |
681 if let Cow::Borrowed(path) = path { |
701 *unreachable_bytes += path.len() as u32 |
682 *unreachable_bytes += path.len() as u32 |
702 } |
683 } |
703 } |
684 } |
928 |
909 |
929 #[timed] |
910 #[timed] |
930 pub fn pack_v1( |
911 pub fn pack_v1( |
931 &mut self, |
912 &mut self, |
932 parents: DirstateParents, |
913 parents: DirstateParents, |
933 now: TruncatedTimestamp, |
|
934 ) -> Result<Vec<u8>, DirstateError> { |
914 ) -> Result<Vec<u8>, DirstateError> { |
935 let map = self.get_map_mut(); |
915 let map = self.get_map_mut(); |
936 let mut ambiguous_mtimes = Vec::new(); |
|
937 // Optizimation (to be measured?): pre-compute size to avoid `Vec` |
916 // Optizimation (to be measured?): pre-compute size to avoid `Vec` |
938 // reallocations |
917 // reallocations |
939 let mut size = parents.as_bytes().len(); |
918 let mut size = parents.as_bytes().len(); |
940 for node in map.iter_nodes() { |
919 for node in map.iter_nodes() { |
941 let node = node?; |
920 let node = node?; |
942 if let Some(entry) = node.entry()? { |
921 if node.entry()?.is_some() { |
943 size += packed_entry_size( |
922 size += packed_entry_size( |
944 node.full_path(map.on_disk)?, |
923 node.full_path(map.on_disk)?, |
945 node.copy_source(map.on_disk)?, |
924 node.copy_source(map.on_disk)?, |
946 ); |
925 ); |
947 if entry.need_delay(now) { |
926 } |
948 ambiguous_mtimes.push( |
927 } |
949 node.full_path_borrowed(map.on_disk)? |
|
950 .detach_from_tree(), |
|
951 ) |
|
952 } |
|
953 } |
|
954 } |
|
955 map.clear_known_ambiguous_mtimes(&ambiguous_mtimes)?; |
|
956 |
928 |
957 let mut packed = Vec::with_capacity(size); |
929 let mut packed = Vec::with_capacity(size); |
958 packed.extend(parents.as_bytes()); |
930 packed.extend(parents.as_bytes()); |
959 |
931 |
960 for node in map.iter_nodes() { |
932 for node in map.iter_nodes() { |
976 /// `map.on_disk` (true), instead of written to a new data file |
948 /// `map.on_disk` (true), instead of written to a new data file |
977 /// (false). |
949 /// (false). |
978 #[timed] |
950 #[timed] |
979 pub fn pack_v2( |
951 pub fn pack_v2( |
980 &mut self, |
952 &mut self, |
981 now: TruncatedTimestamp, |
|
982 can_append: bool, |
953 can_append: bool, |
983 ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> { |
954 ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> { |
984 let map = self.get_map_mut(); |
955 let map = self.get_map_mut(); |
985 let mut paths = Vec::new(); |
|
986 for node in map.iter_nodes() { |
|
987 let node = node?; |
|
988 if let Some(entry) = node.entry()? { |
|
989 if entry.need_delay(now) { |
|
990 paths.push( |
|
991 node.full_path_borrowed(map.on_disk)? |
|
992 .detach_from_tree(), |
|
993 ) |
|
994 } |
|
995 } |
|
996 } |
|
997 // Borrow of `self` ends here since we collect cloned paths |
|
998 |
|
999 map.clear_known_ambiguous_mtimes(&paths)?; |
|
1000 |
|
1001 on_disk::write(map, can_append) |
956 on_disk::write(map, can_append) |
1002 } |
957 } |
1003 |
958 |
1004 pub fn status<'a>( |
959 pub fn status<'a>( |
1005 &'a mut self, |
960 &'a mut self, |