Mercurial > public > mercurial-scm > hg-stable
annotate rust/hg-core/src/revlog/inner_revlog.rs @ 53040:cdd7bf612c7b stable tip
bundle-spec: properly format boolean parameter (issue6960)
This was breaking automatic clone bundle generation. This changeset fixes it and
add a test to catch it in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Mar 2025 02:29:42 +0100 |
parents | 8de68446a5bd |
children |
rev | line source |
---|---|
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1 //! A layer of lower-level revlog functionality to encapsulate most of the |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
2 //! IO work and expensive operations. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
3 use std::{ |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
4 borrow::Cow, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
5 io::{ErrorKind, Seek, SeekFrom, Write}, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
6 ops::Deref, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
7 path::PathBuf, |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
8 sync::{Arc, Mutex, RwLock}, |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
9 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
10 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
11 use schnellru::{ByMemoryUsage, LruMap}; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
12 use sha1::{Digest, Sha1}; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
14 use crate::{ |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
15 errors::{HgError, IoResultExt}, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
16 exit_codes, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
17 transaction::Transaction, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
18 vfs::Vfs, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
19 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
20 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
21 use super::{ |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
22 compression::{ |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
23 uncompressed_zstd_data, CompressionConfig, Compressor, NoneCompressor, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
24 ZlibCompressor, ZstdCompressor, ZLIB_BYTE, ZSTD_BYTE, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
25 }, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
26 file_io::{DelayedBuffer, FileHandle, RandomAccessFile, WriteHandles}, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
27 index::{Index, IndexHeader, INDEX_ENTRY_SIZE}, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
28 node::{NODE_BYTES_LENGTH, NULL_NODE}, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
29 options::{RevlogDataConfig, RevlogDeltaConfig, RevlogFeatureConfig}, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
30 BaseRevision, Node, Revision, RevlogEntry, RevlogError, RevlogIndex, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
31 UncheckedRevision, NULL_REVISION, NULL_REVLOG_ENTRY_FLAGS, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
32 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
34 /// Matches the `_InnerRevlog` class in the Python code, as an arbitrary |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
35 /// boundary to incrementally rewrite higher-level revlog functionality in |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
36 /// Rust. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
37 pub struct InnerRevlog { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
38 /// When index and data are not interleaved: bytes of the revlog index. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
39 /// When index and data are interleaved (inline revlog): bytes of the |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
40 /// revlog index and data. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
41 pub index: Index, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
42 /// The store vfs that is used to interact with the filesystem |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
43 vfs: Box<dyn Vfs>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
44 /// The index file path, relative to the vfs root |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
45 pub index_file: PathBuf, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
46 /// The data file path, relative to the vfs root (same as `index_file` |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
47 /// if inline) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
48 data_file: PathBuf, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
49 /// Data config that applies to this revlog |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
50 data_config: RevlogDataConfig, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
51 /// Delta config that applies to this revlog |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
52 delta_config: RevlogDeltaConfig, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
53 /// Feature config that applies to this revlog |
52340
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
54 #[allow(unused)] |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
55 feature_config: RevlogFeatureConfig, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 /// A view into this revlog's data file |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
57 segment_file: RandomAccessFile, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
58 /// A cache of uncompressed chunks that have previously been restored. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
59 /// Its eviction policy is defined in [`Self::new`]. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
60 uncompressed_chunk_cache: Option<UncompressedChunkCache>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
61 /// Used to keep track of the actual target during diverted writes |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
62 /// for the changelog |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
63 original_index_file: Option<PathBuf>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
64 /// Write handles to the index and data files |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
65 /// XXX why duplicate from `index` and `segment_file`? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
66 writing_handles: Option<WriteHandles>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
67 /// See [`DelayedBuffer`]. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
68 delayed_buffer: Option<Arc<Mutex<DelayedBuffer>>>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 /// Whether this revlog is inline. XXX why duplicate from `index`? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
70 pub inline: bool, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
71 /// A cache of the last revision, which is usually accessed multiple |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
72 /// times. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
73 pub last_revision_cache: Mutex<Option<SingleRevisionCache>>, |
52340
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
74 /// The [`Compressor`] that this revlog uses by default to compress data. |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
75 /// This does not mean that this revlog uses this compressor for reading |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
76 /// data, as different revisions may have different compression modes. |
52341
f69a3f55fa9b
rust-compression: move the `Send` bound to the `Compressor` trait
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52340
diff
changeset
|
77 compressor: Mutex<Box<dyn Compressor>>, |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
78 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
80 impl InnerRevlog { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
81 pub fn new( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
82 vfs: Box<dyn Vfs>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
83 index: Index, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
84 index_file: PathBuf, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
85 data_file: PathBuf, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
86 data_config: RevlogDataConfig, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
87 delta_config: RevlogDeltaConfig, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
88 feature_config: RevlogFeatureConfig, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
89 ) -> Self { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
90 assert!(index_file.is_relative()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
91 assert!(data_file.is_relative()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
92 let segment_file = RandomAccessFile::new( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
93 dyn_clone::clone_box(&*vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
94 if index.is_inline() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
95 index_file.to_owned() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
96 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
97 data_file.to_owned() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
98 }, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
99 ); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
101 let uncompressed_chunk_cache = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
102 data_config.uncompressed_cache_factor.map( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
103 // Arbitrary initial value |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
104 // TODO check if using a hasher specific to integers is useful |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
105 |_factor| RwLock::new(LruMap::with_memory_budget(65536)), |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
106 ); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
107 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
108 let inline = index.is_inline(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
109 Self { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
110 index, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
111 vfs, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
112 index_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
113 data_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
114 data_config, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
115 delta_config, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
116 feature_config, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
117 segment_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
118 uncompressed_chunk_cache, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
119 original_index_file: None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
120 writing_handles: None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
121 delayed_buffer: None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
122 inline, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
123 last_revision_cache: Mutex::new(None), |
52340
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
124 compressor: Mutex::new(match feature_config.compression_engine { |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
125 CompressionConfig::Zlib { level } => { |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
126 Box::new(ZlibCompressor::new(level)) |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
127 } |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
128 CompressionConfig::Zstd { level, threads } => { |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
129 Box::new(ZstdCompressor::new(level, threads)) |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
130 } |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
131 CompressionConfig::None => Box::new(NoneCompressor), |
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
132 }), |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
133 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
134 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
135 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
136 /// Return number of entries of the revlog index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
137 pub fn len(&self) -> usize { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
138 self.index.len() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
139 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
141 /// Return `true` if this revlog has no entries |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
142 pub fn is_empty(&self) -> bool { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
143 self.len() == 0 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
144 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
145 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
146 /// Return whether this revlog is inline (mixed index and data) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
147 pub fn is_inline(&self) -> bool { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
148 self.inline |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
149 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
150 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
151 /// Clear all caches from this revlog |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
152 pub fn clear_cache(&mut self) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
153 assert!(!self.is_delaying()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
154 if let Some(cache) = self.uncompressed_chunk_cache.as_ref() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
155 // We don't clear the allocation here because it's probably faster. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
156 // We could change our minds later if this ends up being a problem |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
157 // with regards to memory consumption. |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
158 cache.write().expect("lock is poisoned").clear(); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
159 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
160 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
161 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
162 /// Return an entry for the null revision |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
163 pub fn make_null_entry(&self) -> RevlogEntry { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
164 RevlogEntry { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
165 revlog: self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
166 rev: NULL_REVISION, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
167 uncompressed_len: 0, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
168 p1: NULL_REVISION, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
169 p2: NULL_REVISION, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
170 flags: NULL_REVLOG_ENTRY_FLAGS, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
171 hash: NULL_NODE, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
172 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
173 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
174 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
175 /// Return the [`RevlogEntry`] for a [`Revision`] that is known to exist |
52326
a3fa37bdb7ec
rust: normalize `_for_unchecked_rev` naming among revlogs and the index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52311
diff
changeset
|
176 pub fn get_entry( |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
177 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
178 rev: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
179 ) -> Result<RevlogEntry, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
180 if rev == NULL_REVISION { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
181 return Ok(self.make_null_entry()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
182 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
183 let index_entry = self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
184 .index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
185 .get_entry(rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
186 .ok_or_else(|| RevlogError::InvalidRevision(rev.to_string()))?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
187 let p1 = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
188 self.index.check_revision(index_entry.p1()).ok_or_else(|| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
189 RevlogError::corrupted(format!( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
190 "p1 for rev {} is invalid", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
191 rev |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
192 )) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
193 })?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
194 let p2 = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
195 self.index.check_revision(index_entry.p2()).ok_or_else(|| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
196 RevlogError::corrupted(format!( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
197 "p2 for rev {} is invalid", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
198 rev |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
199 )) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
200 })?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
201 let entry = RevlogEntry { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
202 revlog: self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
203 rev, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
204 uncompressed_len: index_entry.uncompressed_len(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
205 p1, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
206 p2, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
207 flags: index_entry.flags(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
208 hash: *index_entry.hash(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
209 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
210 Ok(entry) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
211 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
212 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
213 /// Return the [`RevlogEntry`] for `rev`. If `rev` fails to check, this |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
214 /// returns a [`RevlogError`]. |
52326
a3fa37bdb7ec
rust: normalize `_for_unchecked_rev` naming among revlogs and the index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52311
diff
changeset
|
215 pub fn get_entry_for_unchecked_rev( |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
216 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
217 rev: UncheckedRevision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
218 ) -> Result<RevlogEntry, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
219 if rev == NULL_REVISION.into() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
220 return Ok(self.make_null_entry()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
221 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
222 let rev = self.index.check_revision(rev).ok_or_else(|| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
223 RevlogError::corrupted(format!("rev {} is invalid", rev)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
224 })?; |
52326
a3fa37bdb7ec
rust: normalize `_for_unchecked_rev` naming among revlogs and the index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52311
diff
changeset
|
225 self.get_entry(rev) |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
226 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
227 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
228 /// Is the revlog currently delaying the visibility of written data? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
229 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
230 /// The delaying mechanism can be either in-memory or written on disk in a |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
231 /// side-file. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
232 pub fn is_delaying(&self) -> bool { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
233 self.delayed_buffer.is_some() || self.original_index_file.is_some() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
234 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
235 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
236 /// The offset of the data chunk for this revision |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
237 #[inline(always)] |
52332
e2319309bed4
rust-revlog: rename `start` to `data_start`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52331
diff
changeset
|
238 pub fn data_start(&self, rev: Revision) -> usize { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
239 self.index.start( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
240 rev, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
241 &self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
242 .index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
243 .get_entry(rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
244 .unwrap_or_else(|| self.index.make_null_entry()), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
245 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
246 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
247 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
248 /// The length of the data chunk for this revision |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
249 #[inline(always)] |
52331
4d0c0c255425
rust-revlog: rename `length` to `data_compressed_length`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52330
diff
changeset
|
250 pub fn data_compressed_length(&self, rev: Revision) -> usize { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
251 self.index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
252 .get_entry(rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
253 .unwrap_or_else(|| self.index.make_null_entry()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
254 .compressed_len() as usize |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
255 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
256 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
257 /// The end of the data chunk for this revision |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
258 #[inline(always)] |
52333
7ffc71552662
rust-revlog: rename `end` to `data_end`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52332
diff
changeset
|
259 pub fn data_end(&self, rev: Revision) -> usize { |
52332
e2319309bed4
rust-revlog: rename `start` to `data_start`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52331
diff
changeset
|
260 self.data_start(rev) + self.data_compressed_length(rev) |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
261 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
262 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
263 /// Return the delta parent of the given revision |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
264 pub fn delta_parent(&self, rev: Revision) -> Revision { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
265 let base = self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
266 .index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
267 .get_entry(rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
268 .unwrap() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
269 .base_revision_or_base_of_delta_chain(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
270 if base.0 == rev.0 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
271 NULL_REVISION |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
272 } else if self.delta_config.general_delta { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
273 Revision(base.0) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
274 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
275 Revision(rev.0 - 1) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
276 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
277 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
278 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
279 /// Return whether `rev` points to a snapshot revision (i.e. does not have |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
280 /// a delta base). |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
281 pub fn is_snapshot(&self, rev: Revision) -> Result<bool, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
282 if !self.delta_config.sparse_revlog { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
283 return Ok(self.delta_parent(rev) == NULL_REVISION); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
284 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
285 self.index.is_snapshot_unchecked(rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
286 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
287 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
288 /// Return the delta chain for `rev` according to this revlog's config. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
289 /// See [`Index::delta_chain`] for more information. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
290 pub fn delta_chain( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
291 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
292 rev: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
293 stop_rev: Option<Revision>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
294 ) -> Result<(Vec<Revision>, bool), HgError> { |
52896
8de68446a5bd
index: remember the generaldelta config instead of getting it from the revlog
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52780
diff
changeset
|
295 self.index.delta_chain(rev, stop_rev) |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
296 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
297 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
298 /// Generate a possibly-compressed representation of data. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
299 /// Returns `None` if the data was not compressed. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
300 pub fn compress<'data>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
301 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
302 data: &'data [u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
303 ) -> Result<Option<Cow<'data, [u8]>>, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
304 if data.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
305 return Ok(Some(data.into())); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
306 } |
52340
7756494c5ecd
rust-inner-revlog: cache the compressor
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52333
diff
changeset
|
307 let res = self.compressor.lock().unwrap().compress(data)?; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
308 if let Some(compressed) = res { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
309 // The revlog compressor added the header in the returned data. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
310 return Ok(Some(compressed.into())); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
311 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
312 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
313 if data[0] == b'\0' { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
314 return Ok(Some(data.into())); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
315 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
316 Ok(None) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
317 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
318 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
319 /// Decompress a revlog chunk. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
320 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
321 /// The chunk is expected to begin with a header identifying the |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
322 /// format type so it can be routed to an appropriate decompressor. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
323 pub fn decompress<'a>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
324 &'a self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
325 data: &'a [u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
326 ) -> Result<Cow<[u8]>, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
327 if data.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
328 return Ok(data.into()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
329 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
330 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
331 // Revlogs are read much more frequently than they are written and many |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
332 // chunks only take microseconds to decompress, so performance is |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
333 // important here. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
334 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
335 let header = data[0]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
336 match header { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
337 // Settings don't matter as they only affect compression |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
338 ZLIB_BYTE => Ok(ZlibCompressor::new(0).decompress(data)?.into()), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
339 // Settings don't matter as they only affect compression |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
340 ZSTD_BYTE => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
341 Ok(ZstdCompressor::new(0, 0).decompress(data)?.into()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
342 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
343 b'\0' => Ok(data.into()), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
344 b'u' => Ok((&data[1..]).into()), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
345 other => Err(HgError::UnsupportedFeature(format!( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
346 "unknown compression header '{}'", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
347 other |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
348 )) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
349 .into()), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
350 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
351 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
352 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
353 /// Obtain a segment of raw data corresponding to a range of revisions. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
354 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
355 /// Requests for data may be satisfied by a cache. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
356 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
357 /// Returns a 2-tuple of (offset, data) for the requested range of |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
358 /// revisions. Offset is the integer offset from the beginning of the |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
359 /// revlog and data is a slice of the raw byte data. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
360 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
361 /// Callers will need to call `self.start(rev)` and `self.length(rev)` |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
362 /// to determine where each revision's data begins and ends. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
363 pub fn get_segment_for_revs( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
364 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
365 start_rev: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
366 end_rev: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
367 ) -> Result<(usize, Vec<u8>), HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
368 let start = if start_rev == NULL_REVISION { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
369 0 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
370 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
371 let start_entry = self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
372 .index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
373 .get_entry(start_rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
374 .expect("null revision segment"); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
375 self.index.start(start_rev, &start_entry) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
376 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
377 let end_entry = self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
378 .index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
379 .get_entry(end_rev) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
380 .expect("null revision segment"); |
52331
4d0c0c255425
rust-revlog: rename `length` to `data_compressed_length`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52330
diff
changeset
|
381 let end = self.index.start(end_rev, &end_entry) |
4d0c0c255425
rust-revlog: rename `length` to `data_compressed_length`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52330
diff
changeset
|
382 + self.data_compressed_length(end_rev); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
383 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
384 let length = end - start; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
385 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
386 // XXX should we use mmap instead of doing this for platforms that |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
387 // support madvise/populate? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
388 Ok((start, self.segment_file.read_chunk(start, length)?)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
389 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
390 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
391 /// Return the uncompressed raw data for `rev` |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
392 pub fn chunk_for_rev(&self, rev: Revision) -> Result<Arc<[u8]>, HgError> { |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
393 if let Some(Ok(mut cache)) = self |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
394 .uncompressed_chunk_cache |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
395 .as_ref() |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
396 .map(|c| c.try_write()) |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
397 { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
398 if let Some(chunk) = cache.get(&rev) { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
399 return Ok(chunk.clone()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
400 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
401 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
402 // TODO revlogv2 should check the compression mode |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
403 let data = self.get_segment_for_revs(rev, rev)?.1; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
404 let uncompressed = self.decompress(&data).map_err(|e| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
405 HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
406 format!("revlog decompression error: {}", e), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
407 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
408 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
409 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
410 })?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
411 let uncompressed: Arc<[u8]> = Arc::from(uncompressed.into_owned()); |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
412 if let Some(Ok(mut cache)) = self |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
413 .uncompressed_chunk_cache |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
414 .as_ref() |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
415 .map(|c| c.try_write()) |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
416 { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
417 cache.insert(rev, uncompressed.clone()); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
418 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
419 Ok(uncompressed) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
420 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
421 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
422 /// Execute `func` within a read context for the data file, meaning that |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
423 /// the read handle will be taken and discarded after the operation. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
424 pub fn with_read<R>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
425 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
426 func: impl FnOnce() -> Result<R, RevlogError>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
427 ) -> Result<R, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
428 self.enter_reading_context()?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
429 let res = func(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
430 self.exit_reading_context(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
431 res.map_err(Into::into) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
432 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
433 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
434 /// `pub` only for use in hg-cpython |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
435 #[doc(hidden)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
436 pub fn enter_reading_context(&self) -> Result<(), HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
437 if self.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
438 // Nothing to be read |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
439 return Ok(()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
440 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
441 if self.delayed_buffer.is_some() && self.is_inline() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
442 return Err(HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
443 "revlog with delayed write should not be inline", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
444 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
445 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
446 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
447 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
448 self.segment_file.get_read_handle()?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
449 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
450 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
451 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
452 /// `pub` only for use in hg-cpython |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
453 #[doc(hidden)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
454 pub fn exit_reading_context(&self) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
455 self.segment_file.exit_reading_context() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
456 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
457 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
458 /// Fill the buffer returned by `get_buffer` with the possibly un-validated |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
459 /// raw text for a revision. It can be already validated if it comes |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
460 /// from the cache. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
461 pub fn raw_text<G, T>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
462 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
463 rev: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
464 get_buffer: G, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
465 ) -> Result<(), RevlogError> |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
466 where |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
467 G: FnOnce( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
468 usize, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
469 &mut dyn FnMut( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
470 &mut dyn RevisionBuffer<Target = T>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
471 ) -> Result<(), RevlogError>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
472 ) -> Result<(), RevlogError>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
473 { |
52326
a3fa37bdb7ec
rust: normalize `_for_unchecked_rev` naming among revlogs and the index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52311
diff
changeset
|
474 let entry = &self.get_entry(rev)?; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
475 let raw_size = entry.uncompressed_len(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
476 let mut mutex_guard = self |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
477 .last_revision_cache |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
478 .lock() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
479 .expect("lock should not be held"); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
480 let cached_rev = if let Some((_node, rev, data)) = &*mutex_guard { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
481 Some((*rev, data.deref().as_ref())) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
482 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
483 None |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
484 }; |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
485 if let (Some(size), Some(Ok(mut cache))) = ( |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
486 raw_size, |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
487 self.uncompressed_chunk_cache |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
488 .as_ref() |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
489 .map(|c| c.try_write()), |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
490 ) { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
491 // Dynamically update the uncompressed_chunk_cache size to the |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
492 // largest revision we've seen in this revlog. |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
493 // Do it *before* restoration in case the current revision |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
494 // is the largest. |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
495 let factor = self |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
496 .data_config |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
497 .uncompressed_cache_factor |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
498 .expect("cache should not exist without factor"); |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
499 let candidate_size = (size as f64 * factor) as usize; |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
500 let limiter_mut = cache.limiter_mut(); |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
501 if candidate_size > limiter_mut.max_memory_usage() { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
502 std::mem::swap( |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
503 limiter_mut, |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
504 &mut ByMemoryUsage::new(candidate_size), |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
505 ); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
506 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
507 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
508 entry.rawdata(cached_rev, get_buffer)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
509 // drop cache to save memory, the caller is expected to update |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
510 // the revision cache after validating the text |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
511 mutex_guard.take(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
512 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
513 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
514 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
515 /// Only `pub` for `hg-cpython`. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
516 /// Obtain decompressed raw data for the specified revisions that are |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
517 /// assumed to be in ascending order. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
518 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
519 /// Returns a list with decompressed data for each requested revision. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
520 #[doc(hidden)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
521 pub fn chunks( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
522 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
523 revs: Vec<Revision>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
524 target_size: Option<u64>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
525 ) -> Result<Vec<Arc<[u8]>>, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
526 if revs.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
527 return Ok(vec![]); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
528 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
529 let mut fetched_revs = vec![]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
530 let mut chunks = Vec::with_capacity(revs.len()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
531 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
532 match self.uncompressed_chunk_cache.as_ref() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
533 Some(cache) => { |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
534 if let Ok(mut cache) = cache.try_write() { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
535 for rev in revs.iter() { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
536 match cache.get(rev) { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
537 Some(hit) => chunks.push((*rev, hit.to_owned())), |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
538 None => fetched_revs.push(*rev), |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
539 } |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
540 } |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
541 } else { |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
542 fetched_revs = revs |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
543 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
544 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
545 None => fetched_revs = revs, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
546 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
547 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
548 let already_cached = chunks.len(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
549 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
550 let sliced_chunks = if fetched_revs.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
551 vec![] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
552 } else if !self.data_config.with_sparse_read || self.is_inline() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
553 vec![fetched_revs] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
554 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
555 self.slice_chunk(&fetched_revs, target_size)? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
556 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
557 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
558 self.with_read(|| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
559 for revs_chunk in sliced_chunks { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
560 let first_rev = revs_chunk[0]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
561 // Skip trailing revisions with empty diff |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
562 let last_rev_idx = revs_chunk |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
563 .iter() |
52331
4d0c0c255425
rust-revlog: rename `length` to `data_compressed_length`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52330
diff
changeset
|
564 .rposition(|r| self.data_compressed_length(*r) != 0) |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
565 .unwrap_or(revs_chunk.len() - 1); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
566 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
567 let last_rev = revs_chunk[last_rev_idx]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
568 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
569 let (offset, data) = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
570 self.get_segment_for_revs(first_rev, last_rev)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
571 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
572 let revs_chunk = &revs_chunk[..=last_rev_idx]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
573 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
574 for rev in revs_chunk { |
52332
e2319309bed4
rust-revlog: rename `start` to `data_start`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52331
diff
changeset
|
575 let chunk_start = self.data_start(*rev); |
52331
4d0c0c255425
rust-revlog: rename `length` to `data_compressed_length`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52330
diff
changeset
|
576 let chunk_length = self.data_compressed_length(*rev); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
577 // TODO revlogv2 should check the compression mode |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
578 let bytes = &data[chunk_start - offset..][..chunk_length]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
579 let chunk = if !bytes.is_empty() && bytes[0] == ZSTD_BYTE { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
580 // If we're using `zstd`, we want to try a more |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
581 // specialized decompression |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
582 let entry = self.index.get_entry(*rev).unwrap(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
583 let is_delta = entry |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
584 .base_revision_or_base_of_delta_chain() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
585 != (*rev).into(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
586 let uncompressed = uncompressed_zstd_data( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
587 bytes, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
588 is_delta, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
589 entry.uncompressed_len(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
590 )?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
591 Cow::Owned(uncompressed) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
592 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
593 // Otherwise just fallback to generic decompression. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
594 self.decompress(bytes)? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
595 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
596 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
597 chunks.push((*rev, chunk.into())); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
598 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
599 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
600 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
601 })?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
602 |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
603 if let Some(Ok(mut cache)) = self |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
604 .uncompressed_chunk_cache |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
605 .as_ref() |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
606 .map(|c| c.try_write()) |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
607 { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
608 for (rev, chunk) in chunks.iter().skip(already_cached) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
609 cache.insert(*rev, chunk.clone()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
610 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
611 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
612 // Use stable sort here since it's *mostly* sorted |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
613 chunks.sort_by(|a, b| a.0.cmp(&b.0)); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
614 Ok(chunks.into_iter().map(|(_r, chunk)| chunk).collect()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
615 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
616 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
617 /// Slice revs to reduce the amount of unrelated data to be read from disk. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
618 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
619 /// ``revs`` is sliced into groups that should be read in one time. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
620 /// Assume that revs are sorted. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
621 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
622 /// The initial chunk is sliced until the overall density |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
623 /// (payload/chunks-span ratio) is above |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
624 /// `revlog.data_config.sr_density_threshold`. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
625 /// No gap smaller than `revlog.data_config.sr_min_gap_size` is skipped. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
626 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
627 /// If `target_size` is set, no chunk larger than `target_size` |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
628 /// will be returned. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
629 /// For consistency with other slicing choices, this limit won't go lower |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
630 /// than `revlog.data_config.sr_min_gap_size`. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
631 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
632 /// If individual revision chunks are larger than this limit, they will |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
633 /// still be raised individually. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
634 pub fn slice_chunk( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
635 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
636 revs: &[Revision], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
637 target_size: Option<u64>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
638 ) -> Result<Vec<Vec<Revision>>, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
639 let target_size = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
640 target_size.map(|size| size.max(self.data_config.sr_min_gap_size)); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
641 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
642 let target_density = self.data_config.sr_density_threshold; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
643 let min_gap_size = self.data_config.sr_min_gap_size as usize; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
644 let to_density = self.index.slice_chunk_to_density( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
645 revs, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
646 target_density, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
647 min_gap_size, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
648 ); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
649 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
650 let mut sliced = vec![]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
651 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
652 for chunk in to_density { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
653 sliced.extend( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
654 self.slice_chunk_to_size(&chunk, target_size)? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
655 .into_iter() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
656 .map(ToOwned::to_owned), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
657 ); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
658 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
659 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
660 Ok(sliced) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
661 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
662 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
663 /// Slice revs to match the target size |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
664 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
665 /// This is intended to be used on chunks that density slicing selected, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
666 /// but that are still too large compared to the read guarantee of revlogs. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
667 /// This might happen when the "minimal gap size" interrupted the slicing |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
668 /// or when chains are built in a way that create large blocks next to |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
669 /// each other. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
670 fn slice_chunk_to_size<'a>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
671 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
672 revs: &'a [Revision], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
673 target_size: Option<u64>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
674 ) -> Result<Vec<&'a [Revision]>, RevlogError> { |
52332
e2319309bed4
rust-revlog: rename `start` to `data_start`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52331
diff
changeset
|
675 let mut start_data = self.data_start(revs[0]); |
52333
7ffc71552662
rust-revlog: rename `end` to `data_end`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52332
diff
changeset
|
676 let end_data = self.data_end(revs[revs.len() - 1]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
677 let full_span = end_data - start_data; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
678 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
679 let nothing_to_do = target_size |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
680 .map(|size| full_span <= size as usize) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
681 .unwrap_or(true); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
682 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
683 if nothing_to_do { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
684 return Ok(vec![revs]); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
685 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
686 let target_size = target_size.expect("target_size is set") as usize; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
687 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
688 let mut start_rev_idx = 0; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
689 let mut end_rev_idx = 1; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
690 let mut chunks = vec![]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
691 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
692 for (idx, rev) in revs.iter().enumerate().skip(1) { |
52333
7ffc71552662
rust-revlog: rename `end` to `data_end`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52332
diff
changeset
|
693 let span = self.data_end(*rev) - start_data; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
694 let is_snapshot = self.is_snapshot(*rev)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
695 if span <= target_size && is_snapshot { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
696 end_rev_idx = idx + 1; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
697 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
698 let chunk = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
699 self.trim_chunk(revs, start_rev_idx, Some(end_rev_idx)); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
700 if !chunk.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
701 chunks.push(chunk); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
702 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
703 start_rev_idx = idx; |
52332
e2319309bed4
rust-revlog: rename `start` to `data_start`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52331
diff
changeset
|
704 start_data = self.data_start(*rev); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
705 end_rev_idx = idx + 1; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
706 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
707 if !is_snapshot { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
708 break; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
709 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
710 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
711 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
712 // For the others, we use binary slicing to quickly converge towards |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
713 // valid chunks (otherwise, we might end up looking for the start/end |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
714 // of many revisions). This logic is not looking for the perfect |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
715 // slicing point, it quickly converges towards valid chunks. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
716 let number_of_items = revs.len(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
717 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
718 while (end_data - start_data) > target_size { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
719 end_rev_idx = number_of_items; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
720 if number_of_items - start_rev_idx <= 1 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
721 // Protect against individual chunks larger than the limit |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
722 break; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
723 } |
52333
7ffc71552662
rust-revlog: rename `end` to `data_end`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52332
diff
changeset
|
724 let mut local_end_data = self.data_end(revs[end_rev_idx - 1]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
725 let mut span = local_end_data - start_data; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
726 while span > target_size { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
727 if end_rev_idx - start_rev_idx <= 1 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
728 // Protect against individual chunks larger than the limit |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
729 break; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
730 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
731 end_rev_idx -= (end_rev_idx - start_rev_idx) / 2; |
52333
7ffc71552662
rust-revlog: rename `end` to `data_end`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52332
diff
changeset
|
732 local_end_data = self.data_end(revs[end_rev_idx - 1]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
733 span = local_end_data - start_data; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
734 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
735 let chunk = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
736 self.trim_chunk(revs, start_rev_idx, Some(end_rev_idx)); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
737 if !chunk.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
738 chunks.push(chunk); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
739 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
740 start_rev_idx = end_rev_idx; |
52332
e2319309bed4
rust-revlog: rename `start` to `data_start`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52331
diff
changeset
|
741 start_data = self.data_start(revs[start_rev_idx]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
742 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
743 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
744 let chunk = self.trim_chunk(revs, start_rev_idx, None); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
745 if !chunk.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
746 chunks.push(chunk); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
747 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
748 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
749 Ok(chunks) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
750 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
751 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
752 /// Returns `revs[startidx..endidx]` without empty trailing revs |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
753 fn trim_chunk<'a>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
754 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
755 revs: &'a [Revision], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
756 start_rev_idx: usize, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
757 end_rev_idx: Option<usize>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
758 ) -> &'a [Revision] { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
759 let mut end_rev_idx = end_rev_idx.unwrap_or(revs.len()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
760 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
761 // If we have a non-empty delta candidate, there is nothing to trim |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
762 if revs[end_rev_idx - 1].0 < self.len() as BaseRevision { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
763 // Trim empty revs at the end, except the very first rev of a chain |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
764 while end_rev_idx > 1 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
765 && end_rev_idx > start_rev_idx |
52331
4d0c0c255425
rust-revlog: rename `length` to `data_compressed_length`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52330
diff
changeset
|
766 && self.data_compressed_length(revs[end_rev_idx - 1]) == 0 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
767 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
768 end_rev_idx -= 1 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
769 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
770 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
771 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
772 &revs[start_rev_idx..end_rev_idx] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
773 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
774 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
775 /// Check the hash of some given data against the recorded hash. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
776 pub fn check_hash( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
777 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
778 p1: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
779 p2: Revision, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
780 expected: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
781 data: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
782 ) -> bool { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
783 let e1 = self.index.get_entry(p1); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
784 let h1 = match e1 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
785 Some(ref entry) => entry.hash(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
786 None => &NULL_NODE, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
787 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
788 let e2 = self.index.get_entry(p2); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
789 let h2 = match e2 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
790 Some(ref entry) => entry.hash(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
791 None => &NULL_NODE, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
792 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
793 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
794 hash(data, h1.as_bytes(), h2.as_bytes()) == expected |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
795 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
796 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
797 /// Returns whether we are currently in a [`Self::with_write`] context |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
798 pub fn is_writing(&self) -> bool { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
799 self.writing_handles.is_some() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
800 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
801 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
802 /// Open the revlog files for writing |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
803 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
804 /// Adding content to a revlog should be done within this context. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
805 /// TODO try using `BufRead` and `BufWrite` and see if performance improves |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
806 pub fn with_write<R>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
807 &mut self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
808 transaction: &mut impl Transaction, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
809 data_end: Option<usize>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
810 func: impl FnOnce() -> R, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
811 ) -> Result<R, HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
812 if self.is_writing() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
813 return Ok(func()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
814 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
815 self.enter_writing_context(data_end, transaction) |
52327
f90796d33aa0
rust: fix clippy lints
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52326
diff
changeset
|
816 .inspect_err(|_| { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
817 self.exit_writing_context(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
818 })?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
819 let res = func(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
820 self.exit_writing_context(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
821 Ok(res) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
822 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
823 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
824 /// `pub` only for use in hg-cpython |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
825 #[doc(hidden)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
826 pub fn exit_writing_context(&mut self) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
827 self.writing_handles.take(); |
52780
549b58b1ce72
rust-inner-revlog: use threadlocals for file handles
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52779
diff
changeset
|
828 self.segment_file.writing_handle.get().map(|h| h.take()); |
549b58b1ce72
rust-inner-revlog: use threadlocals for file handles
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52779
diff
changeset
|
829 self.segment_file.reading_handle.get().map(|h| h.take()); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
830 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
831 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
832 /// `pub` only for use in hg-cpython |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
833 #[doc(hidden)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
834 pub fn python_writing_handles(&self) -> Option<&WriteHandles> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
835 self.writing_handles.as_ref() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
836 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
837 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
838 /// `pub` only for use in hg-cpython |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
839 #[doc(hidden)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
840 pub fn enter_writing_context( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
841 &mut self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
842 data_end: Option<usize>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
843 transaction: &mut impl Transaction, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
844 ) -> Result<(), HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
845 let data_size = if self.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
846 0 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
847 } else { |
52333
7ffc71552662
rust-revlog: rename `end` to `data_end`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52332
diff
changeset
|
848 self.data_end(Revision((self.len() - 1) as BaseRevision)) |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
849 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
850 let data_handle = if !self.is_inline() { |
52330
645d247d4c75
rust-vfs: rename `open` to `open_write` and `open_read` to `open`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52327
diff
changeset
|
851 let data_handle = match self.vfs.open_write(&self.data_file) { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
852 Ok(mut f) => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
853 if let Some(end) = data_end { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
854 f.seek(SeekFrom::Start(end as u64)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
855 .when_reading_file(&self.data_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
856 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
857 f.seek(SeekFrom::End(0)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
858 .when_reading_file(&self.data_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
859 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
860 f |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
861 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
862 Err(e) => match e { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
863 HgError::IoError { error, context } => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
864 if error.kind() != ErrorKind::NotFound { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
865 return Err(HgError::IoError { error, context }); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
866 } |
52311
8d35941689af
rust-vfs: support checkambig
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52290
diff
changeset
|
867 self.vfs.create(&self.data_file, true)? |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
868 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
869 e => return Err(e), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
870 }, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
871 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
872 transaction.add(&self.data_file, data_size); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
873 Some(FileHandle::from_file( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
874 data_handle, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
875 dyn_clone::clone_box(&*self.vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
876 &self.data_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
877 )) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
878 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
879 None |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
880 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
881 let index_size = self.len() * INDEX_ENTRY_SIZE; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
882 let index_handle = self.index_write_handle()?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
883 if self.is_inline() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
884 transaction.add(&self.index_file, data_size); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
885 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
886 transaction.add(&self.index_file, index_size); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
887 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
888 self.writing_handles = Some(WriteHandles { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
889 index_handle: index_handle.clone(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
890 data_handle: data_handle.clone(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
891 }); |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
892 *self |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
893 .segment_file |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
894 .reading_handle |
52780
549b58b1ce72
rust-inner-revlog: use threadlocals for file handles
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52779
diff
changeset
|
895 .get_or_default() |
549b58b1ce72
rust-inner-revlog: use threadlocals for file handles
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52779
diff
changeset
|
896 .borrow_mut() = if self.is_inline() { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
897 Some(index_handle) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
898 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
899 data_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
900 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
901 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
902 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
903 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
904 /// Get a write handle to the index, sought to the end of its data. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
905 fn index_write_handle(&self) -> Result<FileHandle, HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
906 let res = if self.delayed_buffer.is_none() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
907 if self.data_config.check_ambig { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
908 self.vfs.open_check_ambig(&self.index_file) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
909 } else { |
52330
645d247d4c75
rust-vfs: rename `open` to `open_write` and `open_read` to `open`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52327
diff
changeset
|
910 self.vfs.open_write(&self.index_file) |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
911 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
912 } else { |
52330
645d247d4c75
rust-vfs: rename `open` to `open_write` and `open_read` to `open`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52327
diff
changeset
|
913 self.vfs.open_write(&self.index_file) |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
914 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
915 match res { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
916 Ok(mut handle) => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
917 handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
918 .seek(SeekFrom::End(0)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
919 .when_reading_file(&self.index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
920 Ok( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
921 if let Some(delayed_buffer) = self.delayed_buffer.as_ref() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
922 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
923 FileHandle::from_file_delayed( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
924 handle, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
925 dyn_clone::clone_box(&*self.vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
926 &self.index_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
927 delayed_buffer.clone(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
928 )? |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
929 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
930 FileHandle::from_file( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
931 handle, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
932 dyn_clone::clone_box(&*self.vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
933 &self.index_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
934 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
935 }, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
936 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
937 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
938 Err(e) => match e { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
939 HgError::IoError { error, context } => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
940 if error.kind() != ErrorKind::NotFound { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
941 return Err(HgError::IoError { error, context }); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
942 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
943 if let Some(delayed_buffer) = self.delayed_buffer.as_ref() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
944 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
945 FileHandle::new_delayed( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
946 dyn_clone::clone_box(&*self.vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
947 &self.index_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
948 true, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
949 delayed_buffer.clone(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
950 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
951 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
952 FileHandle::new( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
953 dyn_clone::clone_box(&*self.vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
954 &self.index_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
955 true, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
956 true, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
957 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
958 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
959 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
960 e => Err(e), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
961 }, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
962 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
963 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
964 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
965 /// Split the data of an inline revlog into an index and a data file |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
966 pub fn split_inline( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
967 &mut self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
968 header: IndexHeader, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
969 new_index_file_path: Option<PathBuf>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
970 ) -> Result<PathBuf, RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
971 assert!(self.delayed_buffer.is_none()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
972 let existing_handles = self.writing_handles.is_some(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
973 if let Some(handles) = &mut self.writing_handles { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
974 handles.index_handle.flush()?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
975 self.writing_handles.take(); |
52780
549b58b1ce72
rust-inner-revlog: use threadlocals for file handles
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52779
diff
changeset
|
976 self.segment_file.writing_handle.get().map(|h| h.take()); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
977 } |
52311
8d35941689af
rust-vfs: support checkambig
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52290
diff
changeset
|
978 let mut new_data_file_handle = |
8d35941689af
rust-vfs: support checkambig
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52290
diff
changeset
|
979 self.vfs.create(&self.data_file, true)?; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
980 // Drop any potential data, possibly redundant with the VFS impl. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
981 new_data_file_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
982 .set_len(0) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
983 .when_writing_file(&self.data_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
984 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
985 self.with_read(|| -> Result<(), RevlogError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
986 for r in 0..self.index.len() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
987 let rev = Revision(r as BaseRevision); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
988 let rev_segment = self.get_segment_for_revs(rev, rev)?.1; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
989 new_data_file_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
990 .write_all(&rev_segment) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
991 .when_writing_file(&self.data_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
992 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
993 new_data_file_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
994 .flush() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
995 .when_writing_file(&self.data_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
996 Ok(()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
997 })?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
998 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
999 if let Some(index_path) = new_index_file_path { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1000 self.index_file = index_path |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1001 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1002 |
52311
8d35941689af
rust-vfs: support checkambig
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52290
diff
changeset
|
1003 let mut new_index_handle = self.vfs.create(&self.index_file, true)?; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1004 let mut new_data = Vec::with_capacity(self.len() * INDEX_ENTRY_SIZE); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1005 for r in 0..self.len() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1006 let rev = Revision(r as BaseRevision); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1007 let entry = self.index.entry_binary(rev).unwrap_or_else(|| { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1008 panic!( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1009 "entry {} should exist in {}", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1010 r, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1011 self.index_file.display() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1012 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1013 }); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1014 if r == 0 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1015 new_data.extend(header.header_bytes); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1016 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1017 new_data.extend(entry); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1018 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1019 new_index_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1020 .write_all(&new_data) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1021 .when_writing_file(&self.index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1022 // Replace the index with a new one because the buffer contains inline |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1023 // data |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1024 self.index = Index::new(Box::new(new_data), header)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1025 self.inline = false; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1026 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1027 self.segment_file = RandomAccessFile::new( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1028 dyn_clone::clone_box(&*self.vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1029 self.data_file.to_owned(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1030 ); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1031 if existing_handles { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1032 // Switched from inline to conventional, reopen the index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1033 let new_data_handle = Some(FileHandle::from_file( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1034 new_data_file_handle, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1035 dyn_clone::clone_box(&*self.vfs), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1036 &self.data_file, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1037 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1038 self.writing_handles = Some(WriteHandles { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1039 index_handle: self.index_write_handle()?, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1040 data_handle: new_data_handle.clone(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1041 }); |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
1042 *self |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
1043 .segment_file |
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
1044 .writing_handle |
52780
549b58b1ce72
rust-inner-revlog: use threadlocals for file handles
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52779
diff
changeset
|
1045 .get_or_default() |
549b58b1ce72
rust-inner-revlog: use threadlocals for file handles
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52779
diff
changeset
|
1046 .borrow_mut() = new_data_handle; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1047 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1048 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1049 Ok(self.index_file.to_owned()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1050 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1051 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1052 /// Write a new entry to this revlog. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1053 /// - `entry` is the index bytes |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1054 /// - `header_and_data` is the compression header and the revision data |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1055 /// - `offset` is the position in the data file to write to |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1056 /// - `index_end` is the overwritten position in the index in revlog-v2, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1057 /// since the format may allow a rewrite of garbage data at the end. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1058 /// - `data_end` is the overwritten position in the data-file in revlog-v2, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1059 /// since the format may allow a rewrite of garbage data at the end. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1060 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1061 /// XXX Why do we have `data_end` *and* `offset`? Same question in Python |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1062 pub fn write_entry( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1063 &mut self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1064 mut transaction: impl Transaction, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1065 entry: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1066 header_and_data: (&[u8], &[u8]), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1067 mut offset: usize, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1068 index_end: Option<u64>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1069 data_end: Option<u64>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1070 ) -> Result<(u64, Option<u64>), HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1071 let current_revision = self.len() - 1; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1072 let canonical_index_file = self.canonical_index_file(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1073 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1074 let is_inline = self.is_inline(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1075 let handles = match &mut self.writing_handles { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1076 None => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1077 return Err(HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1078 "adding revision outside of the `with_write` context", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1079 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1080 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1081 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1082 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1083 Some(handles) => handles, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1084 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1085 let index_handle = &mut handles.index_handle; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1086 let data_handle = &mut handles.data_handle; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1087 if let Some(end) = index_end { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1088 index_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1089 .seek(SeekFrom::Start(end)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1090 .when_reading_file(&self.index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1091 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1092 index_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1093 .seek(SeekFrom::End(0)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1094 .when_reading_file(&self.index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1095 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1096 if let Some(data_handle) = data_handle { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1097 if let Some(end) = data_end { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1098 data_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1099 .seek(SeekFrom::Start(end)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1100 .when_reading_file(&self.data_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1101 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1102 data_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1103 .seek(SeekFrom::End(0)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1104 .when_reading_file(&self.data_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1105 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1106 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1107 let (header, data) = header_and_data; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1108 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1109 if !is_inline { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1110 transaction.add(&self.data_file, offset); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1111 transaction |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1112 .add(&canonical_index_file, current_revision * entry.len()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1113 let data_handle = data_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1114 .as_mut() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1115 .expect("data handle should exist when not inline"); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1116 if !header.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1117 data_handle.write_all(header)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1118 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1119 data_handle.write_all(data)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1120 match &mut self.delayed_buffer { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1121 Some(buf) => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1122 buf.lock() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1123 .expect("propagate the panic") |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1124 .buffer |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1125 .write_all(entry) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1126 .expect("write to delay buffer should succeed"); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1127 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1128 None => index_handle.write_all(entry)?, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1129 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1130 } else if self.delayed_buffer.is_some() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1131 return Err(HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1132 "invalid delayed write on inline revlog", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1133 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1134 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1135 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1136 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1137 offset += current_revision * entry.len(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1138 transaction.add(&canonical_index_file, offset); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1139 index_handle.write_all(entry)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1140 index_handle.write_all(header)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1141 index_handle.write_all(data)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1142 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1143 let data_position = match data_handle { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1144 Some(h) => Some(h.position()?), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1145 None => None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1146 }; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1147 Ok((index_handle.position()?, data_position)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1148 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1149 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1150 /// Return the real target index file and not the temporary when diverting |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1151 pub fn canonical_index_file(&self) -> PathBuf { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1152 self.original_index_file |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1153 .as_ref() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1154 .map(ToOwned::to_owned) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1155 .unwrap_or_else(|| self.index_file.to_owned()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1156 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1157 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1158 /// Return the path to the diverted index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1159 fn diverted_index(&self) -> PathBuf { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1160 self.index_file.with_extension("i.a") |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1161 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1162 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1163 /// True if we're in a [`Self::with_write`] or [`Self::with_read`] context |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1164 pub fn is_open(&self) -> bool { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1165 self.segment_file.is_open() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1166 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1167 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1168 /// Set this revlog to delay its writes to a buffer |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1169 pub fn delay(&mut self) -> Result<Option<PathBuf>, HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1170 assert!(!self.is_open()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1171 if self.is_inline() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1172 return Err(HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1173 "revlog with delayed write should not be inline", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1174 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1175 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1176 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1177 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1178 if self.delayed_buffer.is_some() || self.original_index_file.is_some() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1179 { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1180 // Delay or divert already happening |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1181 return Ok(None); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1182 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1183 if self.is_empty() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1184 self.original_index_file = Some(self.index_file.to_owned()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1185 self.index_file = self.diverted_index(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1186 if self.vfs.exists(&self.index_file) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1187 self.vfs.unlink(&self.index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1188 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1189 Ok(Some(self.index_file.to_owned())) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1190 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1191 self.delayed_buffer = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1192 Some(Arc::new(Mutex::new(DelayedBuffer::default()))); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1193 Ok(None) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1194 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1195 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1196 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1197 /// Write the pending data (in memory) if any to the diverted index file |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1198 /// (on disk temporary file) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1199 pub fn write_pending( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1200 &mut self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1201 ) -> Result<(Option<PathBuf>, bool), HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1202 assert!(!self.is_open()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1203 if self.is_inline() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1204 return Err(HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1205 "revlog with delayed write should not be inline", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1206 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1207 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1208 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1209 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1210 if self.original_index_file.is_some() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1211 return Ok((None, true)); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1212 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1213 let mut any_pending = false; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1214 let pending_index_file = self.diverted_index(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1215 if self.vfs.exists(&pending_index_file) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1216 self.vfs.unlink(&pending_index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1217 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1218 self.vfs.copy(&self.index_file, &pending_index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1219 if let Some(delayed_buffer) = self.delayed_buffer.take() { |
52330
645d247d4c75
rust-vfs: rename `open` to `open_write` and `open_read` to `open`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52327
diff
changeset
|
1220 let mut index_file_handle = |
645d247d4c75
rust-vfs: rename `open` to `open_write` and `open_read` to `open`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52327
diff
changeset
|
1221 self.vfs.open_write(&pending_index_file)?; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1222 index_file_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1223 .seek(SeekFrom::End(0)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1224 .when_writing_file(&pending_index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1225 let delayed_data = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1226 &delayed_buffer.lock().expect("propagate the panic").buffer; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1227 index_file_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1228 .write_all(delayed_data) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1229 .when_writing_file(&pending_index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1230 any_pending = true; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1231 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1232 self.original_index_file = Some(self.index_file.to_owned()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1233 self.index_file = pending_index_file; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1234 Ok((Some(self.index_file.to_owned()), any_pending)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1235 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1236 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1237 /// Overwrite the canonical file with the diverted file, or write out the |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1238 /// delayed buffer. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1239 /// Returns an error if the revlog is neither diverted nor delayed. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1240 pub fn finalize_pending(&mut self) -> Result<PathBuf, HgError> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1241 assert!(!self.is_open()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1242 if self.is_inline() { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1243 return Err(HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1244 "revlog with delayed write should not be inline", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1245 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1246 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1247 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1248 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1249 match ( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1250 self.delayed_buffer.as_ref(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1251 self.original_index_file.as_ref(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1252 ) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1253 (None, None) => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1254 return Err(HgError::abort( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1255 "neither delay nor divert found on this revlog", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1256 exit_codes::ABORT, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1257 None, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1258 )); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1259 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1260 (Some(delay), None) => { |
52330
645d247d4c75
rust-vfs: rename `open` to `open_write` and `open_read` to `open`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52327
diff
changeset
|
1261 let mut index_file_handle = |
645d247d4c75
rust-vfs: rename `open` to `open_write` and `open_read` to `open`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52327
diff
changeset
|
1262 self.vfs.open_write(&self.index_file)?; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1263 index_file_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1264 .seek(SeekFrom::End(0)) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1265 .when_writing_file(&self.index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1266 index_file_handle |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1267 .write_all( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1268 &delay.lock().expect("propagate the panic").buffer, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1269 ) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1270 .when_writing_file(&self.index_file)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1271 self.delayed_buffer = None; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1272 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1273 (None, Some(divert)) => { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1274 if self.vfs.exists(&self.index_file) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1275 self.vfs.rename(&self.index_file, divert, true)?; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1276 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1277 divert.clone_into(&mut self.index_file); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1278 self.original_index_file = None; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1279 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1280 (Some(_), Some(_)) => unreachable!( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1281 "{} is in an inconsistent state of both delay and divert", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1282 self.canonical_index_file().display(), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1283 ), |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1284 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1285 Ok(self.canonical_index_file()) |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1286 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1287 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1288 /// `pub` only for `hg-cpython`. This is made a different method than |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1289 /// [`Revlog::index`] in case there is a different invariant that pops up |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1290 /// later. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1291 #[doc(hidden)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1292 pub fn shared_index(&self) -> &Index { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1293 &self.index |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1294 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1295 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1296 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1297 type UncompressedChunkCache = |
52779
162f4801ad39
rust-inner-revlog: move to `RwLock` instead of `RefCell`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52341
diff
changeset
|
1298 RwLock<LruMap<Revision, Arc<[u8]>, ByMemoryUsage>>; |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1299 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1300 /// The node, revision and data for the last revision we've seen. Speeds up |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1301 /// a lot of sequential operations of the revlog. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1302 /// |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1303 /// The data is not just bytes since it can come from Python and we want to |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1304 /// avoid copies if possible. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1305 type SingleRevisionCache = |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1306 (Node, Revision, Box<dyn Deref<Target = [u8]> + Send>); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1307 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1308 /// A way of progressively filling a buffer with revision data, then return |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1309 /// that buffer. Used to abstract away Python-allocated code to reduce copying |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1310 /// for performance reasons. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1311 pub trait RevisionBuffer { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1312 /// The owned buffer type to return |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1313 type Target; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1314 /// Copies the slice into the buffer |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1315 fn extend_from_slice(&mut self, slice: &[u8]); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1316 /// Returns the now finished owned buffer |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1317 fn finish(self) -> Self::Target; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1318 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1319 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1320 /// A simple vec-based buffer. This is uselessly complicated for the pure Rust |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1321 /// case, but it's the price to pay for Python compatibility. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1322 #[derive(Debug)] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1323 pub(super) struct CoreRevisionBuffer { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1324 buf: Vec<u8>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1325 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1326 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1327 impl CoreRevisionBuffer { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1328 pub fn new() -> Self { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1329 Self { buf: vec![] } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1330 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1331 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1332 #[inline] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1333 pub fn resize(&mut self, size: usize) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1334 self.buf.reserve_exact(size - self.buf.capacity()); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1335 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1336 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1337 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1338 impl RevisionBuffer for CoreRevisionBuffer { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1339 type Target = Vec<u8>; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1340 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1341 #[inline] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1342 fn extend_from_slice(&mut self, slice: &[u8]) { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1343 self.buf.extend_from_slice(slice); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1344 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1345 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1346 #[inline] |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1347 fn finish(self) -> Self::Target { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1348 self.buf |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1349 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1350 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1351 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1352 /// Calculate the hash of a revision given its data and its parents. |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1353 pub fn hash( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1354 data: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1355 p1_hash: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1356 p2_hash: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1357 ) -> [u8; NODE_BYTES_LENGTH] { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1358 let mut hasher = Sha1::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1359 let (a, b) = (p1_hash, p2_hash); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1360 if a > b { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1361 hasher.update(b); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1362 hasher.update(a); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1363 } else { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1364 hasher.update(a); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1365 hasher.update(b); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1366 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1367 hasher.update(data); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1368 *hasher.finalize().as_ref() |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1369 } |