##// END OF EJS Templates
transaction: actually delete file created during the transaction on rollback...
transaction: actually delete file created during the transaction on rollback Transaction currently has two modes: - one where file created during the transaction are deleted on rollback, - one where file created during the transaction are truncated to 0 on rollback. Before this change, `hg rollback` and `hg recover` are using the "delete" mode and transaction abort is using the "truncate" option. This difference is never really explained. A long time ago, there was two code paths, with this divergence existing for unclear reasons. When the two code paths got merged into a single one, a boolean argument have been added to preserve this divergence, mostly probably as a cargo cult. The divergence is weird and induce bad surprises, and the truncate behavior is a bit odds, introducing other bad surprises (e.g. 08ecbdba186f) So solve this, we stop using the "truncate" behavior and unify on the "delete" behavior. Despite being currently more "common", the truncate behavior seems less natural, resulting in the transaction leaving empty file around. This is landed on default, early in the cycle, to help us catch problems that could emerge.

File last commit:

r51575:2cc5de26 default
r51703:5c3d0795 default
Show More
owning.rs
91 lines | 2.3 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;
Raphaël Gomès
rust-hg-core: move from `ouroboros` to `self_cell`...
r51575 use self_cell::self_cell;
Simon Sapin
rust: Make OwningDirstateMap generic and move it into hg-core...
r48766 use std::ops::Deref;
Raphaël Gomès
rust-hg-core: move from `ouroboros` to `self_cell`...
r51575 self_cell!(
/// Keep a `DirstateMap<'owner>` next to the `owner` buffer that it
/// borrows.
pub struct OwningDirstateMap {
owner: Box<dyn Deref<Target = [u8]> + Send>,
#[covariant]
dependent: DirstateMap,
}
);
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-hg-core: move from `ouroboros` to `self_cell`...
r51575 OwningDirstateMap::new(on_disk, |bytes| DirstateMap::empty(bytes))
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((
Raphaël Gomès
rust-hg-core: move from `ouroboros` to `self_cell`...
r51575 OwningDirstateMap::try_new(on_disk, |bytes| {
DirstateMap::new_v1(bytes, identity).map(|(dmap, p)| {
parents = p.unwrap_or(DirstateParents::NULL);
dmap
})
})?,
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 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);
Raphaël Gomès
rust-hg-core: move from `ouroboros` to `self_cell`...
r51575 OwningDirstateMap::try_new(on_disk, |bytes| {
DirstateMap::new_v2(bytes, data_size, metadata, uuid, identity)
})
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 {
Raphaël Gomès
rust-hg-core: move from `ouroboros` to `self_cell`...
r51575 self.with_dependent_mut(|_owner, dmap| f(dmap))
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 }
pub fn get_map(&self) -> &DirstateMap {
Raphaël Gomès
rust-hg-core: move from `ouroboros` to `self_cell`...
r51575 self.borrow_dependent()
Raphaël Gomès
rust: fix unsound `OwningDirstateMap`...
r49864 }
pub fn on_disk(&self) -> &[u8] {
Raphaël Gomès
rust-hg-core: move from `ouroboros` to `self_cell`...
r51575 self.borrow_owner()
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 }