##// END OF EJS Templates
dirstate: use more than a bool to control append behavior...
marmoute -
r51116:1891086f stable
parent child Browse files
Show More
@@ -31,6 +31,9 b' else:'
31 31
32 32 rangemask = 0x7FFFFFFF
33 33
34 WRITE_MODE_AUTO = 0
35 WRITE_MODE_FORCE_NEW = 1
36
34 37
35 38 class _dirstatemapcommon:
36 39 """
@@ -609,8 +612,10 b' if rustmod is not None:'
609 612 return
610 613
611 614 # We can only append to an existing data file if there is one
612 can_append = self.docket.uuid is not None
613 packed, meta, append = self._map.write_v2(can_append)
615 write_mode = WRITE_MODE_AUTO
616 if self.docket.uuid is None:
617 write_mode = WRITE_MODE_FORCE_NEW
618 packed, meta, append = self._map.write_v2(write_mode)
614 619 if append:
615 620 docket = self.docket
616 621 data_filename = docket.data_filename()
@@ -38,6 +38,12 b' pub enum DirstateVersion {'
38 38 V2,
39 39 }
40 40
41 #[derive(Debug, PartialEq, Eq)]
42 pub enum DirstateMapWriteMode {
43 Auto,
44 ForceNewDataFile,
45 }
46
41 47 #[derive(Debug)]
42 48 pub struct DirstateMap<'on_disk> {
43 49 /// Contents of the `.hg/dirstate` file
@@ -1251,11 +1257,11 b' impl OwningDirstateMap {'
1251 1257 #[timed]
1252 1258 pub fn pack_v2(
1253 1259 &self,
1254 can_append: bool,
1260 write_mode: DirstateMapWriteMode,
1255 1261 ) -> Result<(Vec<u8>, on_disk::TreeMetadata, bool, usize), DirstateError>
1256 1262 {
1257 1263 let map = self.get_map();
1258 on_disk::write(map, can_append)
1264 on_disk::write(map, write_mode)
1259 1265 }
1260 1266
1261 1267 /// `callback` allows the caller to process and do something with the
@@ -1812,7 +1818,7 b' mod tests {'
1812 1818 )?;
1813 1819
1814 1820 let (packed, metadata, _should_append, _old_data_size) =
1815 map.pack_v2(false)?;
1821 map.pack_v2(DirstateMapWriteMode::ForceNewDataFile)?;
1816 1822 let packed_len = packed.len();
1817 1823 assert!(packed_len > 0);
1818 1824
@@ -4,7 +4,9 b''
4 4
5 5 use crate::dirstate::{DirstateV2Data, TruncatedTimestamp};
6 6 use crate::dirstate_tree::dirstate_map::DirstateVersion;
7 use crate::dirstate_tree::dirstate_map::{self, DirstateMap, NodeRef};
7 use crate::dirstate_tree::dirstate_map::{
8 self, DirstateMap, DirstateMapWriteMode, NodeRef,
9 };
8 10 use crate::dirstate_tree::path_with_basename::WithBasename;
9 11 use crate::errors::HgError;
10 12 use crate::utils::hg_path::HgPath;
@@ -634,9 +636,12 b" pub(crate) fn for_each_tracked_path<'on_"
634 636 /// (false), and the previous size of data on disk.
635 637 pub(super) fn write(
636 638 dirstate_map: &DirstateMap,
637 can_append: bool,
639 write_mode: DirstateMapWriteMode,
638 640 ) -> Result<(Vec<u8>, TreeMetadata, bool, usize), DirstateError> {
639 let append = can_append && dirstate_map.write_should_append();
641 let append = match write_mode {
642 DirstateMapWriteMode::Auto => dirstate_map.write_should_append(),
643 DirstateMapWriteMode::ForceNewDataFile => false,
644 };
640 645 if append {
641 646 log::trace!("appending to the dirstate data file");
642 647 } else {
@@ -1,6 +1,7 b''
1 1 use crate::changelog::Changelog;
2 2 use crate::config::{Config, ConfigError, ConfigParseError};
3 3 use crate::dirstate::DirstateParents;
4 use crate::dirstate_tree::dirstate_map::DirstateMapWriteMode;
4 5 use crate::dirstate_tree::on_disk::Docket as DirstateDocket;
5 6 use crate::dirstate_tree::owning::OwningDirstateMap;
6 7 use crate::errors::HgResultExt;
@@ -436,9 +437,13 b' impl Repo {'
436 437 .dirstate_data_file_uuid
437 438 .get_or_init(|| self.read_dirstate_data_file_uuid())?;
438 439 let uuid_opt = uuid_opt.as_ref();
439 let can_append = uuid_opt.is_some();
440 let write_mode = if uuid_opt.is_some() {
441 DirstateMapWriteMode::Auto
442 } else {
443 DirstateMapWriteMode::ForceNewDataFile
444 };
440 445 let (data, tree_metadata, append, old_data_size) =
441 map.pack_v2(can_append)?;
446 map.pack_v2(write_mode)?;
442 447
443 448 // Reuse the uuid, or generate a new one, keeping the old for
444 449 // deletion.
@@ -23,7 +23,8 b' use crate::{'
23 23 pybytes_deref::PyBytesDeref,
24 24 };
25 25 use hg::{
26 dirstate::StateMapIter, dirstate_tree::on_disk::DirstateV2ParseError,
26 dirstate::StateMapIter, dirstate_tree::dirstate_map::DirstateMapWriteMode,
27 dirstate_tree::on_disk::DirstateV2ParseError,
27 28 dirstate_tree::owning::OwningDirstateMap, revlog::Node,
28 29 utils::files::normalize_case, utils::hg_path::HgPath, DirstateEntry,
29 30 DirstateError, DirstateParents,
@@ -247,10 +248,15 b' py_class!(pub class DirstateMap |py| {'
247 248 /// instead of written to a new data file (False).
248 249 def write_v2(
249 250 &self,
250 can_append: bool,
251 write_mode: usize,
251 252 ) -> PyResult<PyObject> {
252 253 let inner = self.inner(py).borrow();
253 let result = inner.pack_v2(can_append);
254 let rust_write_mode = match write_mode {
255 0 => DirstateMapWriteMode::Auto,
256 1 => DirstateMapWriteMode::ForceNewDataFile,
257 _ => DirstateMapWriteMode::Auto, // XXX should we error out?
258 };
259 let result = inner.pack_v2(rust_write_mode);
254 260 match result {
255 261 Ok((packed, tree_metadata, append, _old_data_size)) => {
256 262 let packed = PyBytes::new(py, &packed);
General Comments 0
You need to be logged in to leave comments. Login now