Mercurial > hg
annotate rust/hg-core/src/revlog/mod.rs @ 52169:84b5802ba7d3
rust: populate mmap by default if available
See 522b4d729e89edc76544fa549ed36de4aea0b7fb for more details.
Background population to follow in a later patch.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 26 Sep 2024 13:55:26 +0200 |
parents | e01e84e5e426 |
children | 7be39c5110c9 |
rev | line source |
---|---|
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
1 // Copyright 2018-2023 Georges Racinet <georges.racinet@octobus.net> |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
2 // and Mercurial contributors |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
3 // |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
4 // This software may be used and distributed according to the terms of the |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
5 // GNU General Public License version 2 or any later version. |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
6 //! Mercurial concepts for handling revision history |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
7 |
44143
7f86426fdd2c
rust-node: binary Node ID and conversion utilities
Georges Racinet <georges.racinet@octobus.net>
parents:
44142
diff
changeset
|
8 pub mod node; |
44142
63db6657d280
rust-nodemap: building blocks for nodetree structures
Georges Racinet <georges.racinet@octobus.net>
parents:
44088
diff
changeset
|
9 pub mod nodemap; |
46090
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
45539
diff
changeset
|
10 mod nodemap_docket; |
45539
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45533
diff
changeset
|
11 pub mod path_encode; |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
12 use inner_revlog::CoreRevisionBuffer; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
13 use inner_revlog::InnerRevlog; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
14 use inner_revlog::RevisionBuffer; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
15 use memmap2::MmapOptions; |
46431
645ee7225fab
rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef
Simon Sapin <simon.sapin@octobus.net>
parents:
46428
diff
changeset
|
16 pub use node::{FromHexError, Node, NodePrefix}; |
52160
039b7caeb4d9
rust-revlog: introduce an `options` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52159
diff
changeset
|
17 use options::RevlogOpenOptions; |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
18 pub mod changelog; |
52158
0744248cc541
rust-revlog: add compression helpers
Raphaël Gomès <rgomes@octobus.net>
parents:
52060
diff
changeset
|
19 pub mod compression; |
52159
426696af24d3
rust-revlog: add file IO helpers
Raphaël Gomès <rgomes@octobus.net>
parents:
52158
diff
changeset
|
20 pub mod file_io; |
47961
4d2a5ca060e3
rust: Add a Filelog struct that wraps Revlog
Simon Sapin <simon.sapin@octobus.net>
parents:
46821
diff
changeset
|
21 pub mod filelog; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
22 pub mod index; |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
23 pub mod inner_revlog; |
45533
89ac95bd4993
hg-core: add `Manifest` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45532
diff
changeset
|
24 pub mod manifest; |
52160
039b7caeb4d9
rust-revlog: introduce an `options` module
Raphaël Gomès <rgomes@octobus.net>
parents:
52159
diff
changeset
|
25 pub mod options; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
26 pub mod patch; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
27 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
28 use std::borrow::Cow; |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
29 use std::io::ErrorKind; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
30 use std::io::Read; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
31 use std::ops::Deref; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
32 use std::path::Path; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
33 |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
34 use self::node::NULL_NODE; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
35 use self::nodemap_docket::NodeMapDocket; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
36 use super::index::Index; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
37 use super::nodemap::{NodeMap, NodeMapError}; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
38 use crate::errors::HgError; |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
39 use crate::errors::IoResultExt; |
51865
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
40 use crate::exit_codes; |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
41 use crate::vfs::Vfs; |
51868 | 42 use crate::vfs::VfsImpl; |
44142
63db6657d280
rust-nodemap: building blocks for nodetree structures
Georges Racinet <georges.racinet@octobus.net>
parents:
44088
diff
changeset
|
43 |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
44 /// As noted in revlog.c, revision numbers are actually encoded in |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
45 /// 4 bytes, and are liberally converted to ints, whence the i32 |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
46 pub type BaseRevision = i32; |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
47 |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
48 /// Mercurial revision numbers |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
49 /// In contrast to the more general [`UncheckedRevision`], these are "checked" |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
50 /// in the sense that they should only be used for revisions that are |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
51 /// valid for a given index (i.e. in bounds). |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
52 #[derive( |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
53 Debug, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
54 derive_more::Display, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
55 Clone, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
56 Copy, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
57 Hash, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
58 PartialEq, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
59 Eq, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
60 PartialOrd, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
61 Ord, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
62 )] |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
63 pub struct Revision(pub BaseRevision); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
64 |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
65 impl format_bytes::DisplayBytes for Revision { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
66 fn display_bytes( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
67 &self, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
68 output: &mut dyn std::io::Write, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
69 ) -> std::io::Result<()> { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
70 self.0.display_bytes(output) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
71 } |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
72 } |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
73 |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
74 /// Unchecked Mercurial revision numbers. |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
75 /// |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
76 /// Values of this type have no guarantee of being a valid revision number |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
77 /// in any context. Use method `check_revision` to get a valid revision within |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
78 /// the appropriate index object. |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
79 #[derive( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
80 Debug, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
81 derive_more::Display, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
82 Clone, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
83 Copy, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
84 Hash, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
85 PartialEq, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
86 Eq, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
87 PartialOrd, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
88 Ord, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
89 )] |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
90 pub struct UncheckedRevision(pub BaseRevision); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
91 |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
92 impl format_bytes::DisplayBytes for UncheckedRevision { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
93 fn display_bytes( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
94 &self, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
95 output: &mut dyn std::io::Write, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
96 ) -> std::io::Result<()> { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
97 self.0.display_bytes(output) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
98 } |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
99 } |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
100 |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
101 impl From<Revision> for UncheckedRevision { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
102 fn from(value: Revision) -> Self { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
103 Self(value.0) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
104 } |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
105 } |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
106 |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
107 impl From<BaseRevision> for UncheckedRevision { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
108 fn from(value: BaseRevision) -> Self { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
109 Self(value) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
110 } |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
111 } |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
112 |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
113 /// Marker expressing the absence of a parent |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
114 /// |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
115 /// Independently of the actual representation, `NULL_REVISION` is guaranteed |
44088
b3ec1ea95ee6
rust-core: fix typo in comment
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents:
44005
diff
changeset
|
116 /// to be smaller than all existing revisions. |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
117 pub const NULL_REVISION: Revision = Revision(-1); |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
118 |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
119 /// Same as `mercurial.node.wdirrev` |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
120 /// |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
121 /// This is also equal to `i32::max_value()`, but it's better to spell |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
122 /// it out explicitely, same as in `mercurial.node` |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
123 #[allow(clippy::unreadable_literal)] |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
124 pub const WORKING_DIRECTORY_REVISION: UncheckedRevision = |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
125 UncheckedRevision(0x7fffffff); |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
126 |
46821
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46431
diff
changeset
|
127 pub const WORKING_DIRECTORY_HEX: &str = |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46431
diff
changeset
|
128 "ffffffffffffffffffffffffffffffffffffffff"; |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46431
diff
changeset
|
129 |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
130 /// The simplest expression of what we need of Mercurial DAGs. |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
131 pub trait Graph { |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
132 /// Return the two parents of the given `Revision`. |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
133 /// |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
134 /// Each of the parents can be independently `NULL_REVISION` |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
135 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>; |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
136 } |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
137 |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
138 #[derive(Clone, Debug, PartialEq)] |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
139 pub enum GraphError { |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
140 ParentOutOfRange(Revision), |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
141 } |
44181
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
142 |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
143 impl std::fmt::Display for GraphError { |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
144 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
145 match self { |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
146 GraphError::ParentOutOfRange(revision) => { |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
147 write!(f, "parent out of range ({})", revision) |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
148 } |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
149 } |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
150 } |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
151 } |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
152 |
51619
b08c5fbe0e70
rust: blanket implementation of Graph for Graph references
Georges Racinet <georges.racinet@octobus.net>
parents:
51256
diff
changeset
|
153 impl<T: Graph> Graph for &T { |
b08c5fbe0e70
rust: blanket implementation of Graph for Graph references
Georges Racinet <georges.racinet@octobus.net>
parents:
51256
diff
changeset
|
154 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
b08c5fbe0e70
rust: blanket implementation of Graph for Graph references
Georges Racinet <georges.racinet@octobus.net>
parents:
51256
diff
changeset
|
155 (*self).parents(rev) |
b08c5fbe0e70
rust: blanket implementation of Graph for Graph references
Georges Racinet <georges.racinet@octobus.net>
parents:
51256
diff
changeset
|
156 } |
b08c5fbe0e70
rust: blanket implementation of Graph for Graph references
Georges Racinet <georges.racinet@octobus.net>
parents:
51256
diff
changeset
|
157 } |
b08c5fbe0e70
rust: blanket implementation of Graph for Graph references
Georges Racinet <georges.racinet@octobus.net>
parents:
51256
diff
changeset
|
158 |
44181
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
159 /// The Mercurial Revlog Index |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
160 /// |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
161 /// This is currently limited to the minimal interface that is needed for |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
162 /// the [`nodemap`](nodemap/index.html) module |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
163 pub trait RevlogIndex { |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
164 /// Total number of Revisions referenced in this index |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
165 fn len(&self) -> usize; |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
166 |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
167 fn is_empty(&self) -> bool { |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
168 self.len() == 0 |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
169 } |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
170 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
171 /// Return a reference to the Node or `None` for `NULL_REVISION` |
44181
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
172 fn node(&self, rev: Revision) -> Option<&Node>; |
50974
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
173 |
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
174 /// Return a [`Revision`] if `rev` is a valid revision number for this |
51203
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
175 /// index. |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
176 /// |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
177 /// [`NULL_REVISION`] is considered to be valid. |
51256
83de5a06f6eb
rust-index: allow inlining `check_revision` across crates
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
178 #[inline(always)] |
50974
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
179 fn check_revision(&self, rev: UncheckedRevision) -> Option<Revision> { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
180 let rev = rev.0; |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
181 |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
182 if rev == NULL_REVISION.0 || (rev >= 0 && (rev as usize) < self.len()) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
183 { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
184 Some(Revision(rev)) |
50974
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
185 } else { |
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
186 None |
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
187 } |
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
188 } |
44181
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
189 } |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
190 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
191 const REVISION_FLAG_CENSORED: u16 = 1 << 15; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
192 const REVISION_FLAG_ELLIPSIS: u16 = 1 << 14; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
193 const REVISION_FLAG_EXTSTORED: u16 = 1 << 13; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
194 const REVISION_FLAG_HASCOPIESINFO: u16 = 1 << 12; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
195 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
196 // Keep this in sync with REVIDX_KNOWN_FLAGS in |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
197 // mercurial/revlogutils/flagutil.py |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
198 const REVIDX_KNOWN_FLAGS: u16 = REVISION_FLAG_CENSORED |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
199 | REVISION_FLAG_ELLIPSIS |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
200 | REVISION_FLAG_EXTSTORED |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
201 | REVISION_FLAG_HASCOPIESINFO; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
202 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
203 const NULL_REVLOG_ENTRY_FLAGS: u16 = 0; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
204 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
205 #[derive(Debug, derive_more::From, derive_more::Display)] |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
206 pub enum RevlogError { |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
207 #[display(fmt = "invalid revision identifier: {}", "_0")] |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
208 InvalidRevision(String), |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
209 /// Working directory is not supported |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
210 WDirUnsupported, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
211 /// Found more than one entry whose ID match the requested prefix |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
212 AmbiguousPrefix, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
213 #[from] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
214 Other(HgError), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
215 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
216 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
217 impl From<NodeMapError> for RevlogError { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
218 fn from(error: NodeMapError) -> Self { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
219 match error { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
220 NodeMapError::MultipleResults => RevlogError::AmbiguousPrefix, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
221 NodeMapError::RevisionNotInIndex(rev) => RevlogError::corrupted( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
222 format!("nodemap point to revision {} not in index", rev), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
223 ), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
224 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
225 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
226 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
227 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
228 fn corrupted<S: AsRef<str>>(context: S) -> HgError { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
229 HgError::corrupted(format!("corrupted revlog, {}", context.as_ref())) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
230 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
231 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
232 impl RevlogError { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
233 fn corrupted<S: AsRef<str>>(context: S) -> Self { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
234 RevlogError::Other(corrupted(context)) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
235 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
236 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
237 |
51867
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Raphaël Gomès <rgomes@octobus.net>
parents:
51866
diff
changeset
|
238 #[derive(derive_more::Display, Debug, Copy, Clone, PartialEq, Eq)] |
51865
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
239 pub enum RevlogType { |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
240 Changelog, |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
241 Manifestlog, |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
242 Filelog, |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
243 } |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
244 |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
245 impl TryFrom<usize> for RevlogType { |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
246 type Error = HgError; |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
247 |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
248 fn try_from(value: usize) -> Result<Self, Self::Error> { |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
249 match value { |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
250 1001 => Ok(Self::Changelog), |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
251 1002 => Ok(Self::Manifestlog), |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
252 1003 => Ok(Self::Filelog), |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
253 t => Err(HgError::abort( |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
254 format!("Unknown revlog type {}", t), |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
255 exit_codes::ABORT, |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
256 None, |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
257 )), |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
258 } |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
259 } |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
260 } |
0604673428b7
rust-revlog: add revlog-specific config objects
Raphaël Gomès <rgomes@octobus.net>
parents:
51623
diff
changeset
|
261 |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
262 pub struct Revlog { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
263 inner: InnerRevlog, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
264 /// When present on disk: the persistent nodemap for this revlog |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
265 nodemap: Option<nodemap::NodeTree>, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
266 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
267 |
50978
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
268 impl Graph for Revlog { |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
269 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
270 self.index().parents(rev) |
50978
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
271 } |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
272 } |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
273 impl Revlog { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
274 /// Open a revlog index file. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
275 /// |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
276 /// It will also open the associated data file if index and data are not |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
277 /// interleaved. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
278 pub fn open( |
51868 | 279 // Todo use the `Vfs` trait here once we create a function for mmap |
280 store_vfs: &VfsImpl, | |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
281 index_path: impl AsRef<Path>, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
282 data_path: Option<&Path>, |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
283 options: RevlogOpenOptions, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
284 ) -> Result<Self, HgError> { |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
285 Self::open_gen(store_vfs, index_path, data_path, options, None) |
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
286 } |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
287 |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
288 fn index(&self) -> &Index { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
289 &self.inner.index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
290 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
291 |
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
292 fn open_gen( |
51868 | 293 // Todo use the `Vfs` trait here once we create a function for mmap |
294 store_vfs: &VfsImpl, | |
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
295 index_path: impl AsRef<Path>, |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
296 data_path: Option<&Path>, |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
297 options: RevlogOpenOptions, |
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
298 nodemap_for_test: Option<nodemap::NodeTree>, |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
299 ) -> Result<Self, HgError> { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
300 let index_path = index_path.as_ref(); |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
301 let index = open_index(store_vfs, index_path, options)?; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
302 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
303 let default_data_path = index_path.with_extension("d"); |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
304 let data_path = data_path.unwrap_or(&default_data_path); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
305 |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
306 let nodemap = if index.is_inline() || !options.use_nodemap { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
307 None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
308 } else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
309 NodeMapDocket::read_from_file(store_vfs, index_path)?.map( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
310 |(docket, data)| { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
311 nodemap::NodeTree::load_bytes( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
312 Box::new(data), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
313 docket.data_length, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
314 ) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
315 }, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
316 ) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
317 }; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
318 |
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
319 let nodemap = nodemap_for_test.or(nodemap); |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
320 |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
321 Ok(Revlog { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
322 inner: InnerRevlog::new( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
323 Box::new(store_vfs.clone()), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
324 index, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
325 index_path.to_path_buf(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
326 data_path.to_path_buf(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
327 options.data_config, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
328 options.delta_config, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
329 options.feature_config, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
330 ), |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
331 nodemap, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
332 }) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
333 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
334 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
335 /// Return number of entries of the `Revlog`. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
336 pub fn len(&self) -> usize { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
337 self.index().len() |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
338 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
339 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
340 /// Returns `true` if the `Revlog` has zero `entries`. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
341 pub fn is_empty(&self) -> bool { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
342 self.index().is_empty() |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
343 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
344 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
345 /// Returns the node ID for the given revision number, if it exists in this |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
346 /// revlog |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
347 pub fn node_from_rev(&self, rev: UncheckedRevision) -> Option<&Node> { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
348 if rev == NULL_REVISION.into() { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
349 return Some(&NULL_NODE); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
350 } |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
351 let rev = self.index().check_revision(rev)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
352 Some(self.index().get_entry(rev)?.hash()) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
353 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
354 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
355 /// Return the revision number for the given node ID, if it exists in this |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
356 /// revlog |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
357 pub fn rev_from_node( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
358 &self, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
359 node: NodePrefix, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
360 ) -> Result<Revision, RevlogError> { |
50985
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
361 if let Some(nodemap) = &self.nodemap { |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
362 nodemap |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
363 .find_bin(self.index(), node)? |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
364 .ok_or(RevlogError::InvalidRevision(format!("{:x}", node))) |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
365 } else { |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
366 self.rev_from_node_no_persistent_nodemap(node) |
50985
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
367 } |
50743
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
368 } |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
369 |
50743
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
370 /// Same as `rev_from_node`, without using a persistent nodemap |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
371 /// |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
372 /// This is used as fallback when a persistent nodemap is not present. |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
373 /// This happens when the persistent-nodemap experimental feature is not |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
374 /// enabled, or for small revlogs. |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
375 fn rev_from_node_no_persistent_nodemap( |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
376 &self, |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
377 node: NodePrefix, |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
378 ) -> Result<Revision, RevlogError> { |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
379 // Linear scan of the revlog |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
380 // TODO: consider building a non-persistent nodemap in memory to |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
381 // optimize these cases. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
382 let mut found_by_prefix = None; |
50993
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
383 for rev in (-1..self.len() as BaseRevision).rev() { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
384 let rev = Revision(rev as BaseRevision); |
50993
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
385 let candidate_node = if rev == Revision(-1) { |
50985
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
386 NULL_NODE |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
387 } else { |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
388 let index_entry = |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
389 self.index().get_entry(rev).ok_or_else(|| { |
50985
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
390 HgError::corrupted( |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
391 "revlog references a revision not in the index", |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
392 ) |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
393 })?; |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
394 *index_entry.hash() |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
395 }; |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
396 if node == candidate_node { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
397 return Ok(rev); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
398 } |
50985
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
399 if node.is_prefix_of(&candidate_node) { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
400 if found_by_prefix.is_some() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
401 return Err(RevlogError::AmbiguousPrefix); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
402 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
403 found_by_prefix = Some(rev) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
404 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
405 } |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
406 found_by_prefix |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51868
diff
changeset
|
407 .ok_or(RevlogError::InvalidRevision(format!("{:x}", node))) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
408 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
409 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
410 /// Returns whether the given revision exists in this revlog. |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
411 pub fn has_rev(&self, rev: UncheckedRevision) -> bool { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
412 self.index().check_revision(rev).is_some() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
413 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
414 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
415 pub fn get_entry_for_checked_rev( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
416 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
417 rev: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
418 ) -> Result<RevlogEntry, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
419 self.inner.get_entry_for_checked_rev(rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
420 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
421 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
422 pub fn get_entry( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
423 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
424 rev: UncheckedRevision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
425 ) -> Result<RevlogEntry, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
426 self.inner.get_entry(rev) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
427 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
428 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
429 /// Return the full data associated to a revision. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
430 /// |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
431 /// All entries required to build the final data out of deltas will be |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
432 /// retrieved as needed, and the deltas will be applied to the inital |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
433 /// snapshot to rebuild the final data. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
434 pub fn get_rev_data( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
435 &self, |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
436 rev: UncheckedRevision, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
437 ) -> Result<Cow<[u8]>, RevlogError> { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
438 if rev == NULL_REVISION.into() { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
439 return Ok(Cow::Borrowed(&[])); |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
440 }; |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
441 self.get_entry(rev)?.data() |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
442 } |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
443 |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
444 /// [`Self::get_rev_data`] for checked revisions. |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
445 pub fn get_rev_data_for_checked_rev( |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
446 &self, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
447 rev: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
448 ) -> Result<Cow<[u8]>, RevlogError> { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
449 if rev == NULL_REVISION { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
450 return Ok(Cow::Borrowed(&[])); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
451 }; |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
452 self.get_entry_for_checked_rev(rev)?.data() |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
453 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
454 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
455 /// Check the hash of some given data against the recorded hash. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
456 pub fn check_hash( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
457 &self, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
458 p1: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
459 p2: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
460 expected: &[u8], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
461 data: &[u8], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
462 ) -> bool { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
463 self.inner.check_hash(p1, p2, expected, data) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
464 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
465 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
466 /// Build the full data of a revision out its snapshot |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
467 /// and its deltas. |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
468 fn build_data_from_deltas<T>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
469 buffer: &mut dyn RevisionBuffer<Target = T>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
470 snapshot: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
471 deltas: &[impl AsRef<[u8]>], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
472 ) -> Result<(), RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
473 if deltas.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
474 buffer.extend_from_slice(snapshot); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
475 return Ok(()); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
476 } |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
477 let patches: Result<Vec<_>, _> = deltas |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
478 .iter() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
479 .map(|d| patch::PatchList::new(d.as_ref())) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
480 .collect(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
481 let patch = patch::fold_patch_lists(&patches?); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
482 patch.apply(buffer, snapshot); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
483 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
484 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
485 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
486 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
487 type IndexData = Box<dyn Deref<Target = [u8]> + Send + Sync>; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
488 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
489 /// Open the revlog [`Index`] at `index_path`, through the `store_vfs` and the |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
490 /// given `options`. This controls whether (and how) we `mmap` the index file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
491 /// and returns an empty buffer if the index does not exist on disk. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
492 /// This is only used when doing pure-Rust work, in Python contexts this is |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
493 /// unused at the time of writing. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
494 pub fn open_index( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
495 store_vfs: &impl Vfs, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
496 index_path: &Path, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
497 options: RevlogOpenOptions, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
498 ) -> Result<Index, HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
499 let buf: IndexData = match store_vfs.open_read(index_path) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
500 Ok(mut file) => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
501 let mut buf = if let Some(threshold) = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
502 options.data_config.mmap_index_threshold |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
503 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
504 let size = store_vfs.file_size(&file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
505 if size >= threshold { |
52169
84b5802ba7d3
rust: populate mmap by default if available
Raphaël Gomès <rgomes@octobus.net>
parents:
52164
diff
changeset
|
506 // TODO madvise populate read in a background thread |
84b5802ba7d3
rust: populate mmap by default if available
Raphaël Gomès <rgomes@octobus.net>
parents:
52164
diff
changeset
|
507 let mut mmap_options = MmapOptions::new(); |
84b5802ba7d3
rust: populate mmap by default if available
Raphaël Gomès <rgomes@octobus.net>
parents:
52164
diff
changeset
|
508 // This does nothing on platforms where it's not defined |
84b5802ba7d3
rust: populate mmap by default if available
Raphaël Gomès <rgomes@octobus.net>
parents:
52164
diff
changeset
|
509 mmap_options.populate(); |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
510 // Safety is "enforced" by locks and assuming other |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
511 // processes are well-behaved. If any misbehaving or |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
512 // malicious process does touch the index, it could lead |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
513 // to corruption. This is somewhat inherent to file-based |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
514 // `mmap`, though some platforms have some ways of |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
515 // mitigating. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
516 // TODO linux: set the immutable flag with `chattr(1)`? |
52169
84b5802ba7d3
rust: populate mmap by default if available
Raphaël Gomès <rgomes@octobus.net>
parents:
52164
diff
changeset
|
517 let mmap = unsafe { mmap_options.map(&file) } |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
518 .when_reading_file(index_path)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
519 Some(Box::new(mmap) as IndexData) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
520 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
521 None |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
522 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
523 } else { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
524 None |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
525 }; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
526 |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
527 if buf.is_none() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
528 let mut data = vec![]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
529 file.read_to_end(&mut data).when_reading_file(index_path)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
530 buf = Some(Box::new(data) as IndexData); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
531 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
532 buf.unwrap() |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
533 } |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
534 Err(err) => match err { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
535 HgError::IoError { error, context } => match error.kind() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
536 ErrorKind::NotFound => Box::<Vec<u8>>::default(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
537 _ => return Err(HgError::IoError { error, context }), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
538 }, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
539 e => return Err(e), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
540 }, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
541 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
542 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
543 let index = Index::new(buf, options.index_header())?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
544 Ok(index) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
545 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
546 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
547 /// The revlog entry's bytes and the necessary informations to extract |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
548 /// the entry's data. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
549 #[derive(Clone)] |
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
550 pub struct RevlogEntry<'revlog> { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
551 revlog: &'revlog InnerRevlog, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
552 rev: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
553 uncompressed_len: i32, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
554 p1: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
555 p2: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
556 flags: u16, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
557 hash: Node, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
558 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
559 |
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
560 impl<'revlog> RevlogEntry<'revlog> { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
561 pub fn revision(&self) -> Revision { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
562 self.rev |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
563 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
564 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
565 pub fn node(&self) -> &Node { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
566 &self.hash |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
567 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
568 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
569 pub fn uncompressed_len(&self) -> Option<u32> { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
570 u32::try_from(self.uncompressed_len).ok() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
571 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
572 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
573 pub fn has_p1(&self) -> bool { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
574 self.p1 != NULL_REVISION |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
575 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
576 |
50413
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
577 pub fn p1_entry( |
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
578 &self, |
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
579 ) -> Result<Option<RevlogEntry<'revlog>>, RevlogError> { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
580 if self.p1 == NULL_REVISION { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
581 Ok(None) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
582 } else { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
583 Ok(Some(self.revlog.get_entry_for_checked_rev(self.p1)?)) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
584 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
585 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
586 |
50413
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
587 pub fn p2_entry( |
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
588 &self, |
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
589 ) -> Result<Option<RevlogEntry<'revlog>>, RevlogError> { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
590 if self.p2 == NULL_REVISION { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
591 Ok(None) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
592 } else { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
593 Ok(Some(self.revlog.get_entry_for_checked_rev(self.p2)?)) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
594 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
595 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
596 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
597 pub fn p1(&self) -> Option<Revision> { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
598 if self.p1 == NULL_REVISION { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
599 None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
600 } else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
601 Some(self.p1) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
602 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
603 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
604 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
605 pub fn p2(&self) -> Option<Revision> { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
606 if self.p2 == NULL_REVISION { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
607 None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
608 } else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
609 Some(self.p2) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
610 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
611 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
612 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
613 pub fn is_censored(&self) -> bool { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
614 (self.flags & REVISION_FLAG_CENSORED) != 0 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
615 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
616 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
617 pub fn has_length_affecting_flag_processor(&self) -> bool { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
618 // Relevant Python code: revlog.size() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
619 // note: ELLIPSIS is known to not change the content |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
620 (self.flags & (REVIDX_KNOWN_FLAGS ^ REVISION_FLAG_ELLIPSIS)) != 0 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
621 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
622 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
623 /// The data for this entry, after resolving deltas if any. |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
624 /// Non-Python callers should probably call [`Self::data`] instead. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
625 fn rawdata<G, T>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
626 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
627 stop_rev: Option<(Revision, &[u8])>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
628 with_buffer: G, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
629 ) -> Result<(), RevlogError> |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
630 where |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
631 G: FnOnce( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
632 usize, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
633 &mut dyn FnMut( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
634 &mut dyn RevisionBuffer<Target = T>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
635 ) -> Result<(), RevlogError>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
636 ) -> Result<(), RevlogError>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
637 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
638 let (delta_chain, stopped) = self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
639 .revlog |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
640 .delta_chain(self.revision(), stop_rev.map(|(r, _)| r))?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
641 let target_size = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
642 self.uncompressed_len().map(|raw_size| 4 * raw_size as u64); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
643 |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
644 let deltas = self.revlog.chunks(delta_chain, target_size)?; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
645 |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
646 let (base_text, deltas) = if stopped { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
647 ( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
648 stop_rev.as_ref().expect("last revision should be cached").1, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
649 &deltas[..], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
650 ) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
651 } else { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
652 let (buf, deltas) = deltas.split_at(1); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
653 (buf[0].as_ref(), deltas) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
654 }; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
655 |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
656 let size = self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
657 .uncompressed_len() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
658 .map(|l| l as usize) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
659 .unwrap_or(base_text.len()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
660 with_buffer(size, &mut |buf| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
661 Revlog::build_data_from_deltas(buf, base_text, deltas)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
662 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
663 })?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
664 Ok(()) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
665 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
666 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
667 fn check_data( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
668 &self, |
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
669 data: Cow<'revlog, [u8]>, |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
670 ) -> Result<Cow<'revlog, [u8]>, RevlogError> { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
671 if self.revlog.check_hash( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
672 self.p1, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
673 self.p2, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
674 self.hash.as_bytes(), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
675 &data, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
676 ) { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
677 Ok(data) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
678 } else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
679 if (self.flags & REVISION_FLAG_ELLIPSIS) != 0 { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
680 return Err(HgError::unsupported( |
52060
8b7123c8947b
update: add a Rust fast-path when updating from null (and clean)
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
681 "support for ellipsis nodes is missing", |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
682 ) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
683 .into()); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
684 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
685 Err(corrupted(format!( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
686 "hash check failed for revision {}", |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
687 self.rev |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
688 )) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
689 .into()) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
690 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
691 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
692 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
693 pub fn data(&self) -> Result<Cow<'revlog, [u8]>, RevlogError> { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
694 // TODO figure out if there is ever a need for `Cow` here anymore. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
695 let mut data = CoreRevisionBuffer::new(); |
50746
124c44b5cfad
rust-revlog: fix RevlogEntry.data() for NULL_REVISION
Georges Racinet <georges.racinet@octobus.net>
parents:
50745
diff
changeset
|
696 if self.rev == NULL_REVISION { |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
697 return Ok(data.finish().into()); |
50746
124c44b5cfad
rust-revlog: fix RevlogEntry.data() for NULL_REVISION
Georges Racinet <georges.racinet@octobus.net>
parents:
50745
diff
changeset
|
698 } |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
699 self.rawdata(None, |size, f| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
700 // Pre-allocate the expected size (received from the index) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
701 data.resize(size); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
702 // Actually fill the buffer |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
703 f(&mut data)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
704 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
705 })?; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
706 if self.is_censored() { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
707 return Err(HgError::CensoredNodeError.into()); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
708 } |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52160
diff
changeset
|
709 self.check_data(data.finish().into()) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
710 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
711 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
712 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
713 #[cfg(test)] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
714 mod tests { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
715 use super::*; |
51444
c3f2a9b55f59
rust-index: stop calling `with_offset` in the tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51256
diff
changeset
|
716 use crate::index::IndexEntryBuilder; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
717 use itertools::Itertools; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
718 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
719 #[test] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
720 fn test_empty() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
721 let temp = tempfile::tempdir().unwrap(); |
51868 | 722 let vfs = VfsImpl { |
723 base: temp.path().to_owned(), | |
724 }; | |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
725 std::fs::write(temp.path().join("foo.i"), b"").unwrap(); |
51867
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Raphaël Gomès <rgomes@octobus.net>
parents:
51866
diff
changeset
|
726 std::fs::write(temp.path().join("foo.d"), b"").unwrap(); |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
727 let revlog = |
51867
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Raphaël Gomès <rgomes@octobus.net>
parents:
51866
diff
changeset
|
728 Revlog::open(&vfs, "foo.i", None, RevlogOpenOptions::default()) |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
729 .unwrap(); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
730 assert!(revlog.is_empty()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
731 assert_eq!(revlog.len(), 0); |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
732 assert!(revlog.get_entry(0.into()).is_err()); |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
733 assert!(!revlog.has_rev(0.into())); |
50745
3338c6ffdaa3
rust-revlog: using constant in test
Georges Racinet <georges.racinet@octobus.net>
parents:
50744
diff
changeset
|
734 assert_eq!( |
3338c6ffdaa3
rust-revlog: using constant in test
Georges Racinet <georges.racinet@octobus.net>
parents:
50744
diff
changeset
|
735 revlog.rev_from_node(NULL_NODE.into()).unwrap(), |
3338c6ffdaa3
rust-revlog: using constant in test
Georges Racinet <georges.racinet@octobus.net>
parents:
50744
diff
changeset
|
736 NULL_REVISION |
3338c6ffdaa3
rust-revlog: using constant in test
Georges Racinet <georges.racinet@octobus.net>
parents:
50744
diff
changeset
|
737 ); |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
738 let null_entry = revlog.get_entry(NULL_REVISION.into()).ok().unwrap(); |
50746
124c44b5cfad
rust-revlog: fix RevlogEntry.data() for NULL_REVISION
Georges Racinet <georges.racinet@octobus.net>
parents:
50745
diff
changeset
|
739 assert_eq!(null_entry.revision(), NULL_REVISION); |
124c44b5cfad
rust-revlog: fix RevlogEntry.data() for NULL_REVISION
Georges Racinet <georges.racinet@octobus.net>
parents:
50745
diff
changeset
|
740 assert!(null_entry.data().unwrap().is_empty()); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
741 } |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
742 |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
743 #[test] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
744 fn test_inline() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
745 let temp = tempfile::tempdir().unwrap(); |
51868 | 746 let vfs = VfsImpl { |
747 base: temp.path().to_owned(), | |
748 }; | |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
749 let node0 = Node::from_hex("2ed2a3912a0b24502043eae84ee4b279c18b90dd") |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
750 .unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
751 let node1 = Node::from_hex("b004912a8510032a0350a74daa2803dadfb00e12") |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
752 .unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
753 let node2 = Node::from_hex("dd6ad206e907be60927b5a3117b97dffb2590582") |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
754 .unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
755 let entry0_bytes = IndexEntryBuilder::new() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
756 .is_first(true) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
757 .with_version(1) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
758 .with_inline(true) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
759 .with_node(node0) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
760 .build(); |
51444
c3f2a9b55f59
rust-index: stop calling `with_offset` in the tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51256
diff
changeset
|
761 let entry1_bytes = IndexEntryBuilder::new().with_node(node1).build(); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
762 let entry2_bytes = IndexEntryBuilder::new() |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
763 .with_p1(Revision(0)) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
764 .with_p2(Revision(1)) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
765 .with_node(node2) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
766 .build(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
767 let contents = vec![entry0_bytes, entry1_bytes, entry2_bytes] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
768 .into_iter() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
769 .flatten() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
770 .collect_vec(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
771 std::fs::write(temp.path().join("foo.i"), contents).unwrap(); |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
772 let revlog = |
51867
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Raphaël Gomès <rgomes@octobus.net>
parents:
51866
diff
changeset
|
773 Revlog::open(&vfs, "foo.i", None, RevlogOpenOptions::default()) |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
774 .unwrap(); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
775 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
776 let entry0 = revlog.get_entry(0.into()).ok().unwrap(); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
777 assert_eq!(entry0.revision(), Revision(0)); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
778 assert_eq!(*entry0.node(), node0); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
779 assert!(!entry0.has_p1()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
780 assert_eq!(entry0.p1(), None); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
781 assert_eq!(entry0.p2(), None); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
782 let p1_entry = entry0.p1_entry().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
783 assert!(p1_entry.is_none()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
784 let p2_entry = entry0.p2_entry().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
785 assert!(p2_entry.is_none()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
786 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
787 let entry1 = revlog.get_entry(1.into()).ok().unwrap(); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
788 assert_eq!(entry1.revision(), Revision(1)); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
789 assert_eq!(*entry1.node(), node1); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
790 assert!(!entry1.has_p1()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
791 assert_eq!(entry1.p1(), None); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
792 assert_eq!(entry1.p2(), None); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
793 let p1_entry = entry1.p1_entry().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
794 assert!(p1_entry.is_none()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
795 let p2_entry = entry1.p2_entry().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
796 assert!(p2_entry.is_none()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
797 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
798 let entry2 = revlog.get_entry(2.into()).ok().unwrap(); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
799 assert_eq!(entry2.revision(), Revision(2)); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
800 assert_eq!(*entry2.node(), node2); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
801 assert!(entry2.has_p1()); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
802 assert_eq!(entry2.p1(), Some(Revision(0))); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
803 assert_eq!(entry2.p2(), Some(Revision(1))); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
804 let p1_entry = entry2.p1_entry().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
805 assert!(p1_entry.is_some()); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
806 assert_eq!(p1_entry.unwrap().revision(), Revision(0)); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
807 let p2_entry = entry2.p2_entry().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
808 assert!(p2_entry.is_some()); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
809 assert_eq!(p2_entry.unwrap().revision(), Revision(1)); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
810 } |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
811 |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
812 #[test] |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
813 fn test_nodemap() { |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
814 let temp = tempfile::tempdir().unwrap(); |
51868 | 815 let vfs = VfsImpl { |
816 base: temp.path().to_owned(), | |
817 }; | |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
818 |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
819 // building a revlog with a forced Node starting with zeros |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
820 // This is a corruption, but it does not preclude using the nodemap |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
821 // if we don't try and access the data |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
822 let node0 = Node::from_hex("00d2a3912a0b24502043eae84ee4b279c18b90dd") |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
823 .unwrap(); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
824 let node1 = Node::from_hex("b004912a8510032a0350a74daa2803dadfb00e12") |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
825 .unwrap(); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
826 let entry0_bytes = IndexEntryBuilder::new() |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
827 .is_first(true) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
828 .with_version(1) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
829 .with_inline(true) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
830 .with_node(node0) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
831 .build(); |
51444
c3f2a9b55f59
rust-index: stop calling `with_offset` in the tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51256
diff
changeset
|
832 let entry1_bytes = IndexEntryBuilder::new().with_node(node1).build(); |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
833 let contents = vec![entry0_bytes, entry1_bytes] |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
834 .into_iter() |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
835 .flatten() |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
836 .collect_vec(); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
837 std::fs::write(temp.path().join("foo.i"), contents).unwrap(); |
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
838 |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
839 let mut idx = nodemap::tests::TestNtIndex::new(); |
50993
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
840 idx.insert_node(Revision(0), node0).unwrap(); |
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
841 idx.insert_node(Revision(1), node1).unwrap(); |
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
842 |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
843 let revlog = Revlog::open_gen( |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
844 &vfs, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
845 "foo.i", |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
846 None, |
51867
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Raphaël Gomès <rgomes@octobus.net>
parents:
51866
diff
changeset
|
847 RevlogOpenOptions::default(), |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
848 Some(idx.nt), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
849 ) |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
850 .unwrap(); |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
851 |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
852 // accessing the data shows the corruption |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
853 revlog.get_entry(0.into()).unwrap().data().unwrap_err(); |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
854 |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
855 assert_eq!( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
856 revlog.rev_from_node(NULL_NODE.into()).unwrap(), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
857 Revision(-1) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
858 ); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
859 assert_eq!(revlog.rev_from_node(node0.into()).unwrap(), Revision(0)); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
860 assert_eq!(revlog.rev_from_node(node1.into()).unwrap(), Revision(1)); |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
861 assert_eq!( |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
862 revlog |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
863 .rev_from_node(NodePrefix::from_hex("000").unwrap()) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
864 .unwrap(), |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
865 Revision(-1) |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
866 ); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
867 assert_eq!( |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
868 revlog |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
869 .rev_from_node(NodePrefix::from_hex("b00").unwrap()) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
870 .unwrap(), |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
871 Revision(1) |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
872 ); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
873 // RevlogError does not implement PartialEq |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
874 // (ultimately because io::Error does not) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
875 match revlog |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
876 .rev_from_node(NodePrefix::from_hex("00").unwrap()) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
877 .expect_err("Expected to give AmbiguousPrefix error") |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
878 { |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
879 RevlogError::AmbiguousPrefix => (), |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
880 e => { |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
881 panic!("Got another error than AmbiguousPrefix: {:?}", e); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
882 } |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
883 }; |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
884 } |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
885 } |