Mercurial > hg
changeset 48045:32ef647821b2
dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Now that the `DirstateItem` python class is implemented in Rust containing
a `DirstateEntry` value, use that value directly instead of reconstructing
it from v1 data.
Also rename from `set_v1` since dirstate-v1 data is not used anymore.
Differential Revision: https://phab.mercurial-scm.org/D11487
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 22 Sep 2021 18:21:58 +0200 |
parents | d5528ac9b4f2 |
children | f6d0a89fdf80 |
files | mercurial/dirstatemap.py rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-core/src/dirstate_tree/dirstate_map.rs rust/hg-core/src/dirstate_tree/dispatch.rs rust/hg-core/src/dirstate_tree/owning_dispatch.rs rust/hg-cpython/src/dirstate/dirstate_map.rs rust/hg-cpython/src/dirstate/item.rs |
diffstat | 7 files changed, 23 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstatemap.py Wed Sep 22 11:33:29 2021 +0200 +++ b/mercurial/dirstatemap.py Wed Sep 22 18:21:58 2021 +0200 @@ -664,7 +664,7 @@ new = True elif not entry.tracked: entry.set_tracked() - self._rustmap.set_v1(filename, entry) + self._rustmap.set_dirstate_item(filename, entry) new = True else: # XXX This is probably overkill for more case, but we need this to @@ -949,7 +949,7 @@ """record that the current state of the file on disk is unknown""" entry = self[filename] entry.set_possibly_dirty() - self._rustmap.set_v1(filename, entry) + self._rustmap.set_dirstate_item(filename, entry) def set_clean(self, filename, mode, size, mtime): """mark a file as back to a clean state""" @@ -957,9 +957,9 @@ mtime = mtime & rangemask size = size & rangemask entry.set_clean(mode, size, mtime) - self._rustmap.set_v1(filename, entry) + self._rustmap.set_dirstate_item(filename, entry) self._rustmap.copymap().pop(filename, None) def __setitem__(self, key, value): assert isinstance(value, DirstateItem) - self._rustmap.set_v1(key, value) + self._rustmap.set_dirstate_item(key, value)
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Wed Sep 22 11:33:29 2021 +0200 +++ b/rust/hg-core/src/dirstate/dirstate_map.rs Wed Sep 22 18:21:58 2021 +0200 @@ -64,7 +64,7 @@ self.other_parent_set = None; } - pub fn set_v1_inner(&mut self, filename: &HgPath, entry: DirstateEntry) { + pub fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { self.state_map.insert(filename.to_owned(), entry); }
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Wed Sep 22 11:33:29 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Wed Sep 22 18:21:58 2021 +0200 @@ -758,7 +758,7 @@ self.nodes_with_copy_source_count = 0; } - fn set_v1(&mut self, filename: &HgPath, entry: DirstateEntry) { + fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { let node = self.get_or_insert(&filename).expect("no parse error in v1"); node.data = NodeData::Entry(entry);
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs Wed Sep 22 11:33:29 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/dispatch.rs Wed Sep 22 18:21:58 2021 +0200 @@ -37,7 +37,9 @@ /// Remove information about all files in this map fn clear(&mut self); - fn set_v1(&mut self, filename: &HgPath, entry: DirstateEntry); + /// Add the given filename to the map if it is not already there, and + /// associate the given entry with it. + fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry); /// Add or change the information associated to a given file. /// @@ -319,8 +321,8 @@ /// /// XXX Is temporary during a refactor of V1 dirstate and will disappear /// shortly. - fn set_v1(&mut self, filename: &HgPath, entry: DirstateEntry) { - self.set_v1_inner(&filename, entry) + fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { + self.set_entry(&filename, entry) } fn add_file(
--- a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs Wed Sep 22 11:33:29 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs Wed Sep 22 18:21:58 2021 +0200 @@ -20,8 +20,8 @@ self.get_mut().clear() } - fn set_v1(&mut self, filename: &HgPath, entry: DirstateEntry) { - self.get_mut().set_v1(filename, entry) + fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { + self.get_mut().set_entry(filename, entry) } fn add_file(
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Wed Sep 22 11:33:29 2021 +0200 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Wed Sep 22 18:21:58 2021 +0200 @@ -129,18 +129,14 @@ } } - def set_v1(&self, path: PyObject, item: PyObject) -> PyResult<PyObject> { + def set_dirstate_item( + &self, + path: PyObject, + item: DirstateItem + ) -> PyResult<PyObject> { let f = path.extract::<PyBytes>(py)?; let filename = HgPath::new(f.data(py)); - let state = item.getattr(py, "state")?.extract::<PyBytes>(py)?; - let state = state.data(py)[0]; - let entry = DirstateEntry::from_v1_data( - state.try_into().expect("state is always valid"), - item.getattr(py, "mode")?.extract(py)?, - item.getattr(py, "size")?.extract(py)?, - item.getattr(py, "mtime")?.extract(py)?, - ); - self.inner(py).borrow_mut().set_v1(filename, entry); + self.inner(py).borrow_mut().set_entry(filename, item.get_entry(py)); Ok(py.None()) }
--- a/rust/hg-cpython/src/dirstate/item.rs Wed Sep 22 11:33:29 2021 +0200 +++ b/rust/hg-cpython/src/dirstate/item.rs Wed Sep 22 18:21:58 2021 +0200 @@ -180,6 +180,10 @@ Ok(DirstateItem::create_instance(py, Cell::new(entry))?.into_object()) } + pub fn get_entry(&self, py: Python<'_>) -> DirstateEntry { + self.entry(py).get() + } + // TODO: Use https://doc.rust-lang.org/std/cell/struct.Cell.html#method.update instead when it’s stable pub fn update(&self, py: Python<'_>, f: impl FnOnce(&mut DirstateEntry)) { let mut entry = self.entry(py).get();