comparison rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47678:065e61628980

dirstate-v2: Support appending to the same data file For now we’re still writing the entire data every time, so appending is not useful yet. Later we’ll have new nodes pointing to some existing data for nodes and paths that haven’t changed. The decision whether to append is pseudo-random in order to make tests exercise both code paths. This will be replaced by a heuristic based on the amount of unused existing data. Differential Revision: https://phab.mercurial-scm.org/D11094
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 13 Jul 2021 17:18:23 +0200
parents 48aec076b8fb
children d94118365ec5
comparison
equal deleted inserted replaced
47677:da1c0cd68d53 47678:065e61628980
464 }, 464 },
465 )?; 465 )?;
466 let parents = Some(parents.clone()); 466 let parents = Some(parents.clone());
467 467
468 Ok((map, parents)) 468 Ok((map, parents))
469 }
470
471 /// Assuming dirstate-v2 format, returns whether the next write should
472 /// append to the existing data file that contains `self.on_disk` (true),
473 /// or create a new data file from scratch (false).
474 pub(super) fn write_should_append(&self) -> bool {
475 // Soon this will be a heuristic based on the amount of unreachable
476 // data. For now it’s pseudo-random in order to make tests exercise
477 // both code paths.
478
479 fn bad_rng() -> u32 {
480 std::time::SystemTime::now()
481 .duration_since(std::time::UNIX_EPOCH)
482 .unwrap()
483 .subsec_millis()
484 }
485
486 bad_rng() % 2 == 0
469 } 487 }
470 488
471 fn get_node<'tree>( 489 fn get_node<'tree>(
472 &'tree self, 490 &'tree self,
473 path: &HgPath, 491 path: &HgPath,
1041 } 1059 }
1042 } 1060 }
1043 Ok(packed) 1061 Ok(packed)
1044 } 1062 }
1045 1063
1064 /// Returns new data together with whether that data should be appended to
1065 /// the existing data file whose content is at `self.on_disk` (true),
1066 /// instead of written to a new data file (false).
1046 #[timed] 1067 #[timed]
1047 fn pack_v2(&mut self, now: Timestamp) -> Result<Vec<u8>, DirstateError> { 1068 fn pack_v2(
1069 &mut self,
1070 now: Timestamp,
1071 can_append: bool,
1072 ) -> Result<(Vec<u8>, bool), DirstateError> {
1048 // TODO: how do we want to handle this in 2038? 1073 // TODO: how do we want to handle this in 2038?
1049 let now: i32 = now.0.try_into().expect("time overflow"); 1074 let now: i32 = now.0.try_into().expect("time overflow");
1050 let mut paths = Vec::new(); 1075 let mut paths = Vec::new();
1051 for node in self.iter_nodes() { 1076 for node in self.iter_nodes() {
1052 let node = node?; 1077 let node = node?;
1061 } 1086 }
1062 // Borrow of `self` ends here since we collect cloned paths 1087 // Borrow of `self` ends here since we collect cloned paths
1063 1088
1064 self.clear_known_ambiguous_mtimes(&paths)?; 1089 self.clear_known_ambiguous_mtimes(&paths)?;
1065 1090
1066 on_disk::write(self) 1091 on_disk::write(self, can_append)
1067 } 1092 }
1068 1093
1069 fn status<'a>( 1094 fn status<'a>(
1070 &'a mut self, 1095 &'a mut self,
1071 matcher: &'a (dyn Matcher + Sync), 1096 matcher: &'a (dyn Matcher + Sync),