##// END OF EJS Templates
rhg: remember the inode of .hg/dirstate...
rhg: remember the inode of .hg/dirstate This allows us to detect changes of `.hg/dirstate`, which is either the full dirstate (in dirstate-v1) or the docket file (v2) without relying on data inside the file. It only works on UNIX systems. This fixes a race condition for dirstate-v1 (as demonstrated by the test changes) and adds a confortable layer of sanity for dirstate-v2.

File last commit:

r51140:dbe09fb0 stable
r51140:dbe09fb0 stable
Show More
owning.rs
106 lines | 2.5 KiB | application/rls-services+xml | RustLexer
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 use crate::{DirstateError, DirstateParents};
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 use super::dirstate_map::DirstateMap;
use std::ops::Deref;
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 use ouroboros::self_referencing;
Raphaël Gomès
rust: explain why the current `OwningDirstateMap` is unsound...
r49863
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 /// Keep a `DirstateMap<'on_disk>` next to the `on_disk` buffer that it
/// borrows.
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 #[self_referencing]
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 pub struct OwningDirstateMap {
on_disk: Box<dyn Deref<Target = [u8]> + Send>,
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 #[borrows(on_disk)]
#[covariant]
map: DirstateMap<'this>,
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 }
impl OwningDirstateMap {
pub fn new_empty<OnDisk>(on_disk: OnDisk) -> Self
where
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 OnDisk: Deref<Target = [u8]> + Send + 'static,
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 {
let on_disk = Box::new(on_disk);
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 OwningDirstateMapBuilder {
on_disk,
map_builder: |bytes| DirstateMap::empty(&bytes),
}
.build()
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 }
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 pub fn new_v1<OnDisk>(
on_disk: OnDisk,
Raphaël Gomès
rhg: remember the inode of .hg/dirstate...
r51140 identity: Option<u64>,
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 ) -> Result<(Self, DirstateParents), DirstateError>
where
OnDisk: Deref<Target = [u8]> + Send + 'static,
{
let on_disk = Box::new(on_disk);
let mut parents = DirstateParents::NULL;
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 Ok((
OwningDirstateMapTryBuilder {
on_disk,
map_builder: |bytes| {
Raphaël Gomès
rhg: remember the inode of .hg/dirstate...
r51140 DirstateMap::new_v1(&bytes, identity).map(|(dmap, p)| {
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 parents = p.unwrap_or(DirstateParents::NULL);
dmap
})
},
}
.try_build()?,
parents,
))
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 }
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 pub fn new_v2<OnDisk>(
on_disk: OnDisk,
data_size: usize,
metadata: &[u8],
Raphaël Gomès
rust-dirstate: remember the data file uuid dirstate was loaded with...
r51138 uuid: Vec<u8>,
Raphaël Gomès
rhg: remember the inode of .hg/dirstate...
r51140 identity: Option<u64>,
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 ) -> Result<Self, DirstateError>
where
OnDisk: Deref<Target = [u8]> + Send + 'static,
{
let on_disk = Box::new(on_disk);
OwningDirstateMapTryBuilder {
on_disk,
map_builder: |bytes| {
Raphaël Gomès
rhg: remember the inode of .hg/dirstate...
r51140 DirstateMap::new_v2(
&bytes, data_size, metadata, uuid, identity,
)
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 },
}
.try_build()
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 }
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 pub fn with_dmap_mut<R>(
&mut self,
f: impl FnOnce(&mut DirstateMap) -> R,
) -> R {
self.with_map_mut(f)
}
pub fn get_map(&self) -> &DirstateMap {
self.borrow_map()
}
pub fn on_disk(&self) -> &[u8] {
self.borrow_on_disk()
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 }
Raphaël Gomès
rust-dirstate: remember the data file uuid dirstate was loaded with...
r51138
pub fn old_uuid(&self) -> Option<&[u8]> {
self.get_map().old_uuid.as_deref()
}
Raphaël Gomès
rhg: remember the inode of .hg/dirstate...
r51140 pub fn old_identity(&self) -> Option<u64> {
self.get_map().identity
}
Raphaël Gomès
rust-dirstate: remember the data file uuid dirstate was loaded with...
r51138 pub fn old_data_size(&self) -> usize {
self.get_map().old_data_size
}
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 }