Mercurial > hg
comparison rust/hg-core/src/dirstate/parsers.rs @ 48018:08efe5945d2b
rust: Move DirstateEntry to its own module
… and RawEntry to the dirstate::parsers module, the only one that uses it.
Differential Revision: https://phab.mercurial-scm.org/D11457
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 17 Sep 2021 12:42:24 +0200 |
parents | 3b9914b28133 |
children | f2a9db29cb2d |
comparison
equal
deleted
inserted
replaced
48016:5caec48d9a01 | 48018:08efe5945d2b |
---|---|
4 // GNU General Public License version 2 or any later version. | 4 // GNU General Public License version 2 or any later version. |
5 | 5 |
6 use crate::errors::HgError; | 6 use crate::errors::HgError; |
7 use crate::utils::hg_path::HgPath; | 7 use crate::utils::hg_path::HgPath; |
8 use crate::{ | 8 use crate::{ |
9 dirstate::{CopyMap, EntryState, RawEntry, StateMap}, | 9 dirstate::{CopyMap, EntryState, StateMap}, |
10 DirstateEntry, DirstateParents, | 10 DirstateEntry, DirstateParents, |
11 }; | 11 }; |
12 use byteorder::{BigEndian, WriteBytesExt}; | 12 use byteorder::{BigEndian, WriteBytesExt}; |
13 use bytes_cast::BytesCast; | 13 use bytes_cast::{unaligned, BytesCast}; |
14 use micro_timer::timed; | 14 use micro_timer::timed; |
15 use std::convert::{TryFrom, TryInto}; | 15 use std::convert::{TryFrom, TryInto}; |
16 | 16 |
17 /// Parents are stored in the dirstate as byte hashes. | 17 /// Parents are stored in the dirstate as byte hashes. |
18 pub const PARENT_SIZE: usize = 20; | 18 pub const PARENT_SIZE: usize = 20; |
44 } | 44 } |
45 entries.push((path, *entry)); | 45 entries.push((path, *entry)); |
46 Ok(()) | 46 Ok(()) |
47 })?; | 47 })?; |
48 Ok((parents, entries, copies)) | 48 Ok((parents, entries, copies)) |
49 } | |
50 | |
51 #[derive(BytesCast)] | |
52 #[repr(C)] | |
53 pub(super) struct RawEntry { | |
54 state: u8, | |
55 mode: unaligned::I32Be, | |
56 size: unaligned::I32Be, | |
57 mtime: unaligned::I32Be, | |
58 length: unaligned::I32Be, | |
49 } | 59 } |
50 | 60 |
51 pub fn parse_dirstate_entries<'a>( | 61 pub fn parse_dirstate_entries<'a>( |
52 mut contents: &'a [u8], | 62 mut contents: &'a [u8], |
53 mut each_entry: impl FnMut( | 63 mut each_entry: impl FnMut( |
128 } | 138 } |
129 } | 139 } |
130 | 140 |
131 /// Seconds since the Unix epoch | 141 /// Seconds since the Unix epoch |
132 pub struct Timestamp(pub i64); | 142 pub struct Timestamp(pub i64); |
133 | |
134 impl DirstateEntry { | |
135 pub fn mtime_is_ambiguous(&self, now: i32) -> bool { | |
136 self.state == EntryState::Normal && self.mtime == now | |
137 } | |
138 | |
139 pub fn clear_ambiguous_mtime(&mut self, now: i32) -> bool { | |
140 let ambiguous = self.mtime_is_ambiguous(now); | |
141 if ambiguous { | |
142 // The file was last modified "simultaneously" with the current | |
143 // write to dirstate (i.e. within the same second for file- | |
144 // systems with a granularity of 1 sec). This commonly happens | |
145 // for at least a couple of files on 'update'. | |
146 // The user could change the file without changing its size | |
147 // within the same second. Invalidate the file's mtime in | |
148 // dirstate, forcing future 'status' calls to compare the | |
149 // contents of the file if the size is the same. This prevents | |
150 // mistakenly treating such files as clean. | |
151 self.clear_mtime() | |
152 } | |
153 ambiguous | |
154 } | |
155 | |
156 pub fn clear_mtime(&mut self) { | |
157 self.mtime = -1; | |
158 } | |
159 } | |
160 | 143 |
161 pub fn pack_dirstate( | 144 pub fn pack_dirstate( |
162 state_map: &mut StateMap, | 145 state_map: &mut StateMap, |
163 copy_map: &CopyMap, | 146 copy_map: &CopyMap, |
164 parents: DirstateParents, | 147 parents: DirstateParents, |