##// END OF EJS Templates
rust-dirstate: make the MTIME_UNSET public...
marmoute -
r48308:b68d61af default
parent child Browse files
Show More
@@ -1,152 +1,152 b''
1 // dirstate module
1 // dirstate module
2 //
2 //
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
4 //
4 //
5 // This software may be used and distributed according to the terms of the
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 use crate::dirstate_tree::on_disk::DirstateV2ParseError;
8 use crate::dirstate_tree::on_disk::DirstateV2ParseError;
9 use crate::errors::HgError;
9 use crate::errors::HgError;
10 use crate::revlog::node::NULL_NODE;
10 use crate::revlog::node::NULL_NODE;
11 use crate::revlog::Node;
11 use crate::revlog::Node;
12 use crate::utils::hg_path::{HgPath, HgPathBuf};
12 use crate::utils::hg_path::{HgPath, HgPathBuf};
13 use crate::FastHashMap;
13 use crate::FastHashMap;
14 use bytes_cast::{unaligned, BytesCast};
14 use bytes_cast::{unaligned, BytesCast};
15 use std::convert::TryFrom;
15 use std::convert::TryFrom;
16
16
17 pub mod dirs_multiset;
17 pub mod dirs_multiset;
18 pub mod dirstate_map;
18 pub mod dirstate_map;
19 pub mod parsers;
19 pub mod parsers;
20 pub mod status;
20 pub mod status;
21
21
22 #[derive(Debug, PartialEq, Clone, BytesCast)]
22 #[derive(Debug, PartialEq, Clone, BytesCast)]
23 #[repr(C)]
23 #[repr(C)]
24 pub struct DirstateParents {
24 pub struct DirstateParents {
25 pub p1: Node,
25 pub p1: Node,
26 pub p2: Node,
26 pub p2: Node,
27 }
27 }
28
28
29 impl DirstateParents {
29 impl DirstateParents {
30 pub const NULL: Self = Self {
30 pub const NULL: Self = Self {
31 p1: NULL_NODE,
31 p1: NULL_NODE,
32 p2: NULL_NODE,
32 p2: NULL_NODE,
33 };
33 };
34 }
34 }
35
35
36 /// The C implementation uses all signed types. This will be an issue
36 /// The C implementation uses all signed types. This will be an issue
37 /// either when 4GB+ source files are commonplace or in 2038, whichever
37 /// either when 4GB+ source files are commonplace or in 2038, whichever
38 /// comes first.
38 /// comes first.
39 #[derive(Debug, PartialEq, Copy, Clone)]
39 #[derive(Debug, PartialEq, Copy, Clone)]
40 pub struct DirstateEntry {
40 pub struct DirstateEntry {
41 pub state: EntryState,
41 pub state: EntryState,
42 pub mode: i32,
42 pub mode: i32,
43 pub mtime: i32,
43 pub mtime: i32,
44 pub size: i32,
44 pub size: i32,
45 }
45 }
46
46
47 impl DirstateEntry {
47 impl DirstateEntry {
48 pub fn is_non_normal(&self) -> bool {
48 pub fn is_non_normal(&self) -> bool {
49 self.state != EntryState::Normal || self.mtime == MTIME_UNSET
49 self.state != EntryState::Normal || self.mtime == MTIME_UNSET
50 }
50 }
51
51
52 pub fn is_from_other_parent(&self) -> bool {
52 pub fn is_from_other_parent(&self) -> bool {
53 self.state == EntryState::Normal && self.size == SIZE_FROM_OTHER_PARENT
53 self.state == EntryState::Normal && self.size == SIZE_FROM_OTHER_PARENT
54 }
54 }
55
55
56 // TODO: other platforms
56 // TODO: other platforms
57 #[cfg(unix)]
57 #[cfg(unix)]
58 pub fn mode_changed(
58 pub fn mode_changed(
59 &self,
59 &self,
60 filesystem_metadata: &std::fs::Metadata,
60 filesystem_metadata: &std::fs::Metadata,
61 ) -> bool {
61 ) -> bool {
62 use std::os::unix::fs::MetadataExt;
62 use std::os::unix::fs::MetadataExt;
63 const EXEC_BIT_MASK: u32 = 0o100;
63 const EXEC_BIT_MASK: u32 = 0o100;
64 let dirstate_exec_bit = (self.mode as u32) & EXEC_BIT_MASK;
64 let dirstate_exec_bit = (self.mode as u32) & EXEC_BIT_MASK;
65 let fs_exec_bit = filesystem_metadata.mode() & EXEC_BIT_MASK;
65 let fs_exec_bit = filesystem_metadata.mode() & EXEC_BIT_MASK;
66 dirstate_exec_bit != fs_exec_bit
66 dirstate_exec_bit != fs_exec_bit
67 }
67 }
68 }
68 }
69
69
70 #[derive(BytesCast)]
70 #[derive(BytesCast)]
71 #[repr(C)]
71 #[repr(C)]
72 struct RawEntry {
72 struct RawEntry {
73 state: u8,
73 state: u8,
74 mode: unaligned::I32Be,
74 mode: unaligned::I32Be,
75 size: unaligned::I32Be,
75 size: unaligned::I32Be,
76 mtime: unaligned::I32Be,
76 mtime: unaligned::I32Be,
77 length: unaligned::I32Be,
77 length: unaligned::I32Be,
78 }
78 }
79
79
80 const MTIME_UNSET: i32 = -1;
80 pub const MTIME_UNSET: i32 = -1;
81
81
82 /// A `DirstateEntry` with a size of `-2` means that it was merged from the
82 /// A `DirstateEntry` with a size of `-2` means that it was merged from the
83 /// other parent. This allows revert to pick the right status back during a
83 /// other parent. This allows revert to pick the right status back during a
84 /// merge.
84 /// merge.
85 pub const SIZE_FROM_OTHER_PARENT: i32 = -2;
85 pub const SIZE_FROM_OTHER_PARENT: i32 = -2;
86 /// A special value used for internal representation of special case in
86 /// A special value used for internal representation of special case in
87 /// dirstate v1 format.
87 /// dirstate v1 format.
88 pub const SIZE_NON_NORMAL: i32 = -1;
88 pub const SIZE_NON_NORMAL: i32 = -1;
89
89
90 pub type StateMap = FastHashMap<HgPathBuf, DirstateEntry>;
90 pub type StateMap = FastHashMap<HgPathBuf, DirstateEntry>;
91 pub type StateMapIter<'a> = Box<
91 pub type StateMapIter<'a> = Box<
92 dyn Iterator<
92 dyn Iterator<
93 Item = Result<(&'a HgPath, DirstateEntry), DirstateV2ParseError>,
93 Item = Result<(&'a HgPath, DirstateEntry), DirstateV2ParseError>,
94 > + Send
94 > + Send
95 + 'a,
95 + 'a,
96 >;
96 >;
97
97
98 pub type CopyMap = FastHashMap<HgPathBuf, HgPathBuf>;
98 pub type CopyMap = FastHashMap<HgPathBuf, HgPathBuf>;
99 pub type CopyMapIter<'a> = Box<
99 pub type CopyMapIter<'a> = Box<
100 dyn Iterator<Item = Result<(&'a HgPath, &'a HgPath), DirstateV2ParseError>>
100 dyn Iterator<Item = Result<(&'a HgPath, &'a HgPath), DirstateV2ParseError>>
101 + Send
101 + Send
102 + 'a,
102 + 'a,
103 >;
103 >;
104
104
105 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
105 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
106 pub enum EntryState {
106 pub enum EntryState {
107 Normal,
107 Normal,
108 Added,
108 Added,
109 Removed,
109 Removed,
110 Merged,
110 Merged,
111 Unknown,
111 Unknown,
112 }
112 }
113
113
114 impl EntryState {
114 impl EntryState {
115 pub fn is_tracked(self) -> bool {
115 pub fn is_tracked(self) -> bool {
116 use EntryState::*;
116 use EntryState::*;
117 match self {
117 match self {
118 Normal | Added | Merged => true,
118 Normal | Added | Merged => true,
119 Removed | Unknown => false,
119 Removed | Unknown => false,
120 }
120 }
121 }
121 }
122 }
122 }
123
123
124 impl TryFrom<u8> for EntryState {
124 impl TryFrom<u8> for EntryState {
125 type Error = HgError;
125 type Error = HgError;
126
126
127 fn try_from(value: u8) -> Result<Self, Self::Error> {
127 fn try_from(value: u8) -> Result<Self, Self::Error> {
128 match value {
128 match value {
129 b'n' => Ok(EntryState::Normal),
129 b'n' => Ok(EntryState::Normal),
130 b'a' => Ok(EntryState::Added),
130 b'a' => Ok(EntryState::Added),
131 b'r' => Ok(EntryState::Removed),
131 b'r' => Ok(EntryState::Removed),
132 b'm' => Ok(EntryState::Merged),
132 b'm' => Ok(EntryState::Merged),
133 b'?' => Ok(EntryState::Unknown),
133 b'?' => Ok(EntryState::Unknown),
134 _ => Err(HgError::CorruptedRepository(format!(
134 _ => Err(HgError::CorruptedRepository(format!(
135 "Incorrect dirstate entry state {}",
135 "Incorrect dirstate entry state {}",
136 value
136 value
137 ))),
137 ))),
138 }
138 }
139 }
139 }
140 }
140 }
141
141
142 impl Into<u8> for EntryState {
142 impl Into<u8> for EntryState {
143 fn into(self) -> u8 {
143 fn into(self) -> u8 {
144 match self {
144 match self {
145 EntryState::Normal => b'n',
145 EntryState::Normal => b'n',
146 EntryState::Added => b'a',
146 EntryState::Added => b'a',
147 EntryState::Removed => b'r',
147 EntryState::Removed => b'r',
148 EntryState::Merged => b'm',
148 EntryState::Merged => b'm',
149 EntryState::Unknown => b'?',
149 EntryState::Unknown => b'?',
150 }
150 }
151 }
151 }
152 }
152 }
General Comments 0
You need to be logged in to leave comments. Login now