Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
47329:717a94b423b9 | 47330:73f23e7610f8 |
---|---|
124 } | 124 } |
125 | 125 |
126 /// Seconds since the Unix epoch | 126 /// Seconds since the Unix epoch |
127 pub struct Timestamp(pub u64); | 127 pub struct Timestamp(pub u64); |
128 | 128 |
129 pub fn clear_ambiguous_mtime( | 129 impl DirstateEntry { |
130 entry: &mut DirstateEntry, | 130 pub fn mtime_is_ambiguous(&self, now: i32) -> bool { |
131 mtime_now: i32, | 131 self.state == EntryState::Normal && self.mtime == now |
132 ) -> bool { | 132 } |
133 let ambiguous = | 133 |
134 entry.state == EntryState::Normal && entry.mtime == mtime_now; | 134 pub fn clear_ambiguous_mtime(&mut self, now: i32) -> bool { |
135 if ambiguous { | 135 let ambiguous = self.mtime_is_ambiguous(now); |
136 // The file was last modified "simultaneously" with the current | 136 if ambiguous { |
137 // write to dirstate (i.e. within the same second for file- | 137 // The file was last modified "simultaneously" with the current |
138 // systems with a granularity of 1 sec). This commonly happens | 138 // write to dirstate (i.e. within the same second for file- |
139 // for at least a couple of files on 'update'. | 139 // systems with a granularity of 1 sec). This commonly happens |
140 // The user could change the file without changing its size | 140 // for at least a couple of files on 'update'. |
141 // within the same second. Invalidate the file's mtime in | 141 // The user could change the file without changing its size |
142 // dirstate, forcing future 'status' calls to compare the | 142 // within the same second. Invalidate the file's mtime in |
143 // contents of the file if the size is the same. This prevents | 143 // dirstate, forcing future 'status' calls to compare the |
144 // mistakenly treating such files as clean. | 144 // contents of the file if the size is the same. This prevents |
145 entry.mtime = -1; | 145 // mistakenly treating such files as clean. |
146 } | 146 self.clear_mtime() |
147 ambiguous | 147 } |
148 ambiguous | |
149 } | |
150 | |
151 pub fn clear_mtime(&mut self) { | |
152 self.mtime = -1; | |
153 } | |
148 } | 154 } |
149 | 155 |
150 pub fn pack_dirstate( | 156 pub fn pack_dirstate( |
151 state_map: &mut StateMap, | 157 state_map: &mut StateMap, |
152 copy_map: &CopyMap, | 158 copy_map: &CopyMap, |
168 | 174 |
169 packed.extend(parents.p1.as_bytes()); | 175 packed.extend(parents.p1.as_bytes()); |
170 packed.extend(parents.p2.as_bytes()); | 176 packed.extend(parents.p2.as_bytes()); |
171 | 177 |
172 for (filename, entry) in state_map.iter_mut() { | 178 for (filename, entry) in state_map.iter_mut() { |
173 clear_ambiguous_mtime(entry, now); | 179 entry.clear_ambiguous_mtime(now); |
174 pack_entry( | 180 pack_entry( |
175 filename, | 181 filename, |
176 entry, | 182 entry, |
177 copy_map.get(filename).map(|p| &**p), | 183 copy_map.get(filename).map(|p| &**p), |
178 &mut packed, | 184 &mut packed, |