annotate rust/hg-core/src/dirstate/parsers.rs @ 48674:f7086f6173f8 stable

dirstate-v2: rename the configuration to enable the format The rename of the old experimental name was overlooked before the 6.0 release. We rename everything to use the new name (and keep the released name as an alias for compatibility). Differential Revision: https://phab.mercurial-scm.org/D12129
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 01 Feb 2022 16:36:20 +0100
parents 269ff8978086
children c7fb9b74e753
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
1 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
2 //
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
3 // This software may be used and distributed according to the terms of the
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
4 // GNU General Public License version 2 or any later version.
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
5
46439
68a15b5a7e58 rust: Replace DirstatePackError with HgError
Simon Sapin <simon.sapin@octobus.net>
parents: 45646
diff changeset
6 use crate::errors::HgError;
47124
cd8ca38fccff rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47102
diff changeset
7 use crate::utils::hg_path::HgPath;
48068
bf8837e3d7ce dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
8 use crate::{dirstate::EntryState, DirstateEntry, DirstateParents};
46594
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
9 use byteorder::{BigEndian, WriteBytesExt};
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
10 use bytes_cast::{unaligned, BytesCast};
44541
d880805d5442 hg-core: add function timing information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43826
diff changeset
11 use micro_timer::timed;
48068
bf8837e3d7ce dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
12 use std::convert::TryFrom;
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
13
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
14 /// Parents are stored in the dirstate as byte hashes.
42748
7cae6bc29ff9 rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42609
diff changeset
15 pub const PARENT_SIZE: usize = 20;
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
16 /// Dirstate entries have a static part of 8 + 32 + 32 + 32 + 32 bits.
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
17 const MIN_ENTRY_SIZE: usize = 17;
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
18
45357
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
19 type ParseResult<'a> = (
46594
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
20 &'a DirstateParents,
45357
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
21 Vec<(&'a HgPath, DirstateEntry)>,
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
22 Vec<(&'a HgPath, &'a HgPath)>,
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
23 );
42748
7cae6bc29ff9 rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents: 42609
diff changeset
24
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
25 pub fn parse_dirstate_parents(
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
26 contents: &[u8],
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
27 ) -> Result<&DirstateParents, HgError> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
28 let (parents, _rest) = DirstateParents::from_bytes(contents)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
29 .map_err(|_| HgError::corrupted("Too little data for dirstate."))?;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
30 Ok(parents)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
31 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46595
diff changeset
32
44541
d880805d5442 hg-core: add function timing information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 43826
diff changeset
33 #[timed]
47097
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
34 pub fn parse_dirstate(contents: &[u8]) -> Result<ParseResult, HgError> {
46594
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
35 let mut copies = Vec::new();
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
36 let mut entries = Vec::new();
47097
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
37 let parents =
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
38 parse_dirstate_entries(contents, |path, entry, copy_source| {
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
39 if let Some(source) = copy_source {
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
40 copies.push((path, source));
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
41 }
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
42 entries.push((path, *entry));
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
43 Ok(())
47097
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
44 })?;
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
45 Ok((parents, entries, copies))
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
46 }
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
47
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
48 #[derive(BytesCast)]
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
49 #[repr(C)]
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
50 struct RawEntry {
48018
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
51 state: u8,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
52 mode: unaligned::I32Be,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
53 size: unaligned::I32Be,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
54 mtime: unaligned::I32Be,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
55 length: unaligned::I32Be,
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
56 }
08efe5945d2b rust: Move DirstateEntry to its own module
Simon Sapin <simon.sapin@octobus.net>
parents: 47351
diff changeset
57
47097
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
58 pub fn parse_dirstate_entries<'a>(
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
59 mut contents: &'a [u8],
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
60 mut each_entry: impl FnMut(
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
61 &'a HgPath,
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
62 &DirstateEntry,
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
63 Option<&'a HgPath>,
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
64 ) -> Result<(), HgError>,
47097
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
65 ) -> Result<&'a DirstateParents, HgError> {
46594
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
66 let (parents, rest) = DirstateParents::from_bytes(contents)
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
67 .map_err(|_| HgError::corrupted("Too little data for dirstate."))?;
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
68 contents = rest;
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
69 while !contents.is_empty() {
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
70 let (raw_entry, rest) = RawEntry::from_bytes(contents)
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
71 .map_err(|_| HgError::corrupted("Overflow in dirstate."))?;
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
72
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
73 let entry = DirstateEntry::from_v1_data(
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
74 EntryState::try_from(raw_entry.state)?,
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
75 raw_entry.mode.get(),
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
76 raw_entry.size.get(),
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
77 raw_entry.mtime.get(),
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
78 );
46594
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
79 let (paths, rest) =
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
80 u8::slice_from_bytes(rest, raw_entry.length.get() as usize)
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
81 .map_err(|_| HgError::corrupted("Overflow in dirstate."))?;
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
82
46594
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
83 // `paths` is either a single path, or two paths separated by a NULL
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
84 // byte
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
85 let mut iter = paths.splitn(2, |&byte| byte == b'\0');
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
86 let path = HgPath::new(
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
87 iter.next().expect("splitn always yields at least one item"),
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
88 );
47097
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
89 let copy_source = iter.next().map(HgPath::new);
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47330
diff changeset
90 each_entry(path, &entry, copy_source)?;
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
91
46594
f88e8ae0aa8f rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents: 46440
diff changeset
92 contents = rest;
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
93 }
47097
e66ea29e2b1a dirstate-tree: Implement DirstateMap::read
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
94 Ok(parents)
42302
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
95 }
d1786c1d34fa rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
96
47102
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
97 fn packed_filename_and_copy_source_size(
47124
cd8ca38fccff rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47102
diff changeset
98 filename: &HgPath,
cd8ca38fccff rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47102
diff changeset
99 copy_source: Option<&HgPath>,
47102
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
100 ) -> usize {
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
101 filename.len()
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
102 + if let Some(source) = copy_source {
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
103 b"\0".len() + source.len()
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
104 } else {
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
105 0
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
106 }
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
107 }
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
108
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
109 pub fn packed_entry_size(
47124
cd8ca38fccff rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47102
diff changeset
110 filename: &HgPath,
cd8ca38fccff rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47102
diff changeset
111 copy_source: Option<&HgPath>,
47102
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
112 ) -> usize {
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
113 MIN_ENTRY_SIZE
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
114 + packed_filename_and_copy_source_size(filename, copy_source)
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
115 }
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
116
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
117 pub fn pack_entry(
47124
cd8ca38fccff rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47102
diff changeset
118 filename: &HgPath,
47102
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
119 entry: &DirstateEntry,
47124
cd8ca38fccff rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents: 47102
diff changeset
120 copy_source: Option<&HgPath>,
47102
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
121 packed: &mut Vec<u8>,
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
122 ) {
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
123 let length = packed_filename_and_copy_source_size(filename, copy_source);
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
124 let (state, mode, size, mtime) = entry.v1_data();
47102
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
125
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
126 // Unwrapping because `impl std::io::Write for Vec<u8>` never errors
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
127 packed.write_u8(state).unwrap();
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
128 packed.write_i32::<BigEndian>(mode).unwrap();
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
129 packed.write_i32::<BigEndian>(size).unwrap();
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 48018
diff changeset
130 packed.write_i32::<BigEndian>(mtime).unwrap();
47102
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
131 packed.write_i32::<BigEndian>(length as i32).unwrap();
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
132 packed.extend(filename.as_bytes());
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
133 if let Some(source) = copy_source {
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
134 packed.push(b'\0');
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
135 packed.extend(source.as_bytes());
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
136 }
d6c94ca40863 dirstate-tree: Serialize to disk
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
137 }