comparison rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 48260:269ff8978086

dirstate: store mtimes with nanosecond precision in memory Keep integer seconds since the Unix epoch, together with integer nanoseconds in the `0 <= n < 1e9` range. For now, nanoseconds are still always zero. This commit is about data structure changes. Differential Revision: https://phab.mercurial-scm.org/D11684
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 18 Oct 2021 11:23:07 +0200
parents c591944f42c1
children 434de12918fd
comparison
equal deleted inserted replaced
48259:84f6b0c41b90 48260:269ff8978086
1 use bytes_cast::BytesCast; 1 use bytes_cast::BytesCast;
2 use micro_timer::timed; 2 use micro_timer::timed;
3 use std::borrow::Cow; 3 use std::borrow::Cow;
4 use std::convert::TryInto;
5 use std::path::PathBuf; 4 use std::path::PathBuf;
6 5
7 use super::on_disk; 6 use super::on_disk;
8 use super::on_disk::DirstateV2ParseError; 7 use super::on_disk::DirstateV2ParseError;
9 use super::owning::OwningDirstateMap; 8 use super::owning::OwningDirstateMap;
10 use super::path_with_basename::WithBasename; 9 use super::path_with_basename::WithBasename;
11 use crate::dirstate::parsers::pack_entry; 10 use crate::dirstate::parsers::pack_entry;
12 use crate::dirstate::parsers::packed_entry_size; 11 use crate::dirstate::parsers::packed_entry_size;
13 use crate::dirstate::parsers::parse_dirstate_entries; 12 use crate::dirstate::parsers::parse_dirstate_entries;
14 use crate::dirstate::parsers::Timestamp;
15 use crate::dirstate::CopyMapIter; 13 use crate::dirstate::CopyMapIter;
16 use crate::dirstate::StateMapIter; 14 use crate::dirstate::StateMapIter;
17 use crate::dirstate::TruncatedTimestamp; 15 use crate::dirstate::TruncatedTimestamp;
18 use crate::dirstate::SIZE_FROM_OTHER_PARENT; 16 use crate::dirstate::SIZE_FROM_OTHER_PARENT;
19 use crate::dirstate::SIZE_NON_NORMAL; 17 use crate::dirstate::SIZE_NON_NORMAL;
930 928
931 #[timed] 929 #[timed]
932 pub fn pack_v1( 930 pub fn pack_v1(
933 &mut self, 931 &mut self,
934 parents: DirstateParents, 932 parents: DirstateParents,
935 now: Timestamp, 933 now: TruncatedTimestamp,
936 ) -> Result<Vec<u8>, DirstateError> { 934 ) -> Result<Vec<u8>, DirstateError> {
937 let map = self.get_map_mut(); 935 let map = self.get_map_mut();
938 let now: i32 = now.0.try_into().expect("time overflow");
939 let mut ambiguous_mtimes = Vec::new(); 936 let mut ambiguous_mtimes = Vec::new();
940 // Optizimation (to be measured?): pre-compute size to avoid `Vec` 937 // Optizimation (to be measured?): pre-compute size to avoid `Vec`
941 // reallocations 938 // reallocations
942 let mut size = parents.as_bytes().len(); 939 let mut size = parents.as_bytes().len();
943 for node in map.iter_nodes() { 940 for node in map.iter_nodes() {
979 /// `map.on_disk` (true), instead of written to a new data file 976 /// `map.on_disk` (true), instead of written to a new data file
980 /// (false). 977 /// (false).
981 #[timed] 978 #[timed]
982 pub fn pack_v2( 979 pub fn pack_v2(
983 &mut self, 980 &mut self,
984 now: Timestamp, 981 now: TruncatedTimestamp,
985 can_append: bool, 982 can_append: bool,
986 ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> { 983 ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> {
987 let map = self.get_map_mut(); 984 let map = self.get_map_mut();
988 // TODO: how do we want to handle this in 2038?
989 let now: i32 = now.0.try_into().expect("time overflow");
990 let mut paths = Vec::new(); 985 let mut paths = Vec::new();
991 for node in map.iter_nodes() { 986 for node in map.iter_nodes() {
992 let node = node?; 987 let node = node?;
993 if let Some(entry) = node.entry()? { 988 if let Some(entry) = node.entry()? {
994 if entry.need_delay(now) { 989 if entry.need_delay(now) {