Mercurial > hg
annotate rust/hg-core/src/dirstate_tree/on_disk.rs @ 50243:6cce0afc1454 stable
rust-dirstate: remember the data file uuid dirstate was loaded with
This will be used in the next patch to fix a race condition.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 12 Dec 2022 17:08:12 +0100 |
parents | ecd28d89c29e |
children | dbe09fb038fc |
rev | line source |
---|---|
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
1 //! The "version 2" disk representation of the dirstate |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
2 //! |
48166
e8a576de703f
dirstate-v2: Add internal documentation
Simon Sapin <simon.sapin@octobus.net>
parents:
48165
diff
changeset
|
3 //! See `mercurial/helptext/internals/dirstate-v2.txt` |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
4 |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
5 use crate::dirstate::{DirstateV2Data, TruncatedTimestamp}; |
49337
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
6 use crate::dirstate_tree::dirstate_map::DirstateVersion; |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
7 use crate::dirstate_tree::dirstate_map::{ |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
8 self, DirstateMap, DirstateMapWriteMode, NodeRef, |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
9 }; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
10 use crate::dirstate_tree::path_with_basename::WithBasename; |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
11 use crate::errors::HgError; |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
12 use crate::utils::hg_path::HgPath; |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
13 use crate::DirstateEntry; |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
14 use crate::DirstateError; |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
15 use crate::DirstateParents; |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
16 use bitflags::bitflags; |
48194
1000db4a71f1
dirstate-v2: Store unsigned integers inside DirstateEntry
Simon Sapin <simon.sapin@octobus.net>
parents:
48193
diff
changeset
|
17 use bytes_cast::unaligned::{U16Be, U32Be}; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
18 use bytes_cast::BytesCast; |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
19 use format_bytes::format_bytes; |
48421
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
20 use rand::Rng; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
21 use std::borrow::Cow; |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
22 use std::convert::{TryFrom, TryInto}; |
48421
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
23 use std::fmt::Write; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
24 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
25 /// Added at the start of `.hg/dirstate` when the "v2" format is used. |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
26 /// This a redundant sanity check more than an actual "magic number" since |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
27 /// `.hg/requires` already governs which format should be used. |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
28 pub const V2_FORMAT_MARKER: &[u8; 12] = b"dirstate-v2\n"; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
29 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
30 /// Keep space for 256-bit hashes |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
31 const STORED_NODE_ID_BYTES: usize = 32; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
32 |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
33 /// … even though only 160 bits are used for now, with SHA-1 |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
34 const USED_NODE_ID_BYTES: usize = 20; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
35 |
47409
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
36 pub(super) const IGNORE_PATTERNS_HASH_LEN: usize = 20; |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
37 pub(super) type IgnorePatternsHash = [u8; IGNORE_PATTERNS_HASH_LEN]; |
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
38 |
48221
a32a96079e2d
dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents:
48219
diff
changeset
|
39 /// Must match constants of the same names in `mercurial/dirstateutils/v2.py` |
47684
852262e2e7d9
dirstate-v2: Reserve a few bytes of space for future extensions
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
40 const TREE_METADATA_SIZE: usize = 44; |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
41 const NODE_SIZE: usize = 44; |
48196
47fabca85457
dirstate-v2: Name a constant in the Rust implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48195
diff
changeset
|
42 |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
43 /// Make sure that size-affecting changes are made knowingly |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
44 #[allow(unused)] |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
45 fn static_assert_size_of() { |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
46 let _ = std::mem::transmute::<TreeMetadata, [u8; TREE_METADATA_SIZE]>; |
47684
852262e2e7d9
dirstate-v2: Reserve a few bytes of space for future extensions
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
47 let _ = std::mem::transmute::<DocketHeader, [u8; TREE_METADATA_SIZE + 81]>; |
48196
47fabca85457
dirstate-v2: Name a constant in the Rust implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48195
diff
changeset
|
48 let _ = std::mem::transmute::<Node, [u8; NODE_SIZE]>; |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
49 } |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
50 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
51 // Must match `HEADER` in `mercurial/dirstateutils/docket.py` |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
52 #[derive(BytesCast)] |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
53 #[repr(C)] |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
54 struct DocketHeader { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
55 marker: [u8; V2_FORMAT_MARKER.len()], |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
56 parent_1: [u8; STORED_NODE_ID_BYTES], |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
57 parent_2: [u8; STORED_NODE_ID_BYTES], |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
58 |
48165
d467e44f71d7
dirstate-v2: Move data file info in the docket closer together
Simon Sapin <simon.sapin@octobus.net>
parents:
48139
diff
changeset
|
59 metadata: TreeMetadata, |
d467e44f71d7
dirstate-v2: Move data file info in the docket closer together
Simon Sapin <simon.sapin@octobus.net>
parents:
48139
diff
changeset
|
60 |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
61 /// Counted in bytes |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
62 data_size: Size, |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
63 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
64 uuid_size: u8, |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
65 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
66 |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
67 pub struct Docket<'on_disk> { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
68 header: &'on_disk DocketHeader, |
48420
c7c23bb036c9
rhg: Add lazy/cached dirstate data file ID parsing on Repo
Simon Sapin <simon.sapin@octobus.net>
parents:
48416
diff
changeset
|
69 pub uuid: &'on_disk [u8], |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
70 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
71 |
48188
77fc340acad7
dirstate-v2: Document flags/mode/size/mtime fields of tree nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
48166
diff
changeset
|
72 /// Fields are documented in the *Tree metadata in the docket file* |
77fc340acad7
dirstate-v2: Document flags/mode/size/mtime fields of tree nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
48166
diff
changeset
|
73 /// section of `mercurial/helptext/internals/dirstate-v2.txt` |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
74 #[derive(BytesCast)] |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
75 #[repr(C)] |
48421
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
76 pub struct TreeMetadata { |
47676
096ee2e260a3
dirstate-v2: Rename Header to Root, move it to the end of the data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
77 root_nodes: ChildNodes, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
78 nodes_with_entry_count: Size, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
79 nodes_with_copy_source_count: Size, |
47681
d94118365ec5
dirstate-v2: Add heuristic for when to create a new data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47680
diff
changeset
|
80 unreachable_bytes: Size, |
47684
852262e2e7d9
dirstate-v2: Reserve a few bytes of space for future extensions
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
81 unused: [u8; 4], |
852262e2e7d9
dirstate-v2: Reserve a few bytes of space for future extensions
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
82 |
48188
77fc340acad7
dirstate-v2: Document flags/mode/size/mtime fields of tree nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
48166
diff
changeset
|
83 /// See *Optional hash of ignore patterns* section of |
77fc340acad7
dirstate-v2: Document flags/mode/size/mtime fields of tree nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
48166
diff
changeset
|
84 /// `mercurial/helptext/internals/dirstate-v2.txt` |
47409
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
85 ignore_patterns_hash: IgnorePatternsHash, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
86 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
87 |
48188
77fc340acad7
dirstate-v2: Document flags/mode/size/mtime fields of tree nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
48166
diff
changeset
|
88 /// Fields are documented in the *The data file format* |
77fc340acad7
dirstate-v2: Document flags/mode/size/mtime fields of tree nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
48166
diff
changeset
|
89 /// section of `mercurial/helptext/internals/dirstate-v2.txt` |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
90 #[derive(BytesCast, Debug)] |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
91 #[repr(C)] |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
92 pub(super) struct Node { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
93 full_path: PathSlice, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
94 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
95 /// In bytes from `self.full_path.start` |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
96 base_name_start: PathSize, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
97 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
98 copy_source: OptPathSlice, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
99 children: ChildNodes, |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47476
diff
changeset
|
100 pub(super) descendants_with_entry_count: Size, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
101 pub(super) tracked_descendants_count: Size, |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
102 flags: U16Be, |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
103 size: U32Be, |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
104 mtime: PackedTruncatedTimestamp, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
105 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
106 |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
107 bitflags! { |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
108 #[repr(C)] |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
109 struct Flags: u16 { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
110 const WDIR_TRACKED = 1 << 0; |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
111 const P1_TRACKED = 1 << 1; |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
112 const P2_INFO = 1 << 2; |
48266
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
113 const MODE_EXEC_PERM = 1 << 3; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
114 const MODE_IS_SYMLINK = 1 << 4; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
115 const HAS_FALLBACK_EXEC = 1 << 5; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
116 const FALLBACK_EXEC = 1 << 6; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
117 const HAS_FALLBACK_SYMLINK = 1 << 7; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
118 const FALLBACK_SYMLINK = 1 << 8; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
119 const EXPECTED_STATE_IS_MODIFIED = 1 << 9; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
120 const HAS_MODE_AND_SIZE = 1 <<10; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
121 const HAS_MTIME = 1 <<11; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
122 const MTIME_SECOND_AMBIGUOUS = 1 << 12; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
123 const DIRECTORY = 1 <<13; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
124 const ALL_UNKNOWN_RECORDED = 1 <<14; |
749946b6a641
dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48265
diff
changeset
|
125 const ALL_IGNORED_RECORDED = 1 <<15; |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
126 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
127 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
128 |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
129 /// Duration since the Unix epoch |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
130 #[derive(BytesCast, Copy, Clone, Debug)] |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
131 #[repr(C)] |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
132 struct PackedTruncatedTimestamp { |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
133 truncated_seconds: U32Be, |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
134 nanoseconds: U32Be, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
135 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
136 |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
137 /// Counted in bytes from the start of the file |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
138 /// |
47476
f23eafb036af
dirstate-v2: Use 32-bit integers instead of 64-bit for offsets
Simon Sapin <simon.sapin@octobus.net>
parents:
47475
diff
changeset
|
139 /// NOTE: not supporting `.hg/dirstate` files larger than 4 GiB. |
f23eafb036af
dirstate-v2: Use 32-bit integers instead of 64-bit for offsets
Simon Sapin <simon.sapin@octobus.net>
parents:
47475
diff
changeset
|
140 type Offset = U32Be; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
141 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
142 /// Counted in number of items |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
143 /// |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
144 /// NOTE: we choose not to support counting more than 4 billion nodes anywhere. |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
145 type Size = U32Be; |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
146 |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
147 /// Counted in bytes |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
148 /// |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
149 /// NOTE: we choose not to support file names/paths longer than 64 KiB. |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
150 type PathSize = U16Be; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
151 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
152 /// A contiguous sequence of `len` times `Node`, representing the child nodes |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
153 /// of either some other node or of the repository root. |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
154 /// |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
155 /// Always sorted by ascending `full_path`, to allow binary search. |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
156 /// Since nodes with the same parent nodes also have the same parent path, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
157 /// only the `base_name`s need to be compared during binary search. |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
158 #[derive(BytesCast, Copy, Clone, Debug)] |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
159 #[repr(C)] |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
160 struct ChildNodes { |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
161 start: Offset, |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
162 len: Size, |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
163 } |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
164 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
165 /// A `HgPath` of `len` bytes |
49125
28a6178a07a2
rust: add `Debug` trait to a bunch of structs
Raphaël Gomès <rgomes@octobus.net>
parents:
49100
diff
changeset
|
166 #[derive(BytesCast, Copy, Clone, Debug)] |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
167 #[repr(C)] |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
168 struct PathSlice { |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
169 start: Offset, |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
170 len: PathSize, |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
171 } |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
172 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
173 /// Either nothing if `start == 0`, or a `HgPath` of `len` bytes |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
174 type OptPathSlice = PathSlice; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
175 |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
176 /// Unexpected file format found in `.hg/dirstate` with the "v2" format. |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
177 /// |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
178 /// This should only happen if Mercurial is buggy or a repository is corrupted. |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47334
diff
changeset
|
179 #[derive(Debug)] |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
180 pub struct DirstateV2ParseError { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
181 message: String, |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
182 } |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
183 |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
184 impl DirstateV2ParseError { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
185 pub fn new<S: Into<String>>(message: S) -> Self { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
186 Self { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
187 message: message.into(), |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
188 } |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
189 } |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
190 } |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
191 |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
192 impl From<DirstateV2ParseError> for HgError { |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
193 fn from(e: DirstateV2ParseError) -> Self { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
194 HgError::corrupted(format!("dirstate-v2 parse error: {}", e.message)) |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
195 } |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
196 } |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
197 |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
198 impl From<DirstateV2ParseError> for crate::DirstateError { |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
199 fn from(error: DirstateV2ParseError) -> Self { |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
200 HgError::from(error).into() |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
201 } |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
202 } |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
203 |
48421
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
204 impl TreeMetadata { |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
205 pub fn as_bytes(&self) -> &[u8] { |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
206 BytesCast::as_bytes(self) |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
207 } |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
208 } |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
209 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
210 impl<'on_disk> Docket<'on_disk> { |
48421
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
211 /// Generate the identifier for a new data file |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
212 /// |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
213 /// TODO: support the `HGTEST_UUIDFILE` environment variable. |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
214 /// See `mercurial/revlogutils/docket.py` |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
215 pub fn new_uid() -> String { |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
216 const ID_LENGTH: usize = 8; |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
217 let mut id = String::with_capacity(ID_LENGTH); |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
218 let mut rng = rand::thread_rng(); |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
219 for _ in 0..ID_LENGTH { |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
220 // One random hexadecimal digit. |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
221 // `unwrap` never panics because `impl Write for String` |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
222 // never returns an error. |
48554
0dc698c91ca0
rust: upgrade `rand*` crates
Martin von Zweigbergk <martinvonz@google.com>
parents:
48525
diff
changeset
|
223 write!(&mut id, "{:x}", rng.gen_range(0..16)).unwrap(); |
48421
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
224 } |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
225 id |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
226 } |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
227 |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
228 pub fn serialize( |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
229 parents: DirstateParents, |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
230 tree_metadata: TreeMetadata, |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
231 data_size: u64, |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
232 uuid: &[u8], |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
233 ) -> Result<Vec<u8>, std::num::TryFromIntError> { |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
234 let header = DocketHeader { |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
235 marker: *V2_FORMAT_MARKER, |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
236 parent_1: parents.p1.pad_to_256_bits(), |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
237 parent_2: parents.p2.pad_to_256_bits(), |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
238 metadata: tree_metadata, |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
239 data_size: u32::try_from(data_size)?.into(), |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
240 uuid_size: uuid.len().try_into()?, |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
241 }; |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
242 let header = header.as_bytes(); |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
243 let mut docket = Vec::with_capacity(header.len() + uuid.len()); |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
244 docket.extend_from_slice(header); |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
245 docket.extend_from_slice(uuid); |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
246 Ok(docket) |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
247 } |
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48420
diff
changeset
|
248 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
249 pub fn parents(&self) -> DirstateParents { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
250 use crate::Node; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
251 let p1 = Node::try_from(&self.header.parent_1[..USED_NODE_ID_BYTES]) |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
252 .unwrap() |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
253 .clone(); |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
254 let p2 = Node::try_from(&self.header.parent_2[..USED_NODE_ID_BYTES]) |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
255 .unwrap() |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
256 .clone(); |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
257 DirstateParents { p1, p2 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
258 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
259 |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
260 pub fn tree_metadata(&self) -> &[u8] { |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
261 self.header.metadata.as_bytes() |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
262 } |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
263 |
47675
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
264 pub fn data_size(&self) -> usize { |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
265 // This `unwrap` could only panic on a 16-bit CPU |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
266 self.header.data_size.get().try_into().unwrap() |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
267 } |
48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47674
diff
changeset
|
268 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
269 pub fn data_filename(&self) -> String { |
47966
681851d6409b
dirstate-v2: Remove the `.d` suffix in data file names
Simon Sapin <simon.sapin@octobus.net>
parents:
47684
diff
changeset
|
270 String::from_utf8(format_bytes!(b"dirstate.{}", self.uuid)).unwrap() |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
271 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
272 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
273 |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
274 pub fn read_docket( |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
275 on_disk: &[u8], |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
276 ) -> Result<Docket<'_>, DirstateV2ParseError> { |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
277 let (header, uuid) = DocketHeader::from_bytes(on_disk).map_err(|e| { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
278 DirstateV2ParseError::new(format!("when reading docket, {}", e)) |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
279 })?; |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
280 let uuid_size = header.uuid_size as usize; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
281 if header.marker == *V2_FORMAT_MARKER && uuid.len() == uuid_size { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
282 Ok(Docket { header, uuid }) |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
283 } else { |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
284 Err(DirstateV2ParseError::new( |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
285 "invalid format marker or uuid size", |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
286 )) |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
287 } |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
288 } |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
289 |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
290 pub(super) fn read<'on_disk>( |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
291 on_disk: &'on_disk [u8], |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
292 metadata: &[u8], |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
293 uuid: Vec<u8>, |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
294 ) -> Result<DirstateMap<'on_disk>, DirstateV2ParseError> { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
295 if on_disk.is_empty() { |
49337
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
296 let mut map = DirstateMap::empty(on_disk); |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
297 map.dirstate_version = DirstateVersion::V2; |
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
298 return Ok(map); |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
299 } |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
300 let (meta, _) = TreeMetadata::from_bytes(metadata).map_err(|e| { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
301 DirstateV2ParseError::new(format!("when parsing tree metadata, {}", e)) |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
302 })?; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
303 let dirstate_map = DirstateMap { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
304 on_disk, |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
305 root: dirstate_map::ChildNodes::OnDisk( |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
306 read_nodes(on_disk, meta.root_nodes).map_err(|mut e| { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
307 e.message = format!("{}, when reading root notes", e.message); |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
308 e |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
309 })?, |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
310 ), |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
311 nodes_with_entry_count: meta.nodes_with_entry_count.get(), |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
312 nodes_with_copy_source_count: meta.nodes_with_copy_source_count.get(), |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
313 ignore_patterns_hash: meta.ignore_patterns_hash, |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
314 unreachable_bytes: meta.unreachable_bytes.get(), |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
315 old_data_size: on_disk.len(), |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Raphaël Gomès <rgomes@octobus.net>
parents:
50222
diff
changeset
|
316 old_uuid: Some(uuid), |
49337
6cd249556e20
rust-status: don't trigger dirstate v1 rewrite when only v2 data is changed
Raphaël Gomès <rgomes@octobus.net>
parents:
49156
diff
changeset
|
317 dirstate_version: DirstateVersion::V2, |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
318 write_mode: DirstateMapWriteMode::Auto, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
319 }; |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47491
diff
changeset
|
320 Ok(dirstate_map) |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
321 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
322 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
323 impl Node { |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
324 pub(super) fn full_path<'on_disk>( |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
325 &self, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
326 on_disk: &'on_disk [u8], |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
327 ) -> Result<&'on_disk HgPath, DirstateV2ParseError> { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
328 read_hg_path(on_disk, self.full_path) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
329 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
330 |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
331 pub(super) fn base_name_start<'on_disk>( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
332 &self, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
333 ) -> Result<usize, DirstateV2ParseError> { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
334 let start = self.base_name_start.get(); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
335 if start < self.full_path.len.get() { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
336 let start = usize::try_from(start) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
337 // u32 -> usize, could only panic on a 16-bit CPU |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
338 .expect("dirstate-v2 base_name_start out of bounds"); |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
339 Ok(start) |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
340 } else { |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
341 Err(DirstateV2ParseError::new("not enough bytes for base name")) |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
342 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
343 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
344 |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
345 pub(super) fn base_name<'on_disk>( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
346 &self, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
347 on_disk: &'on_disk [u8], |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
348 ) -> Result<&'on_disk HgPath, DirstateV2ParseError> { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
349 let full_path = self.full_path(on_disk)?; |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
350 let base_name_start = self.base_name_start()?; |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
351 Ok(HgPath::new(&full_path.as_bytes()[base_name_start..])) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
352 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
353 |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
354 pub(super) fn path<'on_disk>( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
355 &self, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
356 on_disk: &'on_disk [u8], |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
357 ) -> Result<dirstate_map::NodeKey<'on_disk>, DirstateV2ParseError> { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
358 Ok(WithBasename::from_raw_parts( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
359 Cow::Borrowed(self.full_path(on_disk)?), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
360 self.base_name_start()?, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
361 )) |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
362 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
363 |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
364 pub(super) fn has_copy_source<'on_disk>(&self) -> bool { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
365 self.copy_source.start.get() != 0 |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
366 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
367 |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
368 pub(super) fn copy_source<'on_disk>( |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
369 &self, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
370 on_disk: &'on_disk [u8], |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
371 ) -> Result<Option<&'on_disk HgPath>, DirstateV2ParseError> { |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
372 Ok(if self.has_copy_source() { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
373 Some(read_hg_path(on_disk, self.copy_source)?) |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
374 } else { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
375 None |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
376 }) |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
377 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
378 |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
379 fn flags(&self) -> Flags { |
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
380 Flags::from_bits_truncate(self.flags.get()) |
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
381 } |
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
382 |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
383 fn has_entry(&self) -> bool { |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
384 self.flags().intersects( |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
385 Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_INFO, |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
386 ) |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
387 } |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
388 |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
389 pub(super) fn node_data( |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
390 &self, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
391 ) -> Result<dirstate_map::NodeData, DirstateV2ParseError> { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
392 if self.has_entry() { |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
393 Ok(dirstate_map::NodeData::Entry(self.assume_entry()?)) |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
394 } else if let Some(mtime) = self.cached_directory_mtime()? { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
395 Ok(dirstate_map::NodeData::CachedDirectory { mtime }) |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
396 } else { |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
397 Ok(dirstate_map::NodeData::None) |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
398 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
399 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
400 |
48193
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
401 pub(super) fn cached_directory_mtime( |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
402 &self, |
320de901896a
dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents:
48192
diff
changeset
|
403 ) -> Result<Option<TruncatedTimestamp>, DirstateV2ParseError> { |
48264
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
404 // For now we do not have code to handle the absence of |
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
405 // ALL_UNKNOWN_RECORDED, so we ignore the mtime if the flag is |
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
406 // unset. |
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
407 if self.flags().contains(Flags::DIRECTORY) |
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
408 && self.flags().contains(Flags::HAS_MTIME) |
48251
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
409 && self.flags().contains(Flags::ALL_UNKNOWN_RECORDED) |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
410 { |
48501
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
411 Ok(Some(self.mtime()?)) |
48232
f7fd629ffb98
dirstate-v2: Separate HAS_FILE_MTIME and HAS_DIRECTORY_MTIME flags
Simon Sapin <simon.sapin@octobus.net>
parents:
48231
diff
changeset
|
412 } else { |
f7fd629ffb98
dirstate-v2: Separate HAS_FILE_MTIME and HAS_DIRECTORY_MTIME flags
Simon Sapin <simon.sapin@octobus.net>
parents:
48231
diff
changeset
|
413 Ok(None) |
f7fd629ffb98
dirstate-v2: Separate HAS_FILE_MTIME and HAS_DIRECTORY_MTIME flags
Simon Sapin <simon.sapin@octobus.net>
parents:
48231
diff
changeset
|
414 } |
47349
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
415 } |
7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents:
47348
diff
changeset
|
416 |
48195
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
417 fn synthesize_unix_mode(&self) -> u32 { |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
418 let file_type = if self.flags().contains(Flags::MODE_IS_SYMLINK) { |
48195
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
419 libc::S_IFLNK |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
420 } else { |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
421 libc::S_IFREG |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
422 }; |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
423 let permisions = if self.flags().contains(Flags::MODE_EXEC_PERM) { |
48195
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
424 0o755 |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
425 } else { |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
426 0o644 |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
427 }; |
48568
440972d2175d
rust: fix build errors on darwin
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
48266
diff
changeset
|
428 (file_type | permisions).into() |
48195
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
429 } |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
430 |
48501
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
431 fn mtime(&self) -> Result<TruncatedTimestamp, DirstateV2ParseError> { |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
432 let mut m: TruncatedTimestamp = self.mtime.try_into()?; |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
433 if self.flags().contains(Flags::MTIME_SECOND_AMBIGUOUS) { |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
434 m.second_ambiguous = true; |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
435 } |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
436 Ok(m) |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
437 } |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
438 |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
439 fn assume_entry(&self) -> Result<DirstateEntry, DirstateV2ParseError> { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
440 // TODO: convert through raw bits instead? |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
441 let wc_tracked = self.flags().contains(Flags::WDIR_TRACKED); |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
442 let p1_tracked = self.flags().contains(Flags::P1_TRACKED); |
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
443 let p2_info = self.flags().contains(Flags::P2_INFO); |
48250
1730b2fceaa1
dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents:
48232
diff
changeset
|
444 let mode_size = if self.flags().contains(Flags::HAS_MODE_AND_SIZE) |
1730b2fceaa1
dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents:
48232
diff
changeset
|
445 && !self.flags().contains(Flags::EXPECTED_STATE_IS_MODIFIED) |
1730b2fceaa1
dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents:
48232
diff
changeset
|
446 { |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
447 Some((self.synthesize_unix_mode(), self.size.into())) |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
448 } else { |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
449 None |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
450 }; |
48264
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
451 let mtime = if self.flags().contains(Flags::HAS_MTIME) |
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
452 && !self.flags().contains(Flags::DIRECTORY) |
48250
1730b2fceaa1
dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents:
48232
diff
changeset
|
453 && !self.flags().contains(Flags::EXPECTED_STATE_IS_MODIFIED) |
1730b2fceaa1
dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents:
48232
diff
changeset
|
454 { |
48501
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
455 Some(self.mtime()?) |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
456 } else { |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
457 None |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
458 }; |
48265
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
459 let fallback_exec = if self.flags().contains(Flags::HAS_FALLBACK_EXEC) |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
460 { |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
461 Some(self.flags().contains(Flags::FALLBACK_EXEC)) |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
462 } else { |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
463 None |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
464 }; |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
465 let fallback_symlink = |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
466 if self.flags().contains(Flags::HAS_FALLBACK_SYMLINK) { |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
467 Some(self.flags().contains(Flags::FALLBACK_SYMLINK)) |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
468 } else { |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
469 None |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
470 }; |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
471 Ok(DirstateEntry::from_v2_data(DirstateV2Data { |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
472 wc_tracked, |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
473 p1_tracked, |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
474 p2_info, |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
475 mode_size, |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
476 mtime, |
48265
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
477 fallback_exec, |
3861e3f6ad54
dirstate-v2: read the fallback value in Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48264
diff
changeset
|
478 fallback_symlink, |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
479 })) |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
480 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
481 |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
482 pub(super) fn entry( |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
483 &self, |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
484 ) -> Result<Option<DirstateEntry>, DirstateV2ParseError> { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
485 if self.has_entry() { |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
486 Ok(Some(self.assume_entry()?)) |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
487 } else { |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
488 Ok(None) |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
489 } |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
490 } |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
491 |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
492 pub(super) fn children<'on_disk>( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
493 &self, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
494 on_disk: &'on_disk [u8], |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
495 ) -> Result<&'on_disk [Node], DirstateV2ParseError> { |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
496 read_nodes(on_disk, self.children) |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
497 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
498 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
499 pub(super) fn to_in_memory_node<'on_disk>( |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
500 &self, |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
501 on_disk: &'on_disk [u8], |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
502 ) -> Result<dirstate_map::Node<'on_disk>, DirstateV2ParseError> { |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
503 Ok(dirstate_map::Node { |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
504 children: dirstate_map::ChildNodes::OnDisk( |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
505 self.children(on_disk)?, |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
506 ), |
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
507 copy_source: self.copy_source(on_disk)?.map(Cow::Borrowed), |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
508 data: self.node_data()?, |
47478
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47476
diff
changeset
|
509 descendants_with_entry_count: self |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47476
diff
changeset
|
510 .descendants_with_entry_count |
ca8121d26732
dirstate-tree: Keep a counter of descendant nodes that have an entry
Simon Sapin <simon.sapin@octobus.net>
parents:
47476
diff
changeset
|
511 .get(), |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
512 tracked_descendants_count: self.tracked_descendants_count.get(), |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
513 }) |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
514 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
515 |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
516 fn from_dirstate_entry( |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
517 entry: &DirstateEntry, |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
518 ) -> (Flags, U32Be, PackedTruncatedTimestamp) { |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
519 let DirstateV2Data { |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
520 wc_tracked, |
48254
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
521 p1_tracked, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
522 p2_info, |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
523 mode_size: mode_size_opt, |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
524 mtime: mtime_opt, |
48254
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
525 fallback_exec, |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
526 fallback_symlink, |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
527 } = entry.v2_data(); |
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
528 // TODO: convert through raw flag bits instead? |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
529 let mut flags = Flags::empty(); |
49100
38e5bb1425dd
rust-dirstate: introduce intermediate struct for dirstate-v2 data
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
530 flags.set(Flags::WDIR_TRACKED, wc_tracked); |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
531 flags.set(Flags::P1_TRACKED, p1_tracked); |
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
532 flags.set(Flags::P2_INFO, p2_info); |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
533 let size = if let Some((m, s)) = mode_size_opt { |
48568
440972d2175d
rust: fix build errors on darwin
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
48266
diff
changeset
|
534 let exec_perm = m & (libc::S_IXUSR as u32) != 0; |
440972d2175d
rust: fix build errors on darwin
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
48266
diff
changeset
|
535 let is_symlink = m & (libc::S_IFMT as u32) == libc::S_IFLNK as u32; |
48195
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
536 flags.set(Flags::MODE_EXEC_PERM, exec_perm); |
4d5a13253d34
dirstate-v2: Replace the 32-bit `mode` field with two bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48194
diff
changeset
|
537 flags.set(Flags::MODE_IS_SYMLINK, is_symlink); |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
538 flags.insert(Flags::HAS_MODE_AND_SIZE); |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
539 s.into() |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
540 } else { |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
541 0.into() |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
542 }; |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
543 let mtime = if let Some(m) = mtime_opt { |
48264
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
544 flags.insert(Flags::HAS_MTIME); |
48401
995aaacb12d7
dirstate-item: make sure we set the mtime-second-ambiguous on v2 write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
545 if m.second_ambiguous { |
995aaacb12d7
dirstate-item: make sure we set the mtime-second-ambiguous on v2 write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
546 flags.insert(Flags::MTIME_SECOND_AMBIGUOUS); |
995aaacb12d7
dirstate-item: make sure we set the mtime-second-ambiguous on v2 write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48398
diff
changeset
|
547 }; |
48260
269ff8978086
dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents:
48254
diff
changeset
|
548 m.into() |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
549 } else { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
550 PackedTruncatedTimestamp::null() |
48192
d2f760c2c91c
dirstate-v2: Separate Rust structs for Timestamp and PackedTimestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
48191
diff
changeset
|
551 }; |
48254
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
552 if let Some(f_exec) = fallback_exec { |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
553 flags.insert(Flags::HAS_FALLBACK_EXEC); |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
554 if f_exec { |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
555 flags.insert(Flags::FALLBACK_EXEC); |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
556 } |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
557 } |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
558 if let Some(f_symlink) = fallback_symlink { |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
559 flags.insert(Flags::HAS_FALLBACK_SYMLINK); |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
560 if f_symlink { |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
561 flags.insert(Flags::FALLBACK_SYMLINK); |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
562 } |
b874e8d81a98
dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48253
diff
changeset
|
563 } |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
564 (flags, size, mtime) |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
565 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
566 } |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
567 |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
568 fn read_hg_path( |
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
569 on_disk: &[u8], |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
570 slice: PathSlice, |
47337
0654b3b3d2b5
dirstate-v2: Parse the dirstate lazily, with copy-on-write nodes
Simon Sapin <simon.sapin@octobus.net>
parents:
47336
diff
changeset
|
571 ) -> Result<&HgPath, DirstateV2ParseError> { |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
572 read_slice(on_disk, slice.start, slice.len.get()).map(HgPath::new) |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
573 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
574 |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
575 fn read_nodes( |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
576 on_disk: &[u8], |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
577 slice: ChildNodes, |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
578 ) -> Result<&[Node], DirstateV2ParseError> { |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
579 read_slice(on_disk, slice.start, slice.len.get()) |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
580 } |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
581 |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
582 fn read_slice<T, Len>( |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
583 on_disk: &[u8], |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
584 start: Offset, |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
585 len: Len, |
47334
18b3060fe598
dirstate-v2: Add a zero-size error type for dirstate v2 parse errors
Simon Sapin <simon.sapin@octobus.net>
parents:
47333
diff
changeset
|
586 ) -> Result<&[T], DirstateV2ParseError> |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
587 where |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
588 T: BytesCast, |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
589 Len: TryInto<usize>, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
590 { |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
591 // Either `usize::MAX` would result in "out of bounds" error since a single |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
592 // `&[u8]` cannot occupy the entire addess space. |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
593 let start = start.get().try_into().unwrap_or(std::usize::MAX); |
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
594 let len = len.try_into().unwrap_or(std::usize::MAX); |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
595 let bytes = match on_disk.get(start..) { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
596 Some(bytes) => bytes, |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
597 None => { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
598 return Err(DirstateV2ParseError::new( |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
599 "not enough bytes from disk", |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
600 )) |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
601 } |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
602 }; |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
603 T::slice_from_bytes(bytes, len) |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
604 .map_err(|e| { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
605 DirstateV2ParseError::new(format!("when reading a slice, {}", e)) |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
606 }) |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
607 .map(|(slice, _rest)| slice) |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
608 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
609 |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
610 pub(crate) fn for_each_tracked_path<'on_disk>( |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
611 on_disk: &'on_disk [u8], |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
612 metadata: &[u8], |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
613 mut f: impl FnMut(&'on_disk HgPath), |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
614 ) -> Result<(), DirstateV2ParseError> { |
49373
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
615 let (meta, _) = TreeMetadata::from_bytes(metadata).map_err(|e| { |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
616 DirstateV2ParseError::new(format!("when parsing tree metadata, {}", e)) |
f8ec7b16c98f
rust: add message to `DirstateV2ParseError` to give some context
Raphaël Gomès <rgomes@octobus.net>
parents:
49365
diff
changeset
|
617 })?; |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
618 fn recur<'on_disk>( |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
619 on_disk: &'on_disk [u8], |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
620 nodes: ChildNodes, |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
621 f: &mut impl FnMut(&'on_disk HgPath), |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
622 ) -> Result<(), DirstateV2ParseError> { |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
623 for node in read_nodes(on_disk, nodes)? { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
624 if let Some(entry) = node.entry()? { |
49136
3f5e207f78be
rust: use `entry.tracked()` directly
Raphaël Gomès <rgomes@octobus.net>
parents:
49125
diff
changeset
|
625 if entry.tracked() { |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
626 f(node.full_path(on_disk)?) |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
627 } |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
628 } |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
629 recur(on_disk, node.children, f)? |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
630 } |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
631 Ok(()) |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
632 } |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
633 recur(on_disk, meta.root_nodes, &mut f) |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
634 } |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47351
diff
changeset
|
635 |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
636 /// Returns new data and metadata, together with whether that data should be |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
637 /// appended to the existing data file whose content is at |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
638 /// `dirstate_map.on_disk` (true), instead of written to a new data file |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
639 /// (false), and the previous size of data on disk. |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
640 pub(super) fn write( |
48416
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48402
diff
changeset
|
641 dirstate_map: &DirstateMap, |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
642 write_mode: DirstateMapWriteMode, |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
643 ) -> Result<(Vec<u8>, TreeMetadata, bool, usize), DirstateError> { |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
644 let append = match write_mode { |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
645 DirstateMapWriteMode::Auto => dirstate_map.write_should_append(), |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
646 DirstateMapWriteMode::ForceNewDataFile => false, |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Raphaël Gomès <rgomes@octobus.net>
parents:
50221
diff
changeset
|
647 DirstateMapWriteMode::ForceAppend => true, |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50179
diff
changeset
|
648 }; |
50179
f2e13d8d30e0
rust-dirstate: trace append/no append to help debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
649 if append { |
f2e13d8d30e0
rust-dirstate: trace append/no append to help debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
650 log::trace!("appending to the dirstate data file"); |
f2e13d8d30e0
rust-dirstate: trace append/no append to help debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
651 } else { |
f2e13d8d30e0
rust-dirstate: trace append/no append to help debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
652 log::trace!("creating new dirstate data file"); |
f2e13d8d30e0
rust-dirstate: trace append/no append to help debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
49373
diff
changeset
|
653 } |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
654 |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
655 // This ignores the space for paths, and for nodes without an entry. |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
656 // TODO: better estimate? Skip the `Vec` and write to a file directly? |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
657 let size_guess = std::mem::size_of::<Node>() |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
658 * dirstate_map.nodes_with_entry_count as usize; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
659 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
660 let mut writer = Writer { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
661 dirstate_map, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
662 append, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
663 out: Vec::with_capacity(size_guess), |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
664 }; |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
665 |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
666 let root_nodes = writer.write_nodes(dirstate_map.root.as_ref())?; |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
667 |
49156
09984dc70352
rust-dirstate-v2: fix the unused bytes counter when rewriting the dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
668 let unreachable_bytes = if append { |
09984dc70352
rust-dirstate-v2: fix the unused bytes counter when rewriting the dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
669 dirstate_map.unreachable_bytes |
09984dc70352
rust-dirstate-v2: fix the unused bytes counter when rewriting the dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
670 } else { |
09984dc70352
rust-dirstate-v2: fix the unused bytes counter when rewriting the dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
671 0 |
09984dc70352
rust-dirstate-v2: fix the unused bytes counter when rewriting the dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
672 }; |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47681
diff
changeset
|
673 let meta = TreeMetadata { |
47676
096ee2e260a3
dirstate-v2: Rename Header to Root, move it to the end of the data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
674 root_nodes, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
675 nodes_with_entry_count: dirstate_map.nodes_with_entry_count.into(), |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
676 nodes_with_copy_source_count: dirstate_map |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
677 .nodes_with_copy_source_count |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
678 .into(), |
49156
09984dc70352
rust-dirstate-v2: fix the unused bytes counter when rewriting the dirstate
Raphaël Gomès <rgomes@octobus.net>
parents:
49145
diff
changeset
|
679 unreachable_bytes: unreachable_bytes.into(), |
47684
852262e2e7d9
dirstate-v2: Reserve a few bytes of space for future extensions
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
680 unused: [0; 4], |
47409
0ef8231e413f
dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
681 ignore_patterns_hash: dirstate_map.ignore_patterns_hash, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
682 }; |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents:
48569
diff
changeset
|
683 Ok((writer.out, meta, append, dirstate_map.old_data_size)) |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
684 } |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
685 |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
686 struct Writer<'dmap, 'on_disk> { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
687 dirstate_map: &'dmap DirstateMap<'on_disk>, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
688 append: bool, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
689 out: Vec<u8>, |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
690 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
691 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
692 impl Writer<'_, '_> { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
693 fn write_nodes( |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
694 &mut self, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
695 nodes: dirstate_map::ChildNodesRef, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
696 ) -> Result<ChildNodes, DirstateError> { |
47679
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
697 // Reuse already-written nodes if possible |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
698 if self.append { |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
699 if let dirstate_map::ChildNodesRef::OnDisk(nodes_slice) = nodes { |
47680
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
700 let start = self.on_disk_offset_of(nodes_slice).expect( |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
701 "dirstate-v2 OnDisk nodes not found within on_disk", |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
702 ); |
47679
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
703 let len = child_nodes_len_from_usize(nodes_slice.len()); |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
704 return Ok(ChildNodes { start, len }); |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
705 } |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
706 } |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
707 |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
708 // `dirstate_map::ChildNodes::InMemory` contains a `HashMap` which has |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
709 // undefined iteration order. Sort to enable binary search in the |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
710 // written file. |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
711 let nodes = nodes.sorted(); |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
712 let nodes_len = nodes.len(); |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
713 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
714 // First accumulate serialized nodes in a `Vec` |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
715 let mut on_disk_nodes = Vec::with_capacity(nodes_len); |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
716 for node in nodes { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
717 let children = |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
718 self.write_nodes(node.children(self.dirstate_map.on_disk)?)?; |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
719 let full_path = node.full_path(self.dirstate_map.on_disk)?; |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
720 let full_path = self.write_path(full_path.as_bytes()); |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
721 let copy_source = if let Some(source) = |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
722 node.copy_source(self.dirstate_map.on_disk)? |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
723 { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
724 self.write_path(source.as_bytes()) |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
725 } else { |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
726 PathSlice { |
47336
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
727 start: 0.into(), |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
728 len: 0.into(), |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
729 } |
8d0260d0dbc9
dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
730 }; |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
731 on_disk_nodes.push(match node { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
732 NodeRef::InMemory(path, node) => { |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
733 let (flags, size, mtime) = match &node.data { |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
734 dirstate_map::NodeData::Entry(entry) => { |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
735 Node::from_dirstate_entry(entry) |
48139
ab5a7fdbf75c
dirstate-v2: Store a bitfield on disk instead of v1-like state
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
736 } |
48501
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
737 dirstate_map::NodeData::CachedDirectory { mtime } => { |
48251
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
738 // we currently never set a mtime if unknown file |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
739 // are present. |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
740 // So if we have a mtime for a directory, we know |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
741 // they are no unknown |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
742 // files and we |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
743 // blindly set ALL_UNKNOWN_RECORDED. |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
744 // |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
745 // We never set ALL_IGNORED_RECORDED since we |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
746 // don't track that case |
dfc5a505ddc5
dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48250
diff
changeset
|
747 // currently. |
48501
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
748 let mut flags = Flags::DIRECTORY |
48264
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
749 | Flags::HAS_MTIME |
48501
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
750 | Flags::ALL_UNKNOWN_RECORDED; |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
751 if mtime.second_ambiguous { |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
752 flags.insert(Flags::MTIME_SECOND_AMBIGUOUS) |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
753 } |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
754 (flags, 0.into(), (*mtime).into()) |
4afb9627dc77
dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents:
48421
diff
changeset
|
755 } |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
756 dirstate_map::NodeData::None => ( |
48264
bb240915f69f
dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48263
diff
changeset
|
757 Flags::DIRECTORY, |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
758 0.into(), |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
759 PackedTruncatedTimestamp::null(), |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
760 ), |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
761 }; |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
762 Node { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
763 children, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
764 copy_source, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
765 full_path, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
766 base_name_start: u16::try_from(path.base_name_start()) |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
767 // Could only panic for paths over 64 KiB |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
768 .expect("dirstate-v2 path length overflow") |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
769 .into(), |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
770 descendants_with_entry_count: node |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
771 .descendants_with_entry_count |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
772 .into(), |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
773 tracked_descendants_count: node |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
774 .tracked_descendants_count |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
775 .into(), |
48231
0524c1359bfc
dirstate-v2: Extend node flags to 16 bits
Simon Sapin <simon.sapin@octobus.net>
parents:
48221
diff
changeset
|
776 flags: flags.bits().into(), |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
777 size, |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
778 mtime, |
47333
69530e5d4fe5
dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents:
47331
diff
changeset
|
779 } |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
780 } |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
781 NodeRef::OnDisk(node) => Node { |
47348
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
782 children, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
783 copy_source, |
a4de570e61fa
dirstate-v2: Allow tree nodes without an entry to store a timestamp
Simon Sapin <simon.sapin@octobus.net>
parents:
47337
diff
changeset
|
784 full_path, |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
785 ..*node |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
786 }, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
787 }) |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
788 } |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
789 // … so we can write them contiguously, after writing everything else |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
790 // they refer to. |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
791 let start = self.current_offset(); |
47679
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
792 let len = child_nodes_len_from_usize(nodes_len); |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
793 self.out.extend(on_disk_nodes.as_bytes()); |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
794 Ok(ChildNodes { start, len }) |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
795 } |
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
796 |
47680
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
797 /// If the given slice of items is within `on_disk`, returns its offset |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
798 /// from the start of `on_disk`. |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
799 fn on_disk_offset_of<T>(&self, slice: &[T]) -> Option<Offset> |
47679
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
800 where |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
801 T: BytesCast, |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
802 { |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
803 fn address_range(slice: &[u8]) -> std::ops::RangeInclusive<usize> { |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
804 let start = slice.as_ptr() as usize; |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
805 let end = start + slice.len(); |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
806 start..=end |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
807 } |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
808 let slice_addresses = address_range(slice.as_bytes()); |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
809 let on_disk_addresses = address_range(self.dirstate_map.on_disk); |
47680
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
810 if on_disk_addresses.contains(slice_addresses.start()) |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
811 && on_disk_addresses.contains(slice_addresses.end()) |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
812 { |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
813 let offset = slice_addresses.start() - on_disk_addresses.start(); |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
814 Some(offset_from_usize(offset)) |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
815 } else { |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
816 None |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
817 } |
47679
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
818 } |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
819 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
820 fn current_offset(&mut self) -> Offset { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
821 let mut offset = self.out.len(); |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
822 if self.append { |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
823 offset += self.dirstate_map.on_disk.len() |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
824 } |
47679
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
825 offset_from_usize(offset) |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
826 } |
47677
da1c0cd68d53
dirstate-v2: shrink on-disk path lengths to 16-bits
Simon Sapin <simon.sapin@octobus.net>
parents:
47676
diff
changeset
|
827 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
828 fn write_path(&mut self, slice: &[u8]) -> PathSlice { |
47680
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
829 let len = path_len_from_usize(slice.len()); |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
830 // Reuse an already-written path if possible |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
831 if self.append { |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
832 if let Some(start) = self.on_disk_offset_of(slice) { |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
833 return PathSlice { start, len }; |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
834 } |
a8b0f29dc0d7
dirstate-v2: Reuse existing paths when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47679
diff
changeset
|
835 } |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
836 let start = self.current_offset(); |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
837 self.out.extend(slice.as_bytes()); |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
838 PathSlice { start, len } |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47677
diff
changeset
|
839 } |
47283
2a9ddc8094c7
dirstate-v2: Change the on-disk format to be tree-shaped
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
840 } |
47679
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
841 |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
842 fn offset_from_usize(x: usize) -> Offset { |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
843 u32::try_from(x) |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
844 // Could only panic for a dirstate file larger than 4 GiB |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
845 .expect("dirstate-v2 offset overflow") |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
846 .into() |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
847 } |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
848 |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
849 fn child_nodes_len_from_usize(x: usize) -> Size { |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
850 u32::try_from(x) |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
851 // Could only panic with over 4 billion nodes |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
852 .expect("dirstate-v2 slice length overflow") |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
853 .into() |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
854 } |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
855 |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
856 fn path_len_from_usize(x: usize) -> PathSize { |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
857 u16::try_from(x) |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
858 // Could only panic for paths over 64 KiB |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
859 .expect("dirstate-v2 path length overflow") |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
860 .into() |
731286dc5321
dirstate-v2: Reuse existing nodes when appending to a data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
861 } |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
862 |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
863 impl From<TruncatedTimestamp> for PackedTruncatedTimestamp { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
864 fn from(timestamp: TruncatedTimestamp) -> Self { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
865 Self { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
866 truncated_seconds: timestamp.truncated_seconds().into(), |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
867 nanoseconds: timestamp.nanoseconds().into(), |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
868 } |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
869 } |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
870 } |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
871 |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
872 impl TryFrom<PackedTruncatedTimestamp> for TruncatedTimestamp { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
873 type Error = DirstateV2ParseError; |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
874 |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
875 fn try_from( |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
876 timestamp: PackedTruncatedTimestamp, |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
877 ) -> Result<Self, Self::Error> { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
878 Self::from_already_truncated( |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
879 timestamp.truncated_seconds.get(), |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
880 timestamp.nanoseconds.get(), |
48398
111098af6356
dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48266
diff
changeset
|
881 false, |
48219
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
882 ) |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
883 } |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
884 } |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
885 impl PackedTruncatedTimestamp { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
886 fn null() -> Self { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
887 Self { |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
888 truncated_seconds: 0.into(), |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
889 nanoseconds: 0.into(), |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
890 } |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
891 } |
308d9c245337
dirstate-v2: Add storage space for nanoseconds precision in file mtimes
Simon Sapin <simon.sapin@octobus.net>
parents:
48196
diff
changeset
|
892 } |