##// END OF EJS Templates
rust-dirstate: remove unneeded "ref"...
Yuya Nishihara -
r43062:cc424cc1 default
parent child Browse files
Show More
@@ -1,415 +1,415 b''
1 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
1 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
2 //
2 //
3 // This software may be used and distributed according to the terms of the
3 // This software may be used and distributed according to the terms of the
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::{
6 use crate::{
7 dirstate::{CopyMap, EntryState, StateMap},
7 dirstate::{CopyMap, EntryState, StateMap},
8 utils::copy_into_array,
8 utils::copy_into_array,
9 DirstateEntry, DirstatePackError, DirstateParents, DirstateParseError,
9 DirstateEntry, DirstatePackError, DirstateParents, DirstateParseError,
10 };
10 };
11 use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
11 use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
12 use std::convert::{TryFrom, TryInto};
12 use std::convert::{TryFrom, TryInto};
13 use std::io::Cursor;
13 use std::io::Cursor;
14 use std::time::Duration;
14 use std::time::Duration;
15
15
16 /// Parents are stored in the dirstate as byte hashes.
16 /// Parents are stored in the dirstate as byte hashes.
17 pub const PARENT_SIZE: usize = 20;
17 pub const PARENT_SIZE: usize = 20;
18 /// Dirstate entries have a static part of 8 + 32 + 32 + 32 + 32 bits.
18 /// Dirstate entries have a static part of 8 + 32 + 32 + 32 + 32 bits.
19 const MIN_ENTRY_SIZE: usize = 17;
19 const MIN_ENTRY_SIZE: usize = 17;
20
20
21 // TODO parse/pack: is mutate-on-loop better for performance?
21 // TODO parse/pack: is mutate-on-loop better for performance?
22
22
23 pub fn parse_dirstate(
23 pub fn parse_dirstate(
24 state_map: &mut StateMap,
24 state_map: &mut StateMap,
25 copy_map: &mut CopyMap,
25 copy_map: &mut CopyMap,
26 contents: &[u8],
26 contents: &[u8],
27 ) -> Result<DirstateParents, DirstateParseError> {
27 ) -> Result<DirstateParents, DirstateParseError> {
28 if contents.len() < PARENT_SIZE * 2 {
28 if contents.len() < PARENT_SIZE * 2 {
29 return Err(DirstateParseError::TooLittleData);
29 return Err(DirstateParseError::TooLittleData);
30 }
30 }
31
31
32 let mut curr_pos = PARENT_SIZE * 2;
32 let mut curr_pos = PARENT_SIZE * 2;
33 let parents = DirstateParents {
33 let parents = DirstateParents {
34 p1: copy_into_array(&contents[..PARENT_SIZE]),
34 p1: copy_into_array(&contents[..PARENT_SIZE]),
35 p2: copy_into_array(&contents[PARENT_SIZE..curr_pos]),
35 p2: copy_into_array(&contents[PARENT_SIZE..curr_pos]),
36 };
36 };
37
37
38 while curr_pos < contents.len() {
38 while curr_pos < contents.len() {
39 if curr_pos + MIN_ENTRY_SIZE > contents.len() {
39 if curr_pos + MIN_ENTRY_SIZE > contents.len() {
40 return Err(DirstateParseError::Overflow);
40 return Err(DirstateParseError::Overflow);
41 }
41 }
42 let entry_bytes = &contents[curr_pos..];
42 let entry_bytes = &contents[curr_pos..];
43
43
44 let mut cursor = Cursor::new(entry_bytes);
44 let mut cursor = Cursor::new(entry_bytes);
45 let state = EntryState::try_from(cursor.read_u8()?)?;
45 let state = EntryState::try_from(cursor.read_u8()?)?;
46 let mode = cursor.read_i32::<BigEndian>()?;
46 let mode = cursor.read_i32::<BigEndian>()?;
47 let size = cursor.read_i32::<BigEndian>()?;
47 let size = cursor.read_i32::<BigEndian>()?;
48 let mtime = cursor.read_i32::<BigEndian>()?;
48 let mtime = cursor.read_i32::<BigEndian>()?;
49 let path_len = cursor.read_i32::<BigEndian>()? as usize;
49 let path_len = cursor.read_i32::<BigEndian>()? as usize;
50
50
51 if path_len > contents.len() - curr_pos {
51 if path_len > contents.len() - curr_pos {
52 return Err(DirstateParseError::Overflow);
52 return Err(DirstateParseError::Overflow);
53 }
53 }
54
54
55 // Slice instead of allocating a Vec needed for `read_exact`
55 // Slice instead of allocating a Vec needed for `read_exact`
56 let path = &entry_bytes[MIN_ENTRY_SIZE..MIN_ENTRY_SIZE + (path_len)];
56 let path = &entry_bytes[MIN_ENTRY_SIZE..MIN_ENTRY_SIZE + (path_len)];
57
57
58 let (path, copy) = match memchr::memchr(0, path) {
58 let (path, copy) = match memchr::memchr(0, path) {
59 None => (path, None),
59 None => (path, None),
60 Some(i) => (&path[..i], Some(&path[(i + 1)..])),
60 Some(i) => (&path[..i], Some(&path[(i + 1)..])),
61 };
61 };
62
62
63 if let Some(copy_path) = copy {
63 if let Some(copy_path) = copy {
64 copy_map.insert(path.to_owned(), copy_path.to_owned());
64 copy_map.insert(path.to_owned(), copy_path.to_owned());
65 };
65 };
66 state_map.insert(
66 state_map.insert(
67 path.to_owned(),
67 path.to_owned(),
68 DirstateEntry {
68 DirstateEntry {
69 state,
69 state,
70 mode,
70 mode,
71 size,
71 size,
72 mtime,
72 mtime,
73 },
73 },
74 );
74 );
75 curr_pos = curr_pos + MIN_ENTRY_SIZE + (path_len);
75 curr_pos = curr_pos + MIN_ENTRY_SIZE + (path_len);
76 }
76 }
77
77
78 Ok(parents)
78 Ok(parents)
79 }
79 }
80
80
81 /// `now` is the duration in seconds since the Unix epoch
81 /// `now` is the duration in seconds since the Unix epoch
82 pub fn pack_dirstate(
82 pub fn pack_dirstate(
83 state_map: &mut StateMap,
83 state_map: &mut StateMap,
84 copy_map: &CopyMap,
84 copy_map: &CopyMap,
85 parents: DirstateParents,
85 parents: DirstateParents,
86 now: Duration,
86 now: Duration,
87 ) -> Result<Vec<u8>, DirstatePackError> {
87 ) -> Result<Vec<u8>, DirstatePackError> {
88 // TODO move away from i32 before 2038.
88 // TODO move away from i32 before 2038.
89 let now: i32 = now.as_secs().try_into().expect("time overflow");
89 let now: i32 = now.as_secs().try_into().expect("time overflow");
90
90
91 let expected_size: usize = state_map
91 let expected_size: usize = state_map
92 .iter()
92 .iter()
93 .map(|(filename, _)| {
93 .map(|(filename, _)| {
94 let mut length = MIN_ENTRY_SIZE + filename.len();
94 let mut length = MIN_ENTRY_SIZE + filename.len();
95 if let Some(ref copy) = copy_map.get(filename) {
95 if let Some(copy) = copy_map.get(filename) {
96 length += copy.len() + 1;
96 length += copy.len() + 1;
97 }
97 }
98 length
98 length
99 })
99 })
100 .sum();
100 .sum();
101 let expected_size = expected_size + PARENT_SIZE * 2;
101 let expected_size = expected_size + PARENT_SIZE * 2;
102
102
103 let mut packed = Vec::with_capacity(expected_size);
103 let mut packed = Vec::with_capacity(expected_size);
104 let mut new_state_map = vec![];
104 let mut new_state_map = vec![];
105
105
106 packed.extend(&parents.p1);
106 packed.extend(&parents.p1);
107 packed.extend(&parents.p2);
107 packed.extend(&parents.p2);
108
108
109 for (ref filename, entry) in state_map.iter() {
109 for (filename, entry) in state_map.iter() {
110 let mut new_filename: Vec<u8> = filename.to_vec();
110 let mut new_filename: Vec<u8> = filename.to_owned();
111 let mut new_mtime: i32 = entry.mtime;
111 let mut new_mtime: i32 = entry.mtime;
112 if entry.state == EntryState::Normal && entry.mtime == now {
112 if entry.state == EntryState::Normal && entry.mtime == now {
113 // The file was last modified "simultaneously" with the current
113 // The file was last modified "simultaneously" with the current
114 // write to dirstate (i.e. within the same second for file-
114 // write to dirstate (i.e. within the same second for file-
115 // systems with a granularity of 1 sec). This commonly happens
115 // systems with a granularity of 1 sec). This commonly happens
116 // for at least a couple of files on 'update'.
116 // for at least a couple of files on 'update'.
117 // The user could change the file without changing its size
117 // The user could change the file without changing its size
118 // within the same second. Invalidate the file's mtime in
118 // within the same second. Invalidate the file's mtime in
119 // dirstate, forcing future 'status' calls to compare the
119 // dirstate, forcing future 'status' calls to compare the
120 // contents of the file if the size is the same. This prevents
120 // contents of the file if the size is the same. This prevents
121 // mistakenly treating such files as clean.
121 // mistakenly treating such files as clean.
122 new_mtime = -1;
122 new_mtime = -1;
123 new_state_map.push((
123 new_state_map.push((
124 filename.to_owned().to_vec(),
124 filename.to_owned(),
125 DirstateEntry {
125 DirstateEntry {
126 mtime: new_mtime,
126 mtime: new_mtime,
127 ..*entry
127 ..*entry
128 },
128 },
129 ));
129 ));
130 }
130 }
131
131
132 if let Some(copy) = copy_map.get(*filename) {
132 if let Some(copy) = copy_map.get(filename) {
133 new_filename.push('\0' as u8);
133 new_filename.push('\0' as u8);
134 new_filename.extend(copy);
134 new_filename.extend(copy);
135 }
135 }
136
136
137 packed.write_u8(entry.state.into())?;
137 packed.write_u8(entry.state.into())?;
138 packed.write_i32::<BigEndian>(entry.mode)?;
138 packed.write_i32::<BigEndian>(entry.mode)?;
139 packed.write_i32::<BigEndian>(entry.size)?;
139 packed.write_i32::<BigEndian>(entry.size)?;
140 packed.write_i32::<BigEndian>(new_mtime)?;
140 packed.write_i32::<BigEndian>(new_mtime)?;
141 packed.write_i32::<BigEndian>(new_filename.len() as i32)?;
141 packed.write_i32::<BigEndian>(new_filename.len() as i32)?;
142 packed.extend(new_filename)
142 packed.extend(new_filename)
143 }
143 }
144
144
145 if packed.len() != expected_size {
145 if packed.len() != expected_size {
146 return Err(DirstatePackError::BadSize(expected_size, packed.len()));
146 return Err(DirstatePackError::BadSize(expected_size, packed.len()));
147 }
147 }
148
148
149 state_map.extend(new_state_map);
149 state_map.extend(new_state_map);
150
150
151 Ok(packed)
151 Ok(packed)
152 }
152 }
153
153
154 #[cfg(test)]
154 #[cfg(test)]
155 mod tests {
155 mod tests {
156 use super::*;
156 use super::*;
157 use std::collections::HashMap;
157 use std::collections::HashMap;
158
158
159 #[test]
159 #[test]
160 fn test_pack_dirstate_empty() {
160 fn test_pack_dirstate_empty() {
161 let mut state_map: StateMap = HashMap::new();
161 let mut state_map: StateMap = HashMap::new();
162 let copymap = HashMap::new();
162 let copymap = HashMap::new();
163 let parents = DirstateParents {
163 let parents = DirstateParents {
164 p1: *b"12345678910111213141",
164 p1: *b"12345678910111213141",
165 p2: *b"00000000000000000000",
165 p2: *b"00000000000000000000",
166 };
166 };
167 let now = Duration::new(15000000, 0);
167 let now = Duration::new(15000000, 0);
168 let expected = b"1234567891011121314100000000000000000000".to_vec();
168 let expected = b"1234567891011121314100000000000000000000".to_vec();
169
169
170 assert_eq!(
170 assert_eq!(
171 expected,
171 expected,
172 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
172 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
173 );
173 );
174
174
175 assert!(state_map.is_empty())
175 assert!(state_map.is_empty())
176 }
176 }
177 #[test]
177 #[test]
178 fn test_pack_dirstate_one_entry() {
178 fn test_pack_dirstate_one_entry() {
179 let expected_state_map: StateMap = [(
179 let expected_state_map: StateMap = [(
180 b"f1".to_vec(),
180 b"f1".to_vec(),
181 DirstateEntry {
181 DirstateEntry {
182 state: EntryState::Normal,
182 state: EntryState::Normal,
183 mode: 0o644,
183 mode: 0o644,
184 size: 0,
184 size: 0,
185 mtime: 791231220,
185 mtime: 791231220,
186 },
186 },
187 )]
187 )]
188 .iter()
188 .iter()
189 .cloned()
189 .cloned()
190 .collect();
190 .collect();
191 let mut state_map = expected_state_map.clone();
191 let mut state_map = expected_state_map.clone();
192
192
193 let copymap = HashMap::new();
193 let copymap = HashMap::new();
194 let parents = DirstateParents {
194 let parents = DirstateParents {
195 p1: *b"12345678910111213141",
195 p1: *b"12345678910111213141",
196 p2: *b"00000000000000000000",
196 p2: *b"00000000000000000000",
197 };
197 };
198 let now = Duration::new(15000000, 0);
198 let now = Duration::new(15000000, 0);
199 let expected = [
199 let expected = [
200 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49,
200 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49,
201 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
201 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
202 48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47,
202 48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47,
203 41, 58, 244, 0, 0, 0, 2, 102, 49,
203 41, 58, 244, 0, 0, 0, 2, 102, 49,
204 ]
204 ]
205 .to_vec();
205 .to_vec();
206
206
207 assert_eq!(
207 assert_eq!(
208 expected,
208 expected,
209 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
209 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
210 );
210 );
211
211
212 assert_eq!(expected_state_map, state_map);
212 assert_eq!(expected_state_map, state_map);
213 }
213 }
214 #[test]
214 #[test]
215 fn test_pack_dirstate_one_entry_with_copy() {
215 fn test_pack_dirstate_one_entry_with_copy() {
216 let expected_state_map: StateMap = [(
216 let expected_state_map: StateMap = [(
217 b"f1".to_vec(),
217 b"f1".to_vec(),
218 DirstateEntry {
218 DirstateEntry {
219 state: EntryState::Normal,
219 state: EntryState::Normal,
220 mode: 0o644,
220 mode: 0o644,
221 size: 0,
221 size: 0,
222 mtime: 791231220,
222 mtime: 791231220,
223 },
223 },
224 )]
224 )]
225 .iter()
225 .iter()
226 .cloned()
226 .cloned()
227 .collect();
227 .collect();
228 let mut state_map = expected_state_map.clone();
228 let mut state_map = expected_state_map.clone();
229 let mut copymap = HashMap::new();
229 let mut copymap = HashMap::new();
230 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
230 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
231 let parents = DirstateParents {
231 let parents = DirstateParents {
232 p1: *b"12345678910111213141",
232 p1: *b"12345678910111213141",
233 p2: *b"00000000000000000000",
233 p2: *b"00000000000000000000",
234 };
234 };
235 let now = Duration::new(15000000, 0);
235 let now = Duration::new(15000000, 0);
236 let expected = [
236 let expected = [
237 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49,
237 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49,
238 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
238 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
239 48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47,
239 48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47,
240 41, 58, 244, 0, 0, 0, 11, 102, 49, 0, 99, 111, 112, 121, 110, 97,
240 41, 58, 244, 0, 0, 0, 11, 102, 49, 0, 99, 111, 112, 121, 110, 97,
241 109, 101,
241 109, 101,
242 ]
242 ]
243 .to_vec();
243 .to_vec();
244
244
245 assert_eq!(
245 assert_eq!(
246 expected,
246 expected,
247 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
247 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
248 );
248 );
249 assert_eq!(expected_state_map, state_map);
249 assert_eq!(expected_state_map, state_map);
250 }
250 }
251
251
252 #[test]
252 #[test]
253 fn test_parse_pack_one_entry_with_copy() {
253 fn test_parse_pack_one_entry_with_copy() {
254 let mut state_map: StateMap = [(
254 let mut state_map: StateMap = [(
255 b"f1".to_vec(),
255 b"f1".to_vec(),
256 DirstateEntry {
256 DirstateEntry {
257 state: EntryState::Normal,
257 state: EntryState::Normal,
258 mode: 0o644,
258 mode: 0o644,
259 size: 0,
259 size: 0,
260 mtime: 791231220,
260 mtime: 791231220,
261 },
261 },
262 )]
262 )]
263 .iter()
263 .iter()
264 .cloned()
264 .cloned()
265 .collect();
265 .collect();
266 let mut copymap = HashMap::new();
266 let mut copymap = HashMap::new();
267 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
267 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
268 let parents = DirstateParents {
268 let parents = DirstateParents {
269 p1: *b"12345678910111213141",
269 p1: *b"12345678910111213141",
270 p2: *b"00000000000000000000",
270 p2: *b"00000000000000000000",
271 };
271 };
272 let now = Duration::new(15000000, 0);
272 let now = Duration::new(15000000, 0);
273 let result =
273 let result =
274 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
274 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
275 .unwrap();
275 .unwrap();
276
276
277 let mut new_state_map: StateMap = HashMap::new();
277 let mut new_state_map: StateMap = HashMap::new();
278 let mut new_copy_map: CopyMap = HashMap::new();
278 let mut new_copy_map: CopyMap = HashMap::new();
279 let new_parents = parse_dirstate(
279 let new_parents = parse_dirstate(
280 &mut new_state_map,
280 &mut new_state_map,
281 &mut new_copy_map,
281 &mut new_copy_map,
282 result.as_slice(),
282 result.as_slice(),
283 )
283 )
284 .unwrap();
284 .unwrap();
285 assert_eq!(
285 assert_eq!(
286 (parents, state_map, copymap),
286 (parents, state_map, copymap),
287 (new_parents, new_state_map, new_copy_map)
287 (new_parents, new_state_map, new_copy_map)
288 )
288 )
289 }
289 }
290
290
291 #[test]
291 #[test]
292 fn test_parse_pack_multiple_entries_with_copy() {
292 fn test_parse_pack_multiple_entries_with_copy() {
293 let mut state_map: StateMap = [
293 let mut state_map: StateMap = [
294 (
294 (
295 b"f1".to_vec(),
295 b"f1".to_vec(),
296 DirstateEntry {
296 DirstateEntry {
297 state: EntryState::Normal,
297 state: EntryState::Normal,
298 mode: 0o644,
298 mode: 0o644,
299 size: 0,
299 size: 0,
300 mtime: 791231220,
300 mtime: 791231220,
301 },
301 },
302 ),
302 ),
303 (
303 (
304 b"f2".to_vec(),
304 b"f2".to_vec(),
305 DirstateEntry {
305 DirstateEntry {
306 state: EntryState::Merged,
306 state: EntryState::Merged,
307 mode: 0o777,
307 mode: 0o777,
308 size: 1000,
308 size: 1000,
309 mtime: 791231220,
309 mtime: 791231220,
310 },
310 },
311 ),
311 ),
312 (
312 (
313 b"f3".to_vec(),
313 b"f3".to_vec(),
314 DirstateEntry {
314 DirstateEntry {
315 state: EntryState::Removed,
315 state: EntryState::Removed,
316 mode: 0o644,
316 mode: 0o644,
317 size: 234553,
317 size: 234553,
318 mtime: 791231220,
318 mtime: 791231220,
319 },
319 },
320 ),
320 ),
321 (
321 (
322 b"f4\xF6".to_vec(),
322 b"f4\xF6".to_vec(),
323 DirstateEntry {
323 DirstateEntry {
324 state: EntryState::Added,
324 state: EntryState::Added,
325 mode: 0o644,
325 mode: 0o644,
326 size: -1,
326 size: -1,
327 mtime: -1,
327 mtime: -1,
328 },
328 },
329 ),
329 ),
330 ]
330 ]
331 .iter()
331 .iter()
332 .cloned()
332 .cloned()
333 .collect();
333 .collect();
334 let mut copymap = HashMap::new();
334 let mut copymap = HashMap::new();
335 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
335 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
336 copymap.insert(b"f4\xF6".to_vec(), b"copyname2".to_vec());
336 copymap.insert(b"f4\xF6".to_vec(), b"copyname2".to_vec());
337 let parents = DirstateParents {
337 let parents = DirstateParents {
338 p1: *b"12345678910111213141",
338 p1: *b"12345678910111213141",
339 p2: *b"00000000000000000000",
339 p2: *b"00000000000000000000",
340 };
340 };
341 let now = Duration::new(15000000, 0);
341 let now = Duration::new(15000000, 0);
342 let result =
342 let result =
343 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
343 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
344 .unwrap();
344 .unwrap();
345
345
346 let mut new_state_map: StateMap = HashMap::new();
346 let mut new_state_map: StateMap = HashMap::new();
347 let mut new_copy_map: CopyMap = HashMap::new();
347 let mut new_copy_map: CopyMap = HashMap::new();
348 let new_parents = parse_dirstate(
348 let new_parents = parse_dirstate(
349 &mut new_state_map,
349 &mut new_state_map,
350 &mut new_copy_map,
350 &mut new_copy_map,
351 result.as_slice(),
351 result.as_slice(),
352 )
352 )
353 .unwrap();
353 .unwrap();
354 assert_eq!(
354 assert_eq!(
355 (parents, state_map, copymap),
355 (parents, state_map, copymap),
356 (new_parents, new_state_map, new_copy_map)
356 (new_parents, new_state_map, new_copy_map)
357 )
357 )
358 }
358 }
359
359
360 #[test]
360 #[test]
361 /// https://www.mercurial-scm.org/repo/hg/rev/af3f26b6bba4
361 /// https://www.mercurial-scm.org/repo/hg/rev/af3f26b6bba4
362 fn test_parse_pack_one_entry_with_copy_and_time_conflict() {
362 fn test_parse_pack_one_entry_with_copy_and_time_conflict() {
363 let mut state_map: StateMap = [(
363 let mut state_map: StateMap = [(
364 b"f1".to_vec(),
364 b"f1".to_vec(),
365 DirstateEntry {
365 DirstateEntry {
366 state: EntryState::Normal,
366 state: EntryState::Normal,
367 mode: 0o644,
367 mode: 0o644,
368 size: 0,
368 size: 0,
369 mtime: 15000000,
369 mtime: 15000000,
370 },
370 },
371 )]
371 )]
372 .iter()
372 .iter()
373 .cloned()
373 .cloned()
374 .collect();
374 .collect();
375 let mut copymap = HashMap::new();
375 let mut copymap = HashMap::new();
376 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
376 copymap.insert(b"f1".to_vec(), b"copyname".to_vec());
377 let parents = DirstateParents {
377 let parents = DirstateParents {
378 p1: *b"12345678910111213141",
378 p1: *b"12345678910111213141",
379 p2: *b"00000000000000000000",
379 p2: *b"00000000000000000000",
380 };
380 };
381 let now = Duration::new(15000000, 0);
381 let now = Duration::new(15000000, 0);
382 let result =
382 let result =
383 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
383 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
384 .unwrap();
384 .unwrap();
385
385
386 let mut new_state_map: StateMap = HashMap::new();
386 let mut new_state_map: StateMap = HashMap::new();
387 let mut new_copy_map: CopyMap = HashMap::new();
387 let mut new_copy_map: CopyMap = HashMap::new();
388 let new_parents = parse_dirstate(
388 let new_parents = parse_dirstate(
389 &mut new_state_map,
389 &mut new_state_map,
390 &mut new_copy_map,
390 &mut new_copy_map,
391 result.as_slice(),
391 result.as_slice(),
392 )
392 )
393 .unwrap();
393 .unwrap();
394
394
395 assert_eq!(
395 assert_eq!(
396 (
396 (
397 parents,
397 parents,
398 [(
398 [(
399 b"f1".to_vec(),
399 b"f1".to_vec(),
400 DirstateEntry {
400 DirstateEntry {
401 state: EntryState::Normal,
401 state: EntryState::Normal,
402 mode: 0o644,
402 mode: 0o644,
403 size: 0,
403 size: 0,
404 mtime: -1
404 mtime: -1
405 }
405 }
406 )]
406 )]
407 .iter()
407 .iter()
408 .cloned()
408 .cloned()
409 .collect::<StateMap>(),
409 .collect::<StateMap>(),
410 copymap,
410 copymap,
411 ),
411 ),
412 (new_parents, new_state_map, new_copy_map)
412 (new_parents, new_state_map, new_copy_map)
413 )
413 )
414 }
414 }
415 }
415 }
General Comments 0
You need to be logged in to leave comments. Login now