comparison rust/hg-core/src/repo.rs @ 48069:3d0a9c6e614d

dirstate: Remove the Rust abstraction DirstateMapMethods This Rust trait used to exist in order to allow the DirstateMap class exposed to Python to be backed by either of two implementations: one similar to the Python implementation based on a "flat" `HashMap<HgPathBuf, DirstateEntry>`, and the newer one based on a tree of nodes matching the directory structure of tracked files. A boxed trait object was used with dynamic dispatch. With the flat implementation removed and only the tree one remaining, this abstraction is not useful anymore and the concrete type can be stored directly. It remains that the trait was implemented separately for `DirstateMap<'_>` (which takes a lifetime parameter) and `OwningDirstateMap` (whose job is to wrap the former and hide the lifetime parameter), with the latter impl only forwarding calls. This changeset also removes this forwarding. Instead, the methods formerly of the `DirstateMapMethods` trait are now inherent methods implemented for `OwningDirstateMap` (where they will actually be used) but in the module that defines `DirstateMap`. This unusual setup gives access to the private fields of `DirstateMap` from those methods. Differential Revision: https://phab.mercurial-scm.org/D11517
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 27 Sep 2021 13:52:49 +0200
parents d1d9510f73f0
children 005ae1a343f8
comparison
equal deleted inserted replaced
48068:bf8837e3d7ce 48069:3d0a9c6e614d
292 { 292 {
293 OwningDirstateMap::new_empty(data_mmap) 293 OwningDirstateMap::new_empty(data_mmap)
294 } else { 294 } else {
295 OwningDirstateMap::new_empty(Vec::new()) 295 OwningDirstateMap::new_empty(Vec::new())
296 }; 296 };
297 let (on_disk, placeholder) = map.get_mut_pair(); 297 let (on_disk, placeholder) = map.get_pair_mut();
298 *placeholder = DirstateMap::new_v2(on_disk, data_size, metadata)?; 298 *placeholder = DirstateMap::new_v2(on_disk, data_size, metadata)?;
299 Ok(map) 299 Ok(map)
300 } else { 300 } else {
301 let mut map = OwningDirstateMap::new_empty(dirstate_file_contents); 301 let mut map = OwningDirstateMap::new_empty(dirstate_file_contents);
302 let (on_disk, placeholder) = map.get_mut_pair(); 302 let (on_disk, placeholder) = map.get_pair_mut();
303 let (inner, parents) = DirstateMap::new_v1(on_disk)?; 303 let (inner, parents) = DirstateMap::new_v1(on_disk)?;
304 self.dirstate_parents 304 self.dirstate_parents
305 .set(Some(parents.unwrap_or(DirstateParents::NULL))); 305 .set(Some(parents.unwrap_or(DirstateParents::NULL)));
306 *placeholder = inner; 306 *placeholder = inner;
307 Ok(map) 307 Ok(map)