##// END OF EJS Templates
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed...
Raphaël Gomès -
r50232:6cd24955 stable
parent child Browse files
Show More
@@ -31,6 +31,13 b' use crate::StatusOptions;'
31 31 /// anymore) is less than this fraction of the total amount of existing data.
32 32 const ACCEPTABLE_UNREACHABLE_BYTES_RATIO: f32 = 0.5;
33 33
34 #[derive(Debug, PartialEq, Eq)]
35 /// Version of the on-disk format
36 pub enum DirstateVersion {
37 V1,
38 V2,
39 }
40
34 41 pub struct DirstateMap<'on_disk> {
35 42 /// Contents of the `.hg/dirstate` file
36 43 pub(super) on_disk: &'on_disk [u8],
@@ -53,6 +60,8 b" pub struct DirstateMap<'on_disk> {"
53 60 /// Size of the data used to first load this `DirstateMap`. Used in case
54 61 /// we need to write some new metadata, but no new data on disk.
55 62 pub(super) old_data_size: usize,
63
64 pub(super) dirstate_version: DirstateVersion,
56 65 }
57 66
58 67 /// Using a plain `HgPathBuf` of the full path from the repository root as a
@@ -434,6 +443,7 b" impl<'on_disk> DirstateMap<'on_disk> {"
434 443 ignore_patterns_hash: [0; on_disk::IGNORE_PATTERNS_HASH_LEN],
435 444 unreachable_bytes: 0,
436 445 old_data_size: 0,
446 dirstate_version: DirstateVersion::V1,
437 447 }
438 448 }
439 449
@@ -3,6 +3,7 b''
3 3 //! See `mercurial/helptext/internals/dirstate-v2.txt`
4 4
5 5 use crate::dirstate::TruncatedTimestamp;
6 use crate::dirstate_tree::dirstate_map::DirstateVersion;
6 7 use crate::dirstate_tree::dirstate_map::{self, DirstateMap, NodeRef};
7 8 use crate::dirstate_tree::path_with_basename::WithBasename;
8 9 use crate::errors::HgError;
@@ -276,7 +277,9 b" pub(super) fn read<'on_disk>("
276 277 metadata: &[u8],
277 278 ) -> Result<DirstateMap<'on_disk>, DirstateV2ParseError> {
278 279 if on_disk.is_empty() {
279 return Ok(DirstateMap::empty(on_disk));
280 let mut map = DirstateMap::empty(on_disk);
281 map.dirstate_version = DirstateVersion::V2;
282 return Ok(map);
280 283 }
281 284 let (meta, _) = TreeMetadata::from_bytes(metadata)
282 285 .map_err(|_| DirstateV2ParseError)?;
@@ -291,6 +294,7 b" pub(super) fn read<'on_disk>("
291 294 ignore_patterns_hash: meta.ignore_patterns_hash,
292 295 unreachable_bytes: meta.unreachable_bytes.get(),
293 296 old_data_size: on_disk.len(),
297 dirstate_version: DirstateVersion::V2,
294 298 };
295 299 Ok(dirstate_map)
296 300 }
@@ -4,6 +4,7 b' use crate::dirstate::status::StatusPath;'
4 4 use crate::dirstate_tree::dirstate_map::BorrowedPath;
5 5 use crate::dirstate_tree::dirstate_map::ChildNodesRef;
6 6 use crate::dirstate_tree::dirstate_map::DirstateMap;
7 use crate::dirstate_tree::dirstate_map::DirstateVersion;
7 8 use crate::dirstate_tree::dirstate_map::NodeData;
8 9 use crate::dirstate_tree::dirstate_map::NodeRef;
9 10 use crate::dirstate_tree::on_disk::DirstateV2ParseError;
@@ -61,16 +62,29 b" pub fn status<'dirstate>("
61 62
62 63 let (ignore_fn, warnings, patterns_changed): (IgnoreFnType, _, _) =
63 64 if options.list_ignored || options.list_unknown {
64 let mut hasher = Sha1::new();
65 let (ignore_fn, warnings) = get_ignore_function(
66 ignore_files,
67 &root_dir,
68 &mut |pattern_bytes| hasher.update(pattern_bytes),
69 )?;
70 let new_hash = *hasher.finalize().as_ref();
71 let changed = new_hash != dmap.ignore_patterns_hash;
72 dmap.ignore_patterns_hash = new_hash;
73 (ignore_fn, warnings, Some(changed))
65 let (ignore_fn, warnings, changed) = match dmap.dirstate_version {
66 DirstateVersion::V1 => {
67 let (ignore_fn, warnings) = get_ignore_function(
68 ignore_files,
69 &root_dir,
70 &mut |_pattern_bytes| {},
71 )?;
72 (ignore_fn, warnings, None)
73 }
74 DirstateVersion::V2 => {
75 let mut hasher = Sha1::new();
76 let (ignore_fn, warnings) = get_ignore_function(
77 ignore_files,
78 &root_dir,
79 &mut |pattern_bytes| hasher.update(pattern_bytes),
80 )?;
81 let new_hash = *hasher.finalize().as_ref();
82 let changed = new_hash != dmap.ignore_patterns_hash;
83 dmap.ignore_patterns_hash = new_hash;
84 (ignore_fn, warnings, Some(changed))
85 }
86 };
87 (ignore_fn, warnings, changed)
74 88 } else {
75 89 (Box::new(|&_| true), vec![], None)
76 90 };
@@ -135,7 +149,8 b" pub fn status<'dirstate>("
135 149
136 150 outcome.dirty = common.ignore_patterns_have_changed == Some(true)
137 151 || !outdated.is_empty()
138 || !new_cachable.is_empty();
152 || (!new_cachable.is_empty()
153 && dmap.dirstate_version == DirstateVersion::V2);
139 154
140 155 // Remove outdated mtimes before adding new mtimes, in case a given
141 156 // directory is both
General Comments 0
You need to be logged in to leave comments. Login now