Mercurial > hg
comparison rust/hg-core/src/dirstate/entry.rs @ 48139:ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Differential Revision: https://phab.mercurial-scm.org/D11558
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 01 Oct 2021 18:49:33 +0200 |
parents | 38488d488ec1 |
children | fb3b41d583c2 |
comparison
equal
deleted
inserted
replaced
48138:38488d488ec1 | 48139:ab5a7fdbf75c |
---|---|
13 /// The C implementation uses all signed types. This will be an issue | 13 /// The C implementation uses all signed types. This will be an issue |
14 /// either when 4GB+ source files are commonplace or in 2038, whichever | 14 /// either when 4GB+ source files are commonplace or in 2038, whichever |
15 /// comes first. | 15 /// comes first. |
16 #[derive(Debug, PartialEq, Copy, Clone)] | 16 #[derive(Debug, PartialEq, Copy, Clone)] |
17 pub struct DirstateEntry { | 17 pub struct DirstateEntry { |
18 flags: Flags, | 18 pub(crate) flags: Flags, |
19 mode_size: Option<(i32, i32)>, | 19 mode_size: Option<(i32, i32)>, |
20 mtime: Option<i32>, | 20 mtime: Option<i32>, |
21 } | 21 } |
22 | 22 |
23 bitflags! { | 23 bitflags! { |
24 struct Flags: u8 { | 24 pub(crate) struct Flags: u8 { |
25 const WDIR_TRACKED = 1 << 0; | 25 const WDIR_TRACKED = 1 << 0; |
26 const P1_TRACKED = 1 << 1; | 26 const P1_TRACKED = 1 << 1; |
27 const P2_INFO = 1 << 2; | 27 const P2_INFO = 1 << 2; |
28 } | 28 } |
29 } | 29 } |
39 /// A special value used for internal representation of special case in | 39 /// A special value used for internal representation of special case in |
40 /// dirstate v1 format. | 40 /// dirstate v1 format. |
41 pub const SIZE_NON_NORMAL: i32 = -1; | 41 pub const SIZE_NON_NORMAL: i32 = -1; |
42 | 42 |
43 impl DirstateEntry { | 43 impl DirstateEntry { |
44 pub fn new( | 44 pub fn from_v2_data( |
45 wdir_tracked: bool, | 45 wdir_tracked: bool, |
46 p1_tracked: bool, | 46 p1_tracked: bool, |
47 p2_info: bool, | 47 p2_info: bool, |
48 mode_size: Option<(i32, i32)>, | 48 mode_size: Option<(i32, i32)>, |
49 mtime: Option<i32>, | 49 mtime: Option<i32>, |
191 self.flags.intersects( | 191 self.flags.intersects( |
192 Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_INFO, | 192 Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_INFO, |
193 ) | 193 ) |
194 } | 194 } |
195 | 195 |
196 /// Returns `(wdir_tracked, p1_tracked, p2_info, mode_size, mtime)` | |
197 pub(crate) fn v2_data( | |
198 &self, | |
199 ) -> (bool, bool, bool, Option<(i32, i32)>, Option<i32>) { | |
200 if !self.any_tracked() { | |
201 // TODO: return an Option instead? | |
202 panic!("Accessing v1_state of an untracked DirstateEntry") | |
203 } | |
204 let wdir_tracked = self.flags.contains(Flags::WDIR_TRACKED); | |
205 let p1_tracked = self.flags.contains(Flags::P1_TRACKED); | |
206 let p2_info = self.flags.contains(Flags::P2_INFO); | |
207 let mode_size = self.mode_size; | |
208 let mtime = self.mtime; | |
209 (wdir_tracked, p1_tracked, p2_info, mode_size, mtime) | |
210 } | |
211 | |
196 fn v1_state(&self) -> EntryState { | 212 fn v1_state(&self) -> EntryState { |
197 if !self.any_tracked() { | 213 if !self.any_tracked() { |
198 // TODO: return an Option instead? | 214 // TODO: return an Option instead? |
199 panic!("Accessing v1_state of an untracked DirstateEntry") | 215 panic!("Accessing v1_state of an untracked DirstateEntry") |
200 } | 216 } |