This instance will be upgraded to Heptapod 0.31.0rc on 2022-05-19 at 11:00 UTC+2 (a few minutes of down time)

Commit 1000db4a authored by Simon Sapin's avatar Simon Sapin
Browse files

dirstate-v2: Store unsigned integers inside DirstateEntry

The negative marker values are not used anymore.

Differential Revision: https://phab.mercurial-scm.org/D11634
parent 320de901896a
......@@ -18,8 +18,8 @@
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct DirstateEntry {
pub(crate) flags: Flags,
mode_size: Option<(i32, i32)>,
mtime: Option<i32>,
mode_size: Option<(u32, u32)>,
mtime: Option<u32>,
}
bitflags! {
......@@ -153,6 +153,6 @@
wdir_tracked: bool,
p1_tracked: bool,
p2_info: bool,
mode_size: Option<(i32, i32)>,
mtime: Option<i32>,
mode_size: Option<(u32, u32)>,
mtime: Option<u32>,
) -> Self {
......@@ -158,4 +158,12 @@
) -> Self {
if let Some((mode, size)) = mode_size {
// TODO: return an error for out of range values?
assert!(mode & !RANGE_MASK_31BIT == 0);
assert!(size & !RANGE_MASK_31BIT == 0);
}
if let Some(mtime) = mtime {
assert!(mtime & !RANGE_MASK_31BIT == 0);
}
let mut flags = Flags::empty();
flags.set(Flags::WDIR_TRACKED, wdir_tracked);
flags.set(Flags::P1_TRACKED, p1_tracked);
......@@ -189,9 +197,12 @@
mtime: None,
}
} else if mtime == MTIME_UNSET {
// TODO: return an error for negative values?
let mode = u32::try_from(mode).unwrap();
let size = u32::try_from(size).unwrap();
Self {
flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED,
mode_size: Some((mode, size)),
mtime: None,
}
} else {
......@@ -192,9 +203,13 @@
Self {
flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED,
mode_size: Some((mode, size)),
mtime: None,
}
} else {
// TODO: return an error for negative values?
let mode = u32::try_from(mode).unwrap();
let size = u32::try_from(size).unwrap();
let mtime = u32::try_from(mtime).unwrap();
Self {
flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED,
mode_size: Some((mode, size)),
......@@ -282,7 +297,7 @@
/// Returns `(wdir_tracked, p1_tracked, p2_info, mode_size, mtime)`
pub(crate) fn v2_data(
&self,
) -> (bool, bool, bool, Option<(i32, i32)>, Option<i32>) {
) -> (bool, bool, bool, Option<(u32, u32)>, Option<u32>) {
if !self.any_tracked() {
// TODO: return an Option instead?
panic!("Accessing v1_state of an untracked DirstateEntry")
......@@ -316,7 +331,7 @@
fn v1_mode(&self) -> i32 {
if let Some((mode, _size)) = self.mode_size {
mode
i32::try_from(mode).unwrap()
} else {
0
}
......@@ -338,7 +353,7 @@
} else if self.added() {
SIZE_NON_NORMAL
} else if let Some((_mode, size)) = self.mode_size {
size
i32::try_from(size).unwrap()
} else {
SIZE_NON_NORMAL
}
......@@ -355,4 +370,6 @@
MTIME_UNSET
} else if !self.flags.contains(Flags::P1_TRACKED) {
MTIME_UNSET
} else if let Some(mtime) = self.mtime {
i32::try_from(mtime).unwrap()
} else {
......@@ -358,5 +375,5 @@
} else {
self.mtime.unwrap_or(MTIME_UNSET)
MTIME_UNSET
}
}
......@@ -392,7 +409,9 @@
self.mtime = None
}
pub fn set_clean(&mut self, mode: i32, size: i32, mtime: i32) {
pub fn set_clean(&mut self, mode: u32, size: u32, mtime: u32) {
let size = size & RANGE_MASK_31BIT;
let mtime = mtime & RANGE_MASK_31BIT;
self.flags.insert(Flags::WDIR_TRACKED | Flags::P1_TRACKED);
self.mode_size = Some((mode, size));
self.mtime = Some(mtime);
......
......@@ -11,7 +11,7 @@
use crate::DirstateError;
use crate::DirstateParents;
use bitflags::bitflags;
use bytes_cast::unaligned::{I32Be, U16Be, U32Be};
use bytes_cast::unaligned::{U16Be, U32Be};
use bytes_cast::BytesCast;
use format_bytes::format_bytes;
use std::borrow::Cow;
......@@ -113,9 +113,9 @@
#[derive(BytesCast, Copy, Clone, Debug)]
#[repr(C)]
struct Entry {
mode: I32Be,
size: I32Be,
mtime: I32Be,
mode: U32Be,
size: U32Be,
mtime: U32Be,
}
/// Duration since the Unix epoch
......
......@@ -21,7 +21,7 @@
p2_info: bool = false,
has_meaningful_data: bool = true,
has_meaningful_mtime: bool = true,
parentfiledata: Option<(i32, i32, i32)> = None,
parentfiledata: Option<(u32, u32, u32)> = None,
) -> PyResult<DirstateItem> {
let mut mode_size_opt = None;
......@@ -145,9 +145,9 @@
def set_clean(
&self,
mode: i32,
size: i32,
mtime: i32,
mode: u32,
size: u32,
mtime: u32,
) -> PyResult<PyNone> {
self.update(py, |entry| entry.set_clean(mode, size, mtime));
Ok(PyNone)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment