Mercurial > hg
diff rust/hg-core/src/dirstate/parsers.rs @ 47330:73f23e7610f8
dirstate-tree: Remove DirstateMap::iter_node_data_mut
In an upcoming changeset we want DirstateMap to be able to work directly
with nodes in their "on disk" representation, without always allocating
corresponding in-memory data structures. Nodes would have two possible
representations: one immutable "on disk" refering to the bytes buffer
of the contents of the .hg/dirstate file, and one mutable with HashMap
like the curren data structure.
These nodes would have copy-on-write semantics: when an immutable node
would need to be mutated, instead we allocate new mutable node for it and
its ancestors.
A mutable iterator of the entire tree would still be possible, but it would
become much more expensive since we’d need to allocate mutable nodes for
everything.
Instead, remove this iterator. It was only used to clear ambiguous mtimes
while serializing the `DirstateMap`. Instead clearing and serialization are
now two separate passes. Clearing first uses an immutable iterator to collect
the paths of nodes that need to be cleared, then accesses only those nodes
mutably.
Differential Revision: https://phab.mercurial-scm.org/D10744
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 19 May 2021 13:15:00 +0200 |
parents | cd8ca38fccff |
children | ed1583a845d2 |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/parsers.rs Fri May 28 17:33:20 2021 -0400 +++ b/rust/hg-core/src/dirstate/parsers.rs Wed May 19 13:15:00 2021 +0200 @@ -126,25 +126,31 @@ /// Seconds since the Unix epoch pub struct Timestamp(pub u64); -pub fn clear_ambiguous_mtime( - entry: &mut DirstateEntry, - mtime_now: i32, -) -> bool { - let ambiguous = - entry.state == EntryState::Normal && entry.mtime == mtime_now; - if ambiguous { - // The file was last modified "simultaneously" with the current - // write to dirstate (i.e. within the same second for file- - // systems with a granularity of 1 sec). This commonly happens - // for at least a couple of files on 'update'. - // The user could change the file without changing its size - // within the same second. Invalidate the file's mtime in - // dirstate, forcing future 'status' calls to compare the - // contents of the file if the size is the same. This prevents - // mistakenly treating such files as clean. - entry.mtime = -1; +impl DirstateEntry { + pub fn mtime_is_ambiguous(&self, now: i32) -> bool { + self.state == EntryState::Normal && self.mtime == now } - ambiguous + + pub fn clear_ambiguous_mtime(&mut self, now: i32) -> bool { + let ambiguous = self.mtime_is_ambiguous(now); + if ambiguous { + // The file was last modified "simultaneously" with the current + // write to dirstate (i.e. within the same second for file- + // systems with a granularity of 1 sec). This commonly happens + // for at least a couple of files on 'update'. + // The user could change the file without changing its size + // within the same second. Invalidate the file's mtime in + // dirstate, forcing future 'status' calls to compare the + // contents of the file if the size is the same. This prevents + // mistakenly treating such files as clean. + self.clear_mtime() + } + ambiguous + } + + pub fn clear_mtime(&mut self) { + self.mtime = -1; + } } pub fn pack_dirstate( @@ -170,7 +176,7 @@ packed.extend(parents.p2.as_bytes()); for (filename, entry) in state_map.iter_mut() { - clear_ambiguous_mtime(entry, now); + entry.clear_ambiguous_mtime(now); pack_entry( filename, entry,