723 new = true; |
723 new = true; |
724 DirstateEntry::new_tracked() |
724 DirstateEntry::new_tracked() |
725 }; |
725 }; |
726 node.data = NodeData::Entry(new_entry); |
726 node.data = NodeData::Entry(new_entry); |
727 Ok(new) |
727 Ok(new) |
728 } |
|
729 |
|
730 fn add_or_remove_file( |
|
731 &mut self, |
|
732 path: &HgPath, |
|
733 old_state: Option<EntryState>, |
|
734 new_entry: DirstateEntry, |
|
735 ) -> Result<(), DirstateV2ParseError> { |
|
736 let had_entry = old_state.is_some(); |
|
737 let was_tracked = old_state.map_or(false, |s| s.is_tracked()); |
|
738 let tracked_count_increment = |
|
739 match (was_tracked, new_entry.state().is_tracked()) { |
|
740 (false, true) => 1, |
|
741 (true, false) => -1, |
|
742 _ => 0, |
|
743 }; |
|
744 |
|
745 let node = Self::get_or_insert_node( |
|
746 self.on_disk, |
|
747 &mut self.unreachable_bytes, |
|
748 &mut self.root, |
|
749 path, |
|
750 WithBasename::to_cow_owned, |
|
751 |ancestor| { |
|
752 if !had_entry { |
|
753 ancestor.descendants_with_entry_count += 1; |
|
754 } |
|
755 |
|
756 // We can’t use `+= increment` because the counter is unsigned, |
|
757 // and we want debug builds to detect accidental underflow |
|
758 // through zero |
|
759 match tracked_count_increment { |
|
760 1 => ancestor.tracked_descendants_count += 1, |
|
761 -1 => ancestor.tracked_descendants_count -= 1, |
|
762 _ => {} |
|
763 } |
|
764 }, |
|
765 )?; |
|
766 if !had_entry { |
|
767 self.nodes_with_entry_count += 1 |
|
768 } |
|
769 node.data = NodeData::Entry(new_entry); |
|
770 Ok(()) |
|
771 } |
728 } |
772 |
729 |
773 /// It is the responsibility of the caller to know that there was an entry |
730 /// It is the responsibility of the caller to know that there was an entry |
774 /// there before. Does not handle the removal of copy source |
731 /// there before. Does not handle the removal of copy source |
775 fn set_untracked( |
732 fn set_untracked( |
933 entry: DirstateEntry, |
890 entry: DirstateEntry, |
934 ) -> Result<(), DirstateV2ParseError> { |
891 ) -> Result<(), DirstateV2ParseError> { |
935 self.with_dmap_mut(|map| { |
892 self.with_dmap_mut(|map| { |
936 map.get_or_insert(&filename)?.data = NodeData::Entry(entry); |
893 map.get_or_insert(&filename)?.data = NodeData::Entry(entry); |
937 Ok(()) |
894 Ok(()) |
938 }) |
|
939 } |
|
940 |
|
941 pub fn add_file( |
|
942 &mut self, |
|
943 filename: &HgPath, |
|
944 entry: DirstateEntry, |
|
945 ) -> Result<(), DirstateError> { |
|
946 let old_state = self.get(filename)?.map(|e| e.state()); |
|
947 self.with_dmap_mut(|map| { |
|
948 Ok(map.add_or_remove_file(filename, old_state, entry)?) |
|
949 }) |
895 }) |
950 } |
896 } |
951 |
897 |
952 pub fn set_tracked( |
898 pub fn set_tracked( |
953 &mut self, |
899 &mut self, |