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