author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Mon, 26 Feb 2024 12:59:57 +0100 | |
changeset 51445 | d2858d97af6c |
parent 51444 | c3f2a9b55f59 |
child 51623 | 59f846fbc11d |
permissions | -rw-r--r-- |
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; |
46431
645ee7225fab
rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef
Simon Sapin <simon.sapin@octobus.net>
parents:
46428
diff
changeset
|
12 |
pub use node::{FromHexError, Node, NodePrefix}; |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
13 |
pub mod changelog; |
47961
4d2a5ca060e3
rust: Add a Filelog struct that wraps Revlog
Simon Sapin <simon.sapin@octobus.net>
parents:
46821
diff
changeset
|
14 |
pub mod filelog; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
15 |
pub mod index; |
45533
89ac95bd4993
hg-core: add `Manifest` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45532
diff
changeset
|
16 |
pub mod manifest; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
17 |
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
|
18 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
19 |
use std::borrow::Cow; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
24 |
use flate2::read::ZlibDecoder; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
25 |
use sha1::{Digest, Sha1}; |
50506
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
26 |
use std::cell::RefCell; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
27 |
use zstd; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
28 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
29 |
use self::node::{NODE_BYTES_LENGTH, NULL_NODE}; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
30 |
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
|
31 |
use super::index::Index; |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51444
diff
changeset
|
32 |
use super::index::INDEX_ENTRY_SIZE; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
33 |
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
|
34 |
use crate::errors::HgError; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
35 |
use crate::vfs::Vfs; |
44142
63db6657d280
rust-nodemap: building blocks for nodetree structures
Georges Racinet <georges.racinet@octobus.net>
parents:
44088
diff
changeset
|
36 |
|
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
37 |
/// 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
|
38 |
/// 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
|
39 |
pub type BaseRevision = i32; |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
40 |
|
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
41 |
/// Mercurial revision numbers |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
42 |
/// 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
|
43 |
/// 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
|
44 |
/// 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
|
45 |
#[derive( |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
46 |
Debug, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
47 |
derive_more::Display, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
48 |
Clone, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
49 |
Copy, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
50 |
Hash, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
51 |
PartialEq, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
52 |
Eq, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
53 |
PartialOrd, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
54 |
Ord, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
55 |
)] |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
56 |
pub struct Revision(pub BaseRevision); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
57 |
|
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
58 |
impl format_bytes::DisplayBytes for Revision { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
59 |
fn display_bytes( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
60 |
&self, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
61 |
output: &mut dyn std::io::Write, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
62 |
) -> std::io::Result<()> { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
63 |
self.0.display_bytes(output) |
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 |
} |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
66 |
|
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
67 |
/// Unchecked Mercurial revision numbers. |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
68 |
/// |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
69 |
/// 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
|
70 |
/// 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
|
71 |
/// the appropriate index object. |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
72 |
#[derive( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
73 |
Debug, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
74 |
derive_more::Display, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
75 |
Clone, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
76 |
Copy, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
77 |
Hash, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
78 |
PartialEq, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
79 |
Eq, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
80 |
PartialOrd, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
81 |
Ord, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
82 |
)] |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
83 |
pub struct UncheckedRevision(pub BaseRevision); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
84 |
|
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
85 |
impl format_bytes::DisplayBytes for UncheckedRevision { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
86 |
fn display_bytes( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
87 |
&self, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
88 |
output: &mut dyn std::io::Write, |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
89 |
) -> std::io::Result<()> { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
90 |
self.0.display_bytes(output) |
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 |
} |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
93 |
|
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
94 |
impl From<Revision> for UncheckedRevision { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
95 |
fn from(value: Revision) -> Self { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
96 |
Self(value.0) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
97 |
} |
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 |
|
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
100 |
impl From<BaseRevision> for UncheckedRevision { |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
101 |
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
|
102 |
Self(value) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
103 |
} |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
104 |
} |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
105 |
|
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
106 |
/// Marker expressing the absence of a parent |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
107 |
/// |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
108 |
/// 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
|
109 |
/// 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
|
110 |
pub const NULL_REVISION: Revision = Revision(-1); |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
111 |
|
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
112 |
/// Same as `mercurial.node.wdirrev` |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
113 |
/// |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
114 |
/// 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
|
115 |
/// 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
|
116 |
#[allow(clippy::unreadable_literal)] |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
117 |
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
|
118 |
UncheckedRevision(0x7fffffff); |
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
119 |
|
46821
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46431
diff
changeset
|
120 |
pub const WORKING_DIRECTORY_HEX: &str = |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46431
diff
changeset
|
121 |
"ffffffffffffffffffffffffffffffffffffffff"; |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46431
diff
changeset
|
122 |
|
44005
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
123 |
/// 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
|
124 |
pub trait Graph { |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
125 |
/// Return the two parents of the given `Revision`. |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
126 |
/// |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
127 |
/// 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
|
128 |
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
|
129 |
} |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
130 |
|
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
131 |
#[derive(Clone, Debug, PartialEq)] |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
132 |
pub enum GraphError { |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
133 |
ParentOutOfRange(Revision), |
6b332c1fc7fe
rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
134 |
} |
44181
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
135 |
|
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
136 |
/// The Mercurial Revlog Index |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
137 |
/// |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
138 |
/// 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
|
139 |
/// 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
|
140 |
pub trait RevlogIndex { |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
141 |
/// 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
|
142 |
fn len(&self) -> usize; |
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
143 |
|
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
144 |
fn is_empty(&self) -> bool { |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
145 |
self.len() == 0 |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
146 |
} |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44182
diff
changeset
|
147 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
148 |
/// 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
|
149 |
fn node(&self, rev: Revision) -> Option<&Node>; |
50974
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
150 |
|
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
151 |
/// 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
|
152 |
/// 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
|
153 |
/// |
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
|
154 |
/// [`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
|
155 |
#[inline(always)] |
50974
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
156 |
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
|
157 |
let rev = rev.0; |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
158 |
|
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
159 |
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
|
160 |
{ |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
161 |
Some(Revision(rev)) |
50974
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
162 |
} else { |
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
163 |
None |
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
164 |
} |
c950fdba7472
rust: add `UncheckedRevision` type
Raphaël Gomès <rgomes@octobus.net>
parents:
50746
diff
changeset
|
165 |
} |
44181
3fb39dc2e356
rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents:
44143
diff
changeset
|
166 |
} |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
167 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
173 |
// 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
|
174 |
// 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
|
175 |
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
|
176 |
| REVISION_FLAG_ELLIPSIS |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
177 |
| REVISION_FLAG_EXTSTORED |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
178 |
| REVISION_FLAG_HASCOPIESINFO; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
179 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
180 |
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
|
181 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
182 |
#[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
|
183 |
pub enum RevlogError { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
184 |
InvalidRevision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
185 |
/// 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
|
186 |
WDirUnsupported, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
187 |
/// 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
|
188 |
AmbiguousPrefix, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
189 |
#[from] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
190 |
Other(HgError), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
191 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
192 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
match error { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
200 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
201 |
} |
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 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
207 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
208 |
impl RevlogError { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
212 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
213 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
214 |
/// Read only implementation of revlog. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
215 |
pub struct Revlog { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
216 |
/// When index and data are not interleaved: bytes of the revlog index. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
217 |
/// When index and data are interleaved: bytes of the revlog index and |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
218 |
/// data. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
219 |
index: Index, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
220 |
/// When index and data are not interleaved: bytes of the revlog data |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
221 |
data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>>, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
222 |
/// 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
|
223 |
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
|
224 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
225 |
|
50978
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
226 |
impl Graph for Revlog { |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
227 |
fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
228 |
self.index.parents(rev) |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
229 |
} |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
230 |
} |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
231 |
|
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
|
232 |
#[derive(Debug, Copy, Clone)] |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
233 |
pub enum RevlogVersionOptions { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
234 |
V0, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
235 |
V1 { generaldelta: bool }, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
236 |
V2, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
237 |
ChangelogV2 { compute_rank: bool }, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
238 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
239 |
|
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
240 |
/// Options to govern how a revlog should be opened, usually from the |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
241 |
/// repository configuration or requirements. |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
242 |
#[derive(Debug, Copy, Clone)] |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
243 |
pub struct RevlogOpenOptions { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
244 |
/// The revlog version, along with any option specific to this version |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
245 |
pub version: RevlogVersionOptions, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
246 |
/// Whether the revlog uses a persistent nodemap. |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
247 |
pub use_nodemap: bool, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
248 |
// TODO other non-header/version options, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
249 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
250 |
|
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
251 |
impl RevlogOpenOptions { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
252 |
pub fn new() -> Self { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
253 |
Self { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
254 |
version: RevlogVersionOptions::V1 { generaldelta: true }, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
255 |
use_nodemap: false, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
256 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
257 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
258 |
|
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
259 |
fn default_index_header(&self) -> index::IndexHeader { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
260 |
index::IndexHeader { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
261 |
header_bytes: match self.version { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
262 |
RevlogVersionOptions::V0 => [0, 0, 0, 0], |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
263 |
RevlogVersionOptions::V1 { generaldelta } => { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
264 |
[0, if generaldelta { 3 } else { 1 }, 0, 1] |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
265 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
266 |
RevlogVersionOptions::V2 => 0xDEADu32.to_be_bytes(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
267 |
RevlogVersionOptions::ChangelogV2 { compute_rank: _ } => { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
268 |
0xD34Du32.to_be_bytes() |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
269 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
270 |
}, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
271 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
272 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
273 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
274 |
|
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
275 |
impl Default for RevlogOpenOptions { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
276 |
fn default() -> Self { |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
277 |
Self::new() |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
278 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
279 |
} |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
280 |
|
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
281 |
impl Revlog { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
282 |
/// 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
|
283 |
/// |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
284 |
/// 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
|
285 |
/// interleaved. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
286 |
pub fn open( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
287 |
store_vfs: &Vfs, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
288 |
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
|
289 |
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
|
290 |
options: RevlogOpenOptions, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
291 |
) -> 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
|
292 |
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
|
293 |
} |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
294 |
|
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
295 |
fn open_gen( |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
296 |
store_vfs: &Vfs, |
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
) -> 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
|
302 |
let index_path = index_path.as_ref(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
303 |
let index = { |
51120
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Raphaël Gomès <rgomes@octobus.net>
parents:
50993
diff
changeset
|
304 |
match store_vfs.mmap_open_opt(index_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
|
305 |
None => Index::new( |
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 |
Box::<Vec<_>>::default(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
307 |
options.default_index_header(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
308 |
), |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
309 |
Some(index_mmap) => { |
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
|
310 |
let index = Index::new( |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
311 |
Box::new(index_mmap), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
312 |
options.default_index_header(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
313 |
)?; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
314 |
Ok(index) |
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 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
319 |
let default_data_path = index_path.with_extension("d"); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
320 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
321 |
// type annotation required |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
322 |
// won't recognize Mmap as Deref<Target = [u8]> |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
323 |
let data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>> = |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
324 |
if index.is_inline() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
325 |
None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
326 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
327 |
let data_path = data_path.unwrap_or(&default_data_path); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
328 |
let data_mmap = store_vfs.mmap_open(data_path)?; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
329 |
Some(Box::new(data_mmap)) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
330 |
}; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
331 |
|
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
|
332 |
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
|
333 |
None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
334 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
335 |
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
|
336 |
|(docket, data)| { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
337 |
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
|
338 |
Box::new(data), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
339 |
docket.data_length, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
340 |
) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
341 |
}, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
342 |
) |
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 |
|
50986
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
345 |
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
|
346 |
|
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
347 |
Ok(Revlog { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
348 |
index, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
349 |
data_bytes, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
350 |
nodemap, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
351 |
}) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
352 |
} |
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 |
/// 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
|
355 |
pub fn len(&self) -> usize { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
356 |
self.index.len() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
357 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
358 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
359 |
/// 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
|
360 |
pub fn is_empty(&self) -> bool { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
361 |
self.index.is_empty() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
362 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
363 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
364 |
/// 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
|
365 |
/// revlog |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
} |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
370 |
let rev = self.index.check_revision(rev)?; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
371 |
Some(self.index.get_entry(rev)?.hash()) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
372 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
373 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
374 |
/// 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
|
375 |
/// revlog |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
376 |
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
|
377 |
&self, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
378 |
node: NodePrefix, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
379 |
) -> 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
|
380 |
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
|
381 |
nodemap |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
382 |
.find_bin(&self.index, node)? |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
383 |
.ok_or(RevlogError::InvalidRevision) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
384 |
} else { |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
385 |
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
|
386 |
} |
50743
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
387 |
} |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
388 |
|
50743
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
389 |
/// 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
|
390 |
/// |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
391 |
/// 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
|
392 |
/// 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
|
393 |
/// 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
|
394 |
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
|
395 |
&self, |
0159b014f3ab
rust-revlog: split out method for `rev_from_node` without persistent nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
50508
diff
changeset
|
396 |
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
|
397 |
) -> 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
|
398 |
// 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
|
399 |
// 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
|
400 |
// optimize these cases. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
401 |
let mut found_by_prefix = None; |
50993
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
402 |
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
|
403 |
let rev = Revision(rev as BaseRevision); |
50993
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
404 |
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
|
405 |
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
|
406 |
} 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
|
407 |
let index_entry = |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
408 |
self.index.get_entry(rev).ok_or_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
|
409 |
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
|
410 |
"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
|
411 |
) |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
412 |
})?; |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
413 |
*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
|
414 |
}; |
363620b934aa
revlog: fix a bug where NULL_NODE failed to be resolved to NULL_REV
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50746
diff
changeset
|
415 |
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
|
416 |
return Ok(rev); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
417 |
} |
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
|
418 |
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
|
419 |
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
|
420 |
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
|
421 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
422 |
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
|
423 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
424 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
425 |
found_by_prefix.ok_or(RevlogError::InvalidRevision) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
426 |
} |
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 |
/// 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
|
429 |
pub fn has_rev(&self, rev: UncheckedRevision) -> bool { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
430 |
self.index.check_revision(rev).is_some() |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
431 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
432 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
433 |
/// 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
|
434 |
/// |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
435 |
/// 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
|
436 |
/// 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
|
437 |
/// 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
|
438 |
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
|
439 |
&self, |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
440 |
rev: UncheckedRevision, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
441 |
) -> Result<Cow<[u8]>, RevlogError> { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
442 |
if rev == NULL_REVISION.into() { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
443 |
return Ok(Cow::Borrowed(&[])); |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
444 |
}; |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
445 |
self.get_entry(rev)?.data() |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
446 |
} |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
447 |
|
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
448 |
/// [`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
|
449 |
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
|
450 |
&self, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
451 |
rev: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
452 |
) -> 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
|
453 |
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
|
454 |
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
|
455 |
}; |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
456 |
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
|
457 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
458 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
459 |
/// 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
|
460 |
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
|
461 |
&self, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
462 |
p1: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
463 |
p2: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
464 |
expected: &[u8], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
465 |
data: &[u8], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
466 |
) -> bool { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
467 |
let e1 = self.index.get_entry(p1); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
468 |
let h1 = match e1 { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
469 |
Some(ref entry) => entry.hash(), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
470 |
None => &NULL_NODE, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
471 |
}; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
472 |
let e2 = self.index.get_entry(p2); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
473 |
let h2 = match e2 { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
474 |
Some(ref entry) => entry.hash(), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
475 |
None => &NULL_NODE, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
476 |
}; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
477 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
478 |
hash(data, h1.as_bytes(), h2.as_bytes()) == expected |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
479 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
480 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
481 |
/// 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
|
482 |
/// and its deltas. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
483 |
fn build_data_from_deltas( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
484 |
snapshot: RevlogEntry, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
485 |
deltas: &[RevlogEntry], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
486 |
) -> Result<Vec<u8>, HgError> { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
487 |
let snapshot = snapshot.data_chunk()?; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
488 |
let deltas = deltas |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
489 |
.iter() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
490 |
.rev() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
491 |
.map(RevlogEntry::data_chunk) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
492 |
.collect::<Result<Vec<_>, _>>()?; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
493 |
let patches: Vec<_> = |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
494 |
deltas.iter().map(|d| patch::PatchList::new(d)).collect(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
495 |
let patch = patch::fold_patch_lists(&patches); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
496 |
Ok(patch.apply(&snapshot)) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
497 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
498 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
499 |
/// Return the revlog data. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
500 |
fn data(&self) -> &[u8] { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
501 |
match &self.data_bytes { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
502 |
Some(data_bytes) => data_bytes, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
503 |
None => panic!( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
504 |
"forgot to load the data or trying to access inline data" |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
505 |
), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
506 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
507 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
508 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
509 |
pub fn make_null_entry(&self) -> RevlogEntry { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
510 |
RevlogEntry { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
511 |
revlog: self, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
512 |
rev: NULL_REVISION, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
513 |
bytes: b"", |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
514 |
compressed_len: 0, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
515 |
uncompressed_len: 0, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
516 |
base_rev_or_base_of_delta_chain: None, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
517 |
p1: NULL_REVISION, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
518 |
p2: NULL_REVISION, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
519 |
flags: NULL_REVLOG_ENTRY_FLAGS, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
520 |
hash: NULL_NODE, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
521 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
522 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
523 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
524 |
fn get_entry_for_checked_rev( |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
525 |
&self, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
526 |
rev: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
527 |
) -> Result<RevlogEntry, RevlogError> { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
528 |
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
|
529 |
return Ok(self.make_null_entry()); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
530 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
531 |
let index_entry = self |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
532 |
.index |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
533 |
.get_entry(rev) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
534 |
.ok_or(RevlogError::InvalidRevision)?; |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51444
diff
changeset
|
535 |
let offset = index_entry.offset(); |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51444
diff
changeset
|
536 |
let start = if self.index.is_inline() { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51444
diff
changeset
|
537 |
offset + ((rev.0 as usize + 1) * INDEX_ENTRY_SIZE) |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51444
diff
changeset
|
538 |
} else { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51444
diff
changeset
|
539 |
offset |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51444
diff
changeset
|
540 |
}; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
541 |
let end = start + index_entry.compressed_len() as usize; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
542 |
let data = if self.index.is_inline() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
543 |
self.index.data(start, end) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
544 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
545 |
&self.data()[start..end] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
546 |
}; |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
547 |
let base_rev = self |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
548 |
.index |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
549 |
.check_revision(index_entry.base_revision_or_base_of_delta_chain()) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
550 |
.ok_or_else(|| { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
551 |
RevlogError::corrupted(format!( |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
552 |
"base revision for rev {} is invalid", |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
553 |
rev |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
554 |
)) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
555 |
})?; |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
556 |
let p1 = |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
557 |
self.index.check_revision(index_entry.p1()).ok_or_else(|| { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
558 |
RevlogError::corrupted(format!( |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
559 |
"p1 for rev {} is invalid", |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
560 |
rev |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
561 |
)) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
562 |
})?; |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
563 |
let p2 = |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
564 |
self.index.check_revision(index_entry.p2()).ok_or_else(|| { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
565 |
RevlogError::corrupted(format!( |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
566 |
"p2 for rev {} is invalid", |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
567 |
rev |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
568 |
)) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
569 |
})?; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
570 |
let entry = RevlogEntry { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
571 |
revlog: self, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
572 |
rev, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
573 |
bytes: data, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
574 |
compressed_len: index_entry.compressed_len(), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
575 |
uncompressed_len: index_entry.uncompressed_len(), |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
576 |
base_rev_or_base_of_delta_chain: if base_rev == rev { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
577 |
None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
578 |
} else { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
579 |
Some(base_rev) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
580 |
}, |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
581 |
p1, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
582 |
p2, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
583 |
flags: index_entry.flags(), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
584 |
hash: *index_entry.hash(), |
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 |
Ok(entry) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
587 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
588 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
589 |
/// Get an entry of the revlog. |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
590 |
pub fn get_entry( |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
591 |
&self, |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
592 |
rev: UncheckedRevision, |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
593 |
) -> Result<RevlogEntry, RevlogError> { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
594 |
if rev == NULL_REVISION.into() { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
595 |
return Ok(self.make_null_entry()); |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
596 |
} |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
597 |
let rev = self.index.check_revision(rev).ok_or_else(|| { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
598 |
RevlogError::corrupted(format!("rev {} is invalid", rev)) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
599 |
})?; |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
600 |
self.get_entry_for_checked_rev(rev) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
601 |
} |
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 |
/// 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
|
605 |
/// 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
|
606 |
#[derive(Clone)] |
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
607 |
pub struct RevlogEntry<'revlog> { |
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
608 |
revlog: &'revlog Revlog, |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
609 |
rev: Revision, |
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
610 |
bytes: &'revlog [u8], |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
611 |
compressed_len: u32, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
612 |
uncompressed_len: i32, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
613 |
base_rev_or_base_of_delta_chain: Option<Revision>, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
614 |
p1: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
615 |
p2: Revision, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
616 |
flags: u16, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
617 |
hash: Node, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
618 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
619 |
|
50506
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
620 |
thread_local! { |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
621 |
// seems fine to [unwrap] here: this can only fail due to memory allocation |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
622 |
// failing, and it's normal for that to cause panic. |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
623 |
static ZSTD_DECODER : RefCell<zstd::bulk::Decompressor<'static>> = |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
624 |
RefCell::new(zstd::bulk::Decompressor::new().ok().unwrap()); |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
625 |
} |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
626 |
|
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
627 |
fn zstd_decompress_to_buffer( |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
628 |
bytes: &[u8], |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
629 |
buf: &mut Vec<u8>, |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
630 |
) -> Result<usize, std::io::Error> { |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
631 |
ZSTD_DECODER |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
632 |
.with(|decoder| decoder.borrow_mut().decompress_to_buffer(bytes, buf)) |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
633 |
} |
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
634 |
|
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
635 |
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
|
636 |
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
|
637 |
self.rev |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
638 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
639 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
640 |
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
|
641 |
&self.hash |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
642 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
643 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
644 |
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
|
645 |
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
|
646 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
647 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
648 |
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
|
649 |
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
|
650 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
651 |
|
50413
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
652 |
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
|
653 |
&self, |
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
654 |
) -> 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
|
655 |
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
|
656 |
Ok(None) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
657 |
} else { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
658 |
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
|
659 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
660 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
661 |
|
50413
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
662 |
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
|
663 |
&self, |
c101e7757ed7
rust-revlog: fix lifetime problem for RevlogEntry parent entries accessors
Georges Racinet <georges.racinet@octobus.net>
parents:
50412
diff
changeset
|
664 |
) -> 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
|
665 |
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
|
666 |
Ok(None) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
667 |
} else { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
668 |
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
|
669 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
670 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
671 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
672 |
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
|
673 |
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
|
674 |
None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
675 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
676 |
Some(self.p1) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
677 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
678 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
679 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
680 |
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
|
681 |
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
|
682 |
None |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
683 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
684 |
Some(self.p2) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
685 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
686 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
687 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
688 |
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
|
689 |
(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
|
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 |
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
|
693 |
// 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
|
694 |
// 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
|
695 |
(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
|
696 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
697 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
698 |
/// The data for this entry, after resolving deltas if any. |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
699 |
pub fn rawdata(&self) -> 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
|
700 |
let mut entry = self.clone(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
701 |
let mut delta_chain = vec![]; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
702 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
703 |
// The meaning of `base_rev_or_base_of_delta_chain` depends on |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
704 |
// generaldelta. See the doc on `ENTRY_DELTA_BASE` in |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
705 |
// `mercurial/revlogutils/constants.py` and the code in |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
706 |
// [_chaininfo] and in [index_deltachain]. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
707 |
let uses_generaldelta = self.revlog.index.uses_generaldelta(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
708 |
while let Some(base_rev) = entry.base_rev_or_base_of_delta_chain { |
50976
9929c8a73488
rust-revlog: split logic for `rawdata` to prepare for `UncheckedRevision` use
Raphaël Gomès <rgomes@octobus.net>
parents:
50975
diff
changeset
|
709 |
entry = if uses_generaldelta { |
9929c8a73488
rust-revlog: split logic for `rawdata` to prepare for `UncheckedRevision` use
Raphaël Gomès <rgomes@octobus.net>
parents:
50975
diff
changeset
|
710 |
delta_chain.push(entry); |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
711 |
self.revlog.get_entry_for_checked_rev(base_rev)? |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
712 |
} else { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
713 |
let base_rev = UncheckedRevision(entry.rev.0 - 1); |
50976
9929c8a73488
rust-revlog: split logic for `rawdata` to prepare for `UncheckedRevision` use
Raphaël Gomès <rgomes@octobus.net>
parents:
50975
diff
changeset
|
714 |
delta_chain.push(entry); |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
715 |
self.revlog.get_entry(base_rev)? |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
716 |
}; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
717 |
} |
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 |
let data = if delta_chain.is_empty() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
720 |
entry.data_chunk()? |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
721 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
722 |
Revlog::build_data_from_deltas(entry, &delta_chain)?.into() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
723 |
}; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
724 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
725 |
Ok(data) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
726 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
727 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
728 |
fn check_data( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
729 |
&self, |
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
730 |
data: Cow<'revlog, [u8]>, |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
731 |
) -> 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
|
732 |
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
|
733 |
self.p1, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
734 |
self.p2, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
735 |
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
|
736 |
&data, |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
737 |
) { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
738 |
Ok(data) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
739 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
740 |
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
|
741 |
return Err(HgError::unsupported( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
742 |
"ellipsis revisions are not supported by rhg", |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
743 |
) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
744 |
.into()); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
745 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
746 |
Err(corrupted(format!( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
747 |
"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
|
748 |
self.rev |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
749 |
)) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
750 |
.into()) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
751 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
752 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
753 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
754 |
pub fn data(&self) -> 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
|
755 |
let data = self.rawdata()?; |
50746
124c44b5cfad
rust-revlog: fix RevlogEntry.data() for NULL_REVISION
Georges Racinet <georges.racinet@octobus.net>
parents:
50745
diff
changeset
|
756 |
if self.rev == NULL_REVISION { |
124c44b5cfad
rust-revlog: fix RevlogEntry.data() for NULL_REVISION
Georges Racinet <georges.racinet@octobus.net>
parents:
50745
diff
changeset
|
757 |
return Ok(data); |
124c44b5cfad
rust-revlog: fix RevlogEntry.data() for NULL_REVISION
Georges Racinet <georges.racinet@octobus.net>
parents:
50745
diff
changeset
|
758 |
} |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
759 |
if self.is_censored() { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
760 |
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
|
761 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
762 |
self.check_data(data) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
763 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
764 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
765 |
/// Extract the data contained in the entry. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
766 |
/// This may be a delta. (See `is_delta`.) |
50412
7ef51fff2c4f
rust-revlog: explicit naming for `RevlogEntry` lifetime
Georges Racinet <georges.racinet@octobus.net>
parents:
49937
diff
changeset
|
767 |
fn data_chunk(&self) -> Result<Cow<'revlog, [u8]>, HgError> { |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
768 |
if self.bytes.is_empty() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
769 |
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
|
770 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
771 |
match self.bytes[0] { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
772 |
// Revision data is the entirety of the entry, including this |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
773 |
// header. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
774 |
b'\0' => Ok(Cow::Borrowed(self.bytes)), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
775 |
// Raw revision data follows. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
776 |
b'u' => Ok(Cow::Borrowed(&self.bytes[1..])), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
777 |
// zlib (RFC 1950) data. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
778 |
b'x' => Ok(Cow::Owned(self.uncompressed_zlib_data()?)), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
779 |
// zstd data. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
780 |
b'\x28' => Ok(Cow::Owned(self.uncompressed_zstd_data()?)), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
781 |
// A proper new format should have had a repo/store requirement. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
782 |
format_type => Err(corrupted(format!( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
783 |
"unknown compression header '{}'", |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
784 |
format_type |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
785 |
))), |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
786 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
787 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
788 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
789 |
fn uncompressed_zlib_data(&self) -> Result<Vec<u8>, HgError> { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
790 |
let mut decoder = ZlibDecoder::new(self.bytes); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
791 |
if self.is_delta() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
792 |
let mut buf = Vec::with_capacity(self.compressed_len as usize); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
793 |
decoder |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
794 |
.read_to_end(&mut buf) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
795 |
.map_err(|e| corrupted(e.to_string()))?; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
796 |
Ok(buf) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
797 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
798 |
let cap = self.uncompressed_len.max(0) as usize; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
799 |
let mut buf = vec![0; cap]; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
800 |
decoder |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
801 |
.read_exact(&mut buf) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
802 |
.map_err(|e| corrupted(e.to_string()))?; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
803 |
Ok(buf) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
804 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
805 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
806 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
807 |
fn uncompressed_zstd_data(&self) -> Result<Vec<u8>, HgError> { |
50508
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
808 |
let cap = self.uncompressed_len.max(0) as usize; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
809 |
if self.is_delta() { |
50508
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
810 |
// [cap] is usually an over-estimate of the space needed because |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
811 |
// it's the length of delta-decoded data, but we're interested |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
812 |
// in the size of the delta. |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
813 |
// This means we have to [shrink_to_fit] to avoid holding on |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
814 |
// to a large chunk of memory, but it also means we must have a |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
815 |
// fallback branch, for the case when the delta is longer than |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
816 |
// the original data (surprisingly, this does happen in practice) |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
817 |
let mut buf = Vec::with_capacity(cap); |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
818 |
match zstd_decompress_to_buffer(self.bytes, &mut buf) { |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
819 |
Ok(_) => buf.shrink_to_fit(), |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
820 |
Err(_) => { |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
821 |
buf.clear(); |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
822 |
zstd::stream::copy_decode(self.bytes, &mut buf) |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
823 |
.map_err(|e| corrupted(e.to_string()))?; |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
824 |
} |
39ed7b2953bb
rust: mostly avoid streaming zstd decompression
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50507
diff
changeset
|
825 |
}; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
826 |
Ok(buf) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
827 |
} else { |
50507
d1cab48354bc
rust: in zstd decompression, avoid a useless vec initialization
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50506
diff
changeset
|
828 |
let mut buf = Vec::with_capacity(cap); |
50506
74d8a1b03960
rust: speed up zstd decompression by re-using the decompression context
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50413
diff
changeset
|
829 |
let len = zstd_decompress_to_buffer(self.bytes, &mut buf) |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
830 |
.map_err(|e| corrupted(e.to_string()))?; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
831 |
if len != self.uncompressed_len as usize { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
832 |
Err(corrupted("uncompressed length does not match")) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
833 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
834 |
Ok(buf) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
835 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
836 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
837 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
838 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
839 |
/// Tell if the entry is a snapshot or a delta |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
840 |
/// (influences on decompression). |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
841 |
fn is_delta(&self) -> bool { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
842 |
self.base_rev_or_base_of_delta_chain.is_some() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
843 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
844 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
845 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
846 |
/// Calculate the hash of a revision given its data and its parents. |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
847 |
fn hash( |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
848 |
data: &[u8], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
849 |
p1_hash: &[u8], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
850 |
p2_hash: &[u8], |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
851 |
) -> [u8; NODE_BYTES_LENGTH] { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
852 |
let mut hasher = Sha1::new(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
853 |
let (a, b) = (p1_hash, p2_hash); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
854 |
if a > b { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
855 |
hasher.update(b); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
856 |
hasher.update(a); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
857 |
} else { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
858 |
hasher.update(a); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
859 |
hasher.update(b); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
860 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
861 |
hasher.update(data); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
862 |
*hasher.finalize().as_ref() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
863 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
864 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
865 |
#[cfg(test)] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
866 |
mod tests { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
867 |
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
|
868 |
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
|
869 |
use itertools::Itertools; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
870 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
871 |
#[test] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
872 |
fn test_empty() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
873 |
let temp = tempfile::tempdir().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
874 |
let vfs = Vfs { base: temp.path() }; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
875 |
std::fs::write(temp.path().join("foo.i"), 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
|
876 |
let revlog = |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
877 |
Revlog::open(&vfs, "foo.i", None, RevlogOpenOptions::new()) |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
878 |
.unwrap(); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
879 |
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
|
880 |
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
|
881 |
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
|
882 |
assert!(!revlog.has_rev(0.into())); |
50745
3338c6ffdaa3
rust-revlog: using constant in test
Georges Racinet <georges.racinet@octobus.net>
parents:
50744
diff
changeset
|
883 |
assert_eq!( |
3338c6ffdaa3
rust-revlog: using constant in test
Georges Racinet <georges.racinet@octobus.net>
parents:
50744
diff
changeset
|
884 |
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
|
885 |
NULL_REVISION |
3338c6ffdaa3
rust-revlog: using constant in test
Georges Racinet <georges.racinet@octobus.net>
parents:
50744
diff
changeset
|
886 |
); |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
887 |
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
|
888 |
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
|
889 |
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
|
890 |
} |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
891 |
|
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
892 |
#[test] |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
893 |
fn test_inline() { |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
894 |
let temp = tempfile::tempdir().unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
895 |
let vfs = Vfs { base: temp.path() }; |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
896 |
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
|
897 |
.unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
898 |
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
|
899 |
.unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
900 |
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
|
901 |
.unwrap(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
902 |
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
|
903 |
.is_first(true) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
904 |
.with_version(1) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
905 |
.with_inline(true) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
906 |
.with_node(node0) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
907 |
.build(); |
51444
c3f2a9b55f59
rust-index: stop calling `with_offset` in the tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51256
diff
changeset
|
908 |
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
|
909 |
let entry2_bytes = IndexEntryBuilder::new() |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
910 |
.with_p1(Revision(0)) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
911 |
.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
|
912 |
.with_node(node2) |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
913 |
.build(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
914 |
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
|
915 |
.into_iter() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
916 |
.flatten() |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
917 |
.collect_vec(); |
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
918 |
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
|
919 |
let revlog = |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
920 |
Revlog::open(&vfs, "foo.i", None, RevlogOpenOptions::new()) |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
921 |
.unwrap(); |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
922 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
923 |
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
|
924 |
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
|
925 |
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
|
926 |
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
|
927 |
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
|
928 |
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
|
929 |
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
|
930 |
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
|
931 |
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
|
932 |
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
|
933 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
934 |
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
|
935 |
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
|
936 |
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
|
937 |
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
|
938 |
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
|
939 |
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
|
940 |
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
|
941 |
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
|
942 |
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
|
943 |
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
|
944 |
|
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
50976
diff
changeset
|
945 |
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
|
946 |
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
|
947 |
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
|
948 |
assert!(entry2.has_p1()); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
949 |
assert_eq!(entry2.p1(), Some(Revision(0))); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
950 |
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
|
951 |
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
|
952 |
assert!(p1_entry.is_some()); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
953 |
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
|
954 |
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
|
955 |
assert!(p2_entry.is_some()); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
956 |
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
|
957 |
} |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
958 |
|
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
959 |
#[test] |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
960 |
fn test_nodemap() { |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
961 |
let temp = tempfile::tempdir().unwrap(); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
962 |
let vfs = Vfs { base: temp.path() }; |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
963 |
|
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
964 |
// 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
|
965 |
// 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
|
966 |
// 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
|
967 |
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
|
968 |
.unwrap(); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
969 |
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
|
970 |
.unwrap(); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
971 |
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
|
972 |
.is_first(true) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
973 |
.with_version(1) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
974 |
.with_inline(true) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
975 |
.with_node(node0) |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
976 |
.build(); |
51444
c3f2a9b55f59
rust-index: stop calling `with_offset` in the tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51256
diff
changeset
|
977 |
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
|
978 |
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
|
979 |
.into_iter() |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
980 |
.flatten() |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
981 |
.collect_vec(); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
982 |
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
|
983 |
|
eccf7dc7c91e
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50985
diff
changeset
|
984 |
let mut idx = nodemap::tests::TestNtIndex::new(); |
50993
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
985 |
idx.insert_node(Revision(0), node0).unwrap(); |
12c308c55e53
branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
diff
changeset
|
986 |
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
|
987 |
|
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
|
988 |
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
|
989 |
&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
|
990 |
"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
|
991 |
None, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
992 |
RevlogOpenOptions::new(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
993 |
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
|
994 |
) |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51120
diff
changeset
|
995 |
.unwrap(); |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
996 |
|
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
997 |
// 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
|
998 |
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
|
999 |
|
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1000 |
assert_eq!( |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1001 |
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
|
1002 |
Revision(-1) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1003 |
); |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1004 |
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
|
1005 |
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
|
1006 |
assert_eq!( |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1007 |
revlog |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1008 |
.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
|
1009 |
.unwrap(), |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1010 |
Revision(-1) |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1011 |
); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1012 |
assert_eq!( |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1013 |
revlog |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1014 |
.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
|
1015 |
.unwrap(), |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1016 |
Revision(1) |
50744
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1017 |
); |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1018 |
// 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
|
1019 |
// (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
|
1020 |
match revlog |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1021 |
.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
|
1022 |
.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
|
1023 |
{ |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1024 |
RevlogError::AmbiguousPrefix => (), |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1025 |
e => { |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1026 |
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
|
1027 |
} |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1028 |
}; |
bca4037306da
rust-revlog: fix incorrect results with NULL_NODE prefixes
Georges Racinet <georges.racinet@octobus.net>
parents:
50743
diff
changeset
|
1029 |
} |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
47961
diff
changeset
|
1030 |
} |