Mercurial > hg
annotate rust/hg-core/src/revlog/index.rs @ 52164:e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
This mirrors the Python `InnerRevlog` and will be used in a future patch
to replace said Python implementation. This allows us to start doing more
things in pure Rust, in particular reading and writing operations.
A lot of changes have to be introduced all at once, it wouldn't be very
useful to separate this patch IMO since all of them are either interlocked
or only useful with the rest.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 10 Oct 2024 10:34:51 +0200 |
parents | 44823c5011fe |
children | 6f94dc3cf8cf |
rev | line source |
---|---|
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1 use std::collections::{HashMap, HashSet}; |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
2 use std::fmt::Debug; |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
3 use std::ops::Deref; |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
4 use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
5 |
51260
c4f1a790bda8
rust-index: use a `BitVec` instead of plain `Vec` for heads computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51259
diff
changeset
|
6 use bitvec::prelude::*; |
45531
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
7 use byteorder::{BigEndian, ByteOrder}; |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
8 use bytes_cast::{unaligned, BytesCast}; |
45531
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
9 |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
10 use super::REVIDX_KNOWN_FLAGS; |
46443
43d63979a75e
rust: use HgError in RevlogError and Vfs
Simon Sapin <simon.sapin@octobus.net>
parents:
46090
diff
changeset
|
11 use crate::errors::HgError; |
51209
e9d47e2f5dcf
rust-index: add missing special case for null rev
Raphaël Gomès <rgomes@octobus.net>
parents:
51205
diff
changeset
|
12 use crate::node::{NODE_BYTES_LENGTH, NULL_NODE, STORED_NODE_ID_BYTES}; |
46033
88e741bf2d93
rust: use NodePrefix::from_hex instead of hex::decode directly
Simon Sapin <simon-commits@exyr.org>
parents:
45602
diff
changeset
|
13 use crate::revlog::node::Node; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
14 use crate::revlog::{Revision, NULL_REVISION}; |
51212
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
15 use crate::{ |
51215
a7bba7df9189
rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents:
51213
diff
changeset
|
16 dagops, BaseRevision, FastHashMap, Graph, GraphError, RevlogError, |
a7bba7df9189
rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents:
51213
diff
changeset
|
17 RevlogIndex, UncheckedRevision, |
51212
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
18 }; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
19 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
20 pub const INDEX_ENTRY_SIZE: usize = 64; |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
21 pub const INDEX_HEADER_SIZE: usize = 4; |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
22 pub const COMPRESSION_MODE_INLINE: u8 = 2; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
23 |
51218
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
24 #[derive(Debug)] |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
25 pub struct IndexHeader { |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
26 pub(super) header_bytes: [u8; INDEX_HEADER_SIZE], |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
27 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
28 |
51853
4777378fc3bf
rust-inner-revlog: derive Debug for IndexHeaderFlags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51852
diff
changeset
|
29 #[derive(Copy, Clone, Debug)] |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
30 pub struct IndexHeaderFlags { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
31 flags: u16, |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
32 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
33 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
34 /// Corresponds to the high bits of `_format_flags` in python |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
35 impl IndexHeaderFlags { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
36 /// Corresponds to FLAG_INLINE_DATA in python |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
37 pub fn is_inline(self) -> bool { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
38 self.flags & 1 != 0 |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
39 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
40 /// Corresponds to FLAG_GENERALDELTA in python |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
41 pub fn uses_generaldelta(self) -> bool { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
42 self.flags & 2 != 0 |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
43 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
44 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
45 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
46 /// Corresponds to the INDEX_HEADER structure, |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
47 /// which is parsed as a `header` variable in `_loadindex` in `revlog.py` |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
48 impl IndexHeader { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
49 fn format_flags(&self) -> IndexHeaderFlags { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
50 // No "unknown flags" check here, unlike in python. Maybe there should |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
51 // be. |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
52 IndexHeaderFlags { |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
53 flags: BigEndian::read_u16(&self.header_bytes[0..2]), |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
54 } |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
55 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
56 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
57 /// The only revlog version currently supported by rhg. |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
58 const REVLOGV1: u16 = 1; |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
59 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
60 /// Corresponds to `_format_version` in Python. |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
61 fn format_version(&self) -> u16 { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
62 BigEndian::read_u16(&self.header_bytes[2..4]) |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
63 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
64 |
52162
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
65 pub fn parse(index_bytes: &[u8]) -> Result<IndexHeader, HgError> { |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
66 if index_bytes.len() < 4 { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
67 return Err(HgError::corrupted( |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
68 "corrupted revlog: can't read the index format header", |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
69 )); |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
70 } |
52162
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
71 Ok(IndexHeader { |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
72 header_bytes: { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
73 let bytes: [u8; 4] = |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
74 index_bytes[0..4].try_into().expect("impossible"); |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
75 bytes |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
76 }, |
52163
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
77 }) |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
78 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
79 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
80 |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
81 /// Abstracts the access to the index bytes since they can be spread between |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
82 /// the immutable (bytes) part and the mutable (added) part if any appends |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
83 /// happened. This makes it transparent for the callers. |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
84 struct IndexData { |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
85 /// Immutable bytes, most likely taken from disk |
51233
ca81cd96000a
rust-index: add Sync bound to all relevant mmap-derived values
Raphaël Gomès <rgomes@octobus.net>
parents:
51229
diff
changeset
|
86 bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>, |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
87 /// Used when stripping index contents, keeps track of the start of the |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
88 /// first stripped revision, which is used to give a slice of the |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
89 /// `bytes` field. |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
90 truncation: Option<usize>, |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
91 /// Bytes that were added after reading the index |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
92 added: Vec<u8>, |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
93 first_entry: [u8; INDEX_ENTRY_SIZE], |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
94 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
95 |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
96 impl IndexData { |
51233
ca81cd96000a
rust-index: add Sync bound to all relevant mmap-derived values
Raphaël Gomès <rgomes@octobus.net>
parents:
51229
diff
changeset
|
97 pub fn new(bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>) -> Self { |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
98 let mut first_entry = [0; INDEX_ENTRY_SIZE]; |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
99 if bytes.len() >= INDEX_ENTRY_SIZE { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
100 first_entry[INDEX_HEADER_SIZE..] |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
101 .copy_from_slice(&bytes[INDEX_HEADER_SIZE..INDEX_ENTRY_SIZE]) |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
102 } |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
103 Self { |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
104 bytes, |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
105 truncation: None, |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
106 added: vec![], |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
107 first_entry, |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
108 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
109 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
110 |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
111 pub fn len(&self) -> usize { |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
112 match self.truncation { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
113 Some(truncation) => truncation + self.added.len(), |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
114 None => self.bytes.len() + self.added.len(), |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
115 } |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
116 } |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
117 |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
118 fn remove( |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
119 &mut self, |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
120 rev: Revision, |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
121 offsets: Option<&[usize]>, |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
122 ) -> Result<(), RevlogError> { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
123 let rev = rev.0 as usize; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
124 let truncation = if let Some(offsets) = offsets { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
125 offsets[rev] |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
126 } else { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
127 rev * INDEX_ENTRY_SIZE |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
128 }; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
129 if truncation < self.bytes.len() { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
130 self.truncation = Some(truncation); |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
131 self.added.clear(); |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
132 } else { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
133 self.added.truncate(truncation - self.bytes.len()); |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
134 } |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
135 Ok(()) |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
136 } |
51205
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
137 |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
138 fn is_new(&self) -> bool { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
139 self.bytes.is_empty() |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
140 } |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
141 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
142 |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
143 impl std::ops::Index<std::ops::Range<usize>> for IndexData { |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
144 type Output = [u8]; |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
145 |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
146 fn index(&self, index: std::ops::Range<usize>) -> &Self::Output { |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
147 let start = index.start; |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
148 let end = index.end; |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
149 let immutable_len = match self.truncation { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
150 Some(truncation) => truncation, |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
151 None => self.bytes.len(), |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
152 }; |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
153 if start < immutable_len { |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
154 if end > immutable_len { |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
155 panic!("index data cannot span existing and added ranges"); |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
156 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
157 &self.bytes[index] |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
158 } else { |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
159 &self.added[start - immutable_len..end - immutable_len] |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
160 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
161 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
162 } |
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
163 |
51205
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
164 #[derive(Debug, PartialEq, Eq)] |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
165 pub struct RevisionDataParams { |
51192
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
166 pub flags: u16, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
167 pub data_offset: u64, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
168 pub data_compressed_length: i32, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
169 pub data_uncompressed_length: i32, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
170 pub data_delta_base: i32, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
171 pub link_rev: i32, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
172 pub parent_rev_1: i32, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
173 pub parent_rev_2: i32, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
174 pub node_id: [u8; NODE_BYTES_LENGTH], |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
175 pub _sidedata_offset: u64, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
176 pub _sidedata_compressed_length: i32, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
177 pub data_compression_mode: u8, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
178 pub _sidedata_compression_mode: u8, |
65c9032e2e5a
rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51191
diff
changeset
|
179 pub _rank: i32, |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
180 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
181 |
51205
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
182 impl Default for RevisionDataParams { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
183 fn default() -> Self { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
184 Self { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
185 flags: 0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
186 data_offset: 0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
187 data_compressed_length: 0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
188 data_uncompressed_length: 0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
189 data_delta_base: -1, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
190 link_rev: -1, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
191 parent_rev_1: -1, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
192 parent_rev_2: -1, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
193 node_id: [0; NODE_BYTES_LENGTH], |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
194 _sidedata_offset: 0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
195 _sidedata_compressed_length: 0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
196 data_compression_mode: COMPRESSION_MODE_INLINE, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
197 _sidedata_compression_mode: COMPRESSION_MODE_INLINE, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
198 _rank: -1, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
199 } |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
200 } |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
201 } |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
202 |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
203 #[derive(BytesCast)] |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
204 #[repr(C)] |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
205 pub struct RevisionDataV1 { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
206 data_offset_or_flags: unaligned::U64Be, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
207 data_compressed_length: unaligned::I32Be, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
208 data_uncompressed_length: unaligned::I32Be, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
209 data_delta_base: unaligned::I32Be, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
210 link_rev: unaligned::I32Be, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
211 parent_rev_1: unaligned::I32Be, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
212 parent_rev_2: unaligned::I32Be, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
213 node_id: [u8; STORED_NODE_ID_BYTES], |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
214 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
215 |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
216 fn _static_assert_size_of_revision_data_v1() { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
217 let _ = std::mem::transmute::<RevisionDataV1, [u8; 64]>; |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
218 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
219 |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
220 impl RevisionDataParams { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
221 pub fn validate(&self) -> Result<(), RevlogError> { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
222 if self.flags & !REVIDX_KNOWN_FLAGS != 0 { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
223 return Err(RevlogError::corrupted(format!( |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
224 "unknown revlog index flags: {}", |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
225 self.flags |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
226 ))); |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
227 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
228 if self.data_compression_mode != COMPRESSION_MODE_INLINE { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
229 return Err(RevlogError::corrupted(format!( |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
230 "invalid data compression mode: {}", |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
231 self.data_compression_mode |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
232 ))); |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
233 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
234 // FIXME isn't this only for v2 or changelog v2? |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
235 if self._sidedata_compression_mode != COMPRESSION_MODE_INLINE { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
236 return Err(RevlogError::corrupted(format!( |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
237 "invalid sidedata compression mode: {}", |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
238 self._sidedata_compression_mode |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
239 ))); |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
240 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
241 Ok(()) |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
242 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
243 |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
244 pub fn into_v1(self) -> RevisionDataV1 { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
245 let data_offset_or_flags = self.data_offset << 16 | self.flags as u64; |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
246 let mut node_id = [0; STORED_NODE_ID_BYTES]; |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
247 node_id[..NODE_BYTES_LENGTH].copy_from_slice(&self.node_id); |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
248 RevisionDataV1 { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
249 data_offset_or_flags: data_offset_or_flags.into(), |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
250 data_compressed_length: self.data_compressed_length.into(), |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
251 data_uncompressed_length: self.data_uncompressed_length.into(), |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
252 data_delta_base: self.data_delta_base.into(), |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
253 link_rev: self.link_rev.into(), |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
254 parent_rev_1: self.parent_rev_1.into(), |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
255 parent_rev_2: self.parent_rev_2.into(), |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
256 node_id, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
257 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
258 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
259 } |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
260 |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
261 /// A Revlog index |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
262 pub struct Index { |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
263 bytes: IndexData, |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
264 /// Offsets of starts of index blocks. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
265 /// Only needed when the index is interleaved with data. |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
266 offsets: RwLock<Option<Vec<usize>>>, |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
267 uses_generaldelta: bool, |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
268 is_inline: bool, |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
269 /// Cache of (head_revisions, filtered_revisions) |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
270 /// |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
271 /// The head revisions in this index, kept in sync. Should |
51215
a7bba7df9189
rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents:
51213
diff
changeset
|
272 /// be accessed via the [`Self::head_revs`] method. |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
273 /// The last filtered revisions in this index, used to make sure |
51216
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents:
51215
diff
changeset
|
274 /// we haven't changed filters when returning the cached `head_revs`. |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
275 pub(super) head_revs: RwLock<(Vec<Revision>, HashSet<Revision>)>, |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
276 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
277 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
278 impl Debug for Index { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
279 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
280 f.debug_struct("Index") |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
281 .field("offsets", &self.offsets) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
282 .field("uses_generaldelta", &self.uses_generaldelta) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
283 .finish() |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
284 } |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
285 } |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
286 |
50978
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
287 impl Graph for Index { |
51257
e74dd6d73cb5
rust-index: allow inlining `parents` across crates
Raphaël Gomès <rgomes@octobus.net>
parents:
51236
diff
changeset
|
288 #[inline(always)] |
50978
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
289 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
290 let err = || GraphError::ParentOutOfRange(rev); |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
291 match self.get_entry(rev) { |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
292 Some(entry) => { |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
293 // The C implementation checks that the parents are valid |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
294 // before returning |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
295 Ok([ |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
296 self.check_revision(entry.p1()).ok_or_else(err)?, |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
297 self.check_revision(entry.p2()).ok_or_else(err)?, |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
298 ]) |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
299 } |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
300 None => Ok([NULL_REVISION, NULL_REVISION]), |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
301 } |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
302 } |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
303 } |
27e773aa607d
rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents:
50977
diff
changeset
|
304 |
51212
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
305 /// A cache suitable for find_snapshots |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
306 /// |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
307 /// Logically equivalent to a mapping whose keys are [`BaseRevision`] and |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
308 /// values sets of [`BaseRevision`] |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
309 /// |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
310 /// TODO the dubious part is insisting that errors must be RevlogError |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
311 /// we would probably need to sprinkle some magic here, such as an associated |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
312 /// type that would be Into<RevlogError> but even that would not be |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
313 /// satisfactory, as errors potentially have nothing to do with the revlog. |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
314 pub trait SnapshotsCache { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
315 fn insert_for( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
316 &mut self, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
317 rev: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
318 value: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
319 ) -> Result<(), RevlogError>; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
320 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
321 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
322 impl SnapshotsCache for FastHashMap<BaseRevision, HashSet<BaseRevision>> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
323 fn insert_for( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
324 &mut self, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
325 rev: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
326 value: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
327 ) -> Result<(), RevlogError> { |
51272
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
328 let all_values = self.entry(rev).or_default(); |
51212
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
329 all_values.insert(value); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
330 Ok(()) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
331 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
332 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
333 |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
334 impl Index { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
335 /// Create an index from bytes. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
336 /// Calculate the start of each entry when is_inline is true. |
45602
1cef583541c0
hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
337 pub fn new( |
51233
ca81cd96000a
rust-index: add Sync bound to all relevant mmap-derived values
Raphaël Gomès <rgomes@octobus.net>
parents:
51229
diff
changeset
|
338 bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>, |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51189
diff
changeset
|
339 default_header: IndexHeader, |
47963
001d747c2baf
rust: Return HgError instead of RevlogError in revlog constructors
Simon Sapin <simon.sapin@octobus.net>
parents:
46887
diff
changeset
|
340 ) -> Result<Self, HgError> { |
52162
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
341 let header = if bytes.len() < INDEX_ENTRY_SIZE { |
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
342 default_header |
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
343 } else { |
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
344 IndexHeader::parse(bytes.as_ref())? |
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
345 }; |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
346 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
347 if header.format_version() != IndexHeader::REVLOGV1 { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
348 // A proper new version should have had a repo/store |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
349 // requirement. |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
350 return Err(HgError::corrupted("unsupported revlog version")); |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
351 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
352 |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
353 let uses_generaldelta = header.format_flags().uses_generaldelta(); |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
354 |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
355 if header.format_flags().is_inline() { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
356 let mut offset: usize = 0; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
357 let mut offsets = Vec::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
358 |
45590
11f3c3f408fd
hg-core: minor code style change (D8958#inline-14993 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45536
diff
changeset
|
359 while offset + INDEX_ENTRY_SIZE <= bytes.len() { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
360 offsets.push(offset); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
361 let end = offset + INDEX_ENTRY_SIZE; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
362 let entry = IndexEntry { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
363 bytes: &bytes[offset..end], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
364 }; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
365 |
48543
0a4ac916673e
rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents:
48458
diff
changeset
|
366 offset += INDEX_ENTRY_SIZE + entry.compressed_len() as usize; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
367 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
368 |
45602
1cef583541c0
hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
369 if offset == bytes.len() { |
1cef583541c0
hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
370 Ok(Self { |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
371 bytes: IndexData::new(bytes), |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
372 offsets: RwLock::new(Some(offsets)), |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
373 uses_generaldelta, |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
374 is_inline: true, |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
375 head_revs: RwLock::new((vec![], HashSet::new())), |
45602
1cef583541c0
hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
376 }) |
1cef583541c0
hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
377 } else { |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
378 Err(HgError::corrupted("unexpected inline revlog length")) |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
379 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
380 } else { |
45602
1cef583541c0
hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
381 Ok(Self { |
51188
1ef4a36a934d
rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents:
50979
diff
changeset
|
382 bytes: IndexData::new(bytes), |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
383 offsets: RwLock::new(None), |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
384 uses_generaldelta, |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
385 is_inline: false, |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
386 head_revs: RwLock::new((vec![], HashSet::new())), |
45602
1cef583541c0
hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
387 }) |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
388 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
389 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
390 |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
391 pub fn uses_generaldelta(&self) -> bool { |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
392 self.uses_generaldelta |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
393 } |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
394 |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
395 /// Value of the inline flag. |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
396 pub fn is_inline(&self) -> bool { |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
397 self.is_inline |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
398 } |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
399 |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
400 /// Return a slice of bytes if `revlog` is inline. Panic if not. |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
401 pub fn data(&self, start: usize, end: usize) -> &[u8] { |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
402 if !self.is_inline() { |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
403 panic!("tried to access data in the index of a revlog that is not inline"); |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
404 } |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
405 &self.bytes[start..end] |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
406 } |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
407 |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
408 /// Return number of entries of the revlog index. |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
409 pub fn len(&self) -> usize { |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
410 if self.is_inline() { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
411 (*self.get_offsets()) |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
412 .as_ref() |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
413 .expect("inline should have offsets") |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
414 .len() |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
415 } else { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
416 self.bytes.len() / INDEX_ENTRY_SIZE |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
417 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
418 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
419 |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
420 pub fn get_offsets(&self) -> RwLockReadGuard<Option<Vec<usize>>> { |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
421 assert!(self.is_inline()); |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
422 { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
423 // Wrap in a block to drop the read guard |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
424 let mut offsets = self.offsets.write().unwrap(); |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
425 if offsets.is_none() { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
426 offsets.replace(inline_scan(&self.bytes.bytes).1); |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
427 } |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
428 } |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
429 self.offsets.read().unwrap() |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
430 } |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
431 |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
432 pub fn get_offsets_mut(&mut self) -> RwLockWriteGuard<Option<Vec<usize>>> { |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
433 assert!(self.is_inline()); |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
434 let mut offsets = self.offsets.write().unwrap(); |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
435 if offsets.is_none() { |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
436 offsets.replace(inline_scan(&self.bytes.bytes).1); |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
437 } |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
438 offsets |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
439 } |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
440 |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
441 /// Returns `true` if the `Index` has zero `entries`. |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
442 pub fn is_empty(&self) -> bool { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
443 self.len() == 0 |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
444 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45531
diff
changeset
|
445 |
51203
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
446 /// Return the index entry corresponding to the given revision or `None` |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
447 /// for [`NULL_REVISION`] |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
448 /// |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
449 /// The specified revision being of the checked type, it always exists |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
450 /// if it was validated by this index. |
51854
5baa52ca4932
rust-inner-revlog: always inline `get_entry`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51853
diff
changeset
|
451 #[inline(always)] |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
452 pub fn get_entry(&self, rev: Revision) -> Option<IndexEntry> { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
453 if rev == NULL_REVISION { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
454 return None; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
455 } |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
456 if rev.0 == 0 { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
457 Some(IndexEntry { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
458 bytes: &self.bytes.first_entry[..], |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
459 }) |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
460 } else { |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
461 Some(if self.is_inline() { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
462 self.get_entry_inline(rev) |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
463 } else { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
464 self.get_entry_separated(rev) |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
465 }) |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
466 } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
467 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
468 |
51203
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
469 /// Return the binary content of the index entry for the given revision |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
470 /// |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
471 /// See [get_entry()](`Self::get_entry()`) for cases when `None` is |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
472 /// returned. |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
473 pub fn entry_binary(&self, rev: Revision) -> Option<&[u8]> { |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
474 self.get_entry(rev).map(|e| { |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
475 let bytes = e.as_bytes(); |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
476 if rev.0 == 0 { |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
477 &bytes[4..] |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
478 } else { |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
479 bytes |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
480 } |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
481 }) |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
482 } |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
483 |
51205
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
484 pub fn entry_as_params( |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
485 &self, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
486 rev: UncheckedRevision, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
487 ) -> Option<RevisionDataParams> { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
488 let rev = self.check_revision(rev)?; |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
489 self.get_entry(rev).map(|e| RevisionDataParams { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
490 flags: e.flags(), |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
491 data_offset: if rev.0 == 0 && !self.bytes.is_new() { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
492 e.flags() as u64 |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
493 } else { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
494 e.raw_offset() |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
495 }, |
51236
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
496 data_compressed_length: e |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
497 .compressed_len() |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
498 .try_into() |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
499 .unwrap_or_else(|_| { |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
500 // Python's `unionrepo` sets the compressed length to be |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
501 // `-1` (or `u32::MAX` if transmuted to `u32`) because it |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
502 // cannot know the correct compressed length of a given |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
503 // revision. I'm not sure if this is true, but having this |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
504 // edge case won't hurt other use cases, let's handle it. |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
505 assert_eq!(e.compressed_len(), u32::MAX); |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
506 NULL_REVISION.0 |
eb676c35a29b
rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents:
51235
diff
changeset
|
507 }), |
51205
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
508 data_uncompressed_length: e.uncompressed_len(), |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
509 data_delta_base: e.base_revision_or_base_of_delta_chain().0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
510 link_rev: e.link_revision().0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
511 parent_rev_1: e.p1().0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
512 parent_rev_2: e.p2().0, |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
513 node_id: e.hash().as_bytes().try_into().unwrap(), |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
514 ..Default::default() |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
515 }) |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
516 } |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
517 |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
518 fn get_entry_inline(&self, rev: Revision) -> IndexEntry { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
519 let offsets = &self.get_offsets(); |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
520 let offsets = offsets.as_ref().expect("inline should have offsets"); |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
521 let start = offsets[rev.0 as usize]; |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
522 let end = start + INDEX_ENTRY_SIZE; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
523 let bytes = &self.bytes[start..end]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
524 |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
525 IndexEntry { bytes } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
526 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
527 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
528 fn get_entry_separated(&self, rev: Revision) -> IndexEntry { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
529 let start = rev.0 as usize * INDEX_ENTRY_SIZE; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
530 let end = start + INDEX_ENTRY_SIZE; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
531 let bytes = &self.bytes[start..end]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
532 |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
533 IndexEntry { bytes } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
534 } |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
535 |
51218
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
536 fn null_entry(&self) -> IndexEntry { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
537 IndexEntry { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
538 bytes: &[0; INDEX_ENTRY_SIZE], |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
539 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
540 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
541 |
51215
a7bba7df9189
rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents:
51213
diff
changeset
|
542 /// Return the head revisions of this index |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
543 pub fn head_revs(&self) -> Result<Vec<Revision>, GraphError> { |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
544 self.head_revs_advanced(&HashSet::new(), None, false) |
51261
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Raphaël Gomès <rgomes@octobus.net>
parents:
51260
diff
changeset
|
545 .map(|h| h.unwrap()) |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Raphaël Gomès <rgomes@octobus.net>
parents:
51260
diff
changeset
|
546 } |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Raphaël Gomès <rgomes@octobus.net>
parents:
51260
diff
changeset
|
547 |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
548 /// Return the head revisions of this index |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
549 pub fn head_revs_advanced( |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
550 &self, |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
551 filtered_revs: &HashSet<Revision>, |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
552 stop_rev: Option<Revision>, |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
553 py_shortcut: bool, |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
554 ) -> Result<Option<Vec<Revision>>, GraphError> { |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
555 { |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
556 let guard = self |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
557 .head_revs |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
558 .read() |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
559 .expect("RwLock on Index.head_revs should not be poisoned"); |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
560 let self_head_revs = &guard.0; |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
561 let self_filtered_revs = &guard.1; |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
562 if !self_head_revs.is_empty() |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
563 && filtered_revs == self_filtered_revs |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
564 && stop_rev.is_none() |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
565 { |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
566 if py_shortcut { |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
567 // Don't copy the revs since we've already cached them |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
568 // on the Python side. |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
569 return Ok(None); |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
570 } else { |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
571 return Ok(Some(self_head_revs.to_owned())); |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
572 } |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
573 } |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
574 } |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
575 |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
576 let (as_vec, cachable) = if self.is_empty() { |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
577 (vec![NULL_REVISION], true) |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
578 } else { |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
579 let length: usize = match stop_rev { |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
580 Some(r) => r.0 as usize, |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
581 None => self.len(), |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
582 }; |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
583 let cachable = self.len() == length; |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
584 let mut not_heads = bitvec![0; length]; |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
585 dagops::retain_heads_fast( |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
586 self, |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
587 not_heads.as_mut_bitslice(), |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
588 filtered_revs, |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
589 )?; |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
590 ( |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
591 not_heads |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
592 .into_iter() |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
593 .enumerate() |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
594 .filter_map(|(idx, is_not_head)| { |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
595 if is_not_head { |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
596 None |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
597 } else { |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
598 Some(Revision(idx as BaseRevision)) |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
599 } |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
600 }) |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
601 .collect(), |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
602 cachable, |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
603 ) |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
604 }; |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
605 if cachable { |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
606 *self |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
607 .head_revs |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
608 .write() |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
609 .expect("RwLock on Index.head_revs should not be poisoned") = |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
610 (as_vec.to_owned(), filtered_revs.to_owned()); |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
611 } |
51978
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
612 Ok(Some(as_vec)) |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
613 } |
5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51854
diff
changeset
|
614 |
51261
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Raphaël Gomès <rgomes@octobus.net>
parents:
51260
diff
changeset
|
615 /// Python-specific shortcut to save on PyList creation |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Raphaël Gomès <rgomes@octobus.net>
parents:
51260
diff
changeset
|
616 pub fn head_revs_shortcut( |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Raphaël Gomès <rgomes@octobus.net>
parents:
51260
diff
changeset
|
617 &self, |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Raphaël Gomès <rgomes@octobus.net>
parents:
51260
diff
changeset
|
618 ) -> Result<Option<Vec<Revision>>, GraphError> { |
51979
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51978
diff
changeset
|
619 self.head_revs_advanced(&HashSet::new(), None, true) |
51216
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents:
51215
diff
changeset
|
620 } |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents:
51215
diff
changeset
|
621 |
51397
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
622 /// Return the heads removed and added by advancing from `begin` to `end`. |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
623 /// In revset language, we compute: |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
624 /// - `heads(:begin)-heads(:end)` |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
625 /// - `heads(:end)-heads(:begin)` |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
626 pub fn head_revs_diff( |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
627 &self, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
628 begin: Revision, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
629 end: Revision, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
630 ) -> Result<(Vec<Revision>, Vec<Revision>), GraphError> { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
631 let mut heads_added = vec![]; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
632 let mut heads_removed = vec![]; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
633 |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
634 let mut acc = HashSet::new(); |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
635 let Revision(begin) = begin; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
636 let Revision(end) = end; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
637 let mut i = end; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
638 |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
639 while i > begin { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
640 // acc invariant: |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
641 // `j` is in the set iff `j <= i` and it has children |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
642 // among `i+1..end` (inclusive) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
643 if !acc.remove(&i) { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
644 heads_added.push(Revision(i)); |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
645 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
646 for Revision(parent) in self.parents(Revision(i))? { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
647 acc.insert(parent); |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
648 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
649 i -= 1; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
650 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
651 |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
652 // At this point `acc` contains old revisions that gained new children. |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
653 // We need to check if they had any children before. If not, those |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
654 // revisions are the removed heads. |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
655 while !acc.is_empty() { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
656 // acc invariant: |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
657 // `j` is in the set iff `j <= i` and it has children |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
658 // among `begin+1..end`, but not among `i+1..begin` (inclusive) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
659 |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
660 assert!(i >= -1); // yes, `-1` can also be a head if the repo is empty |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
661 if acc.remove(&i) { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
662 heads_removed.push(Revision(i)); |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
663 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
664 for Revision(parent) in self.parents(Revision(i))? { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
665 acc.remove(&parent); |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
666 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
667 i -= 1; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
668 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
669 |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
670 Ok((heads_removed, heads_added)) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
671 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51272
diff
changeset
|
672 |
51213
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
673 /// Obtain the delta chain for a revision. |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
674 /// |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
675 /// `stop_rev` specifies a revision to stop at. If not specified, we |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
676 /// stop at the base of the chain. |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
677 /// |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
678 /// Returns a 2-tuple of (chain, stopped) where `chain` is a vec of |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
679 /// revs in ascending order and `stopped` is a bool indicating whether |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
680 /// `stoprev` was hit. |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
681 pub fn delta_chain( |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
682 &self, |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
683 rev: Revision, |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
684 stop_rev: Option<Revision>, |
51235
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51234
diff
changeset
|
685 using_general_delta: Option<bool>, |
51213
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
686 ) -> Result<(Vec<Revision>, bool), HgError> { |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
687 let mut current_rev = rev; |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
688 let mut entry = self.get_entry(rev).unwrap(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
689 let mut chain = vec![]; |
51235
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51234
diff
changeset
|
690 let using_general_delta = |
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51234
diff
changeset
|
691 using_general_delta.unwrap_or_else(|| self.uses_generaldelta()); |
51213
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
692 while current_rev.0 != entry.base_revision_or_base_of_delta_chain().0 |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
693 && stop_rev.map(|r| r != current_rev).unwrap_or(true) |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
694 { |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
695 chain.push(current_rev); |
51235
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51234
diff
changeset
|
696 let new_rev = if using_general_delta { |
51213
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
697 entry.base_revision_or_base_of_delta_chain() |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
698 } else { |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
699 UncheckedRevision(current_rev.0 - 1) |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
700 }; |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
701 current_rev = self.check_revision(new_rev).ok_or_else(|| { |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
702 HgError::corrupted(format!("Revision {new_rev} out of range")) |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
703 })?; |
51218
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
704 if current_rev.0 == NULL_REVISION.0 { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
705 break; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
706 } |
51213
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
707 entry = self.get_entry(current_rev).unwrap() |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
708 } |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
709 |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
710 let stopped = if stop_rev.map(|r| current_rev == r).unwrap_or(false) { |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
711 true |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
712 } else { |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
713 chain.push(current_rev); |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
714 false |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
715 }; |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
716 chain.reverse(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
717 Ok((chain, stopped)) |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
718 } |
62e39bef36ca
rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents:
51212
diff
changeset
|
719 |
51212
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
720 pub fn find_snapshots( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
721 &self, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
722 start_rev: UncheckedRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
723 end_rev: UncheckedRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
724 cache: &mut impl SnapshotsCache, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
725 ) -> Result<(), RevlogError> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
726 let mut start_rev = start_rev.0; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
727 let mut end_rev = end_rev.0; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
728 end_rev += 1; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
729 let len = self.len().try_into().unwrap(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
730 if end_rev > len { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
731 end_rev = len; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
732 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
733 if start_rev < 0 { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
734 start_rev = 0; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
735 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
736 for rev in start_rev..end_rev { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
737 if !self.is_snapshot_unchecked(Revision(rev))? { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
738 continue; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
739 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
740 let mut base = self |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
741 .get_entry(Revision(rev)) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
742 .unwrap() |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
743 .base_revision_or_base_of_delta_chain(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
744 if base.0 == rev { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
745 base = NULL_REVISION.into(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
746 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
747 cache.insert_for(base.0, rev)?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
748 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
749 Ok(()) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
750 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents:
51211
diff
changeset
|
751 |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
752 fn clear_head_revs(&self) { |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
753 self.head_revs |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
754 .write() |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
755 .expect("RwLock on Index.head_revs should not be poisoined") |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
756 .0 |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
757 .clear() |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
758 } |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
759 |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
760 /// TODO move this to the trait probably, along with other things |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
761 pub fn append( |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
762 &mut self, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
763 revision_data: RevisionDataParams, |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
764 ) -> Result<(), RevlogError> { |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
765 revision_data.validate()?; |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
766 let entry_v1 = revision_data.into_v1(); |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
767 let entry_bytes = entry_v1.as_bytes(); |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
768 if self.bytes.len() == 0 { |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
769 self.bytes.first_entry[INDEX_HEADER_SIZE..].copy_from_slice( |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
770 &entry_bytes[INDEX_HEADER_SIZE..INDEX_ENTRY_SIZE], |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
771 ) |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
772 } |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
773 if self.is_inline() { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
774 let new_offset = self.bytes.len(); |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
775 if let Some(offsets) = &mut *self.get_offsets_mut() { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
776 offsets.push(new_offset) |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
777 } |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
778 } |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
779 self.bytes.added.extend(entry_bytes); |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
780 self.clear_head_revs(); |
51189
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
781 Ok(()) |
b4d152a28742
rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents:
51188
diff
changeset
|
782 } |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
783 |
51198
51cc12158f97
rust-index: add `pack_header` support
Raphaël Gomès <rgomes@octobus.net>
parents:
51197
diff
changeset
|
784 pub fn pack_header(&self, header: i32) -> [u8; 4] { |
51cc12158f97
rust-index: add `pack_header` support
Raphaël Gomès <rgomes@octobus.net>
parents:
51197
diff
changeset
|
785 header.to_be_bytes() |
51cc12158f97
rust-index: add `pack_header` support
Raphaël Gomès <rgomes@octobus.net>
parents:
51197
diff
changeset
|
786 } |
51cc12158f97
rust-index: add `pack_header` support
Raphaël Gomès <rgomes@octobus.net>
parents:
51197
diff
changeset
|
787 |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
788 pub fn remove(&mut self, rev: Revision) -> Result<(), RevlogError> { |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
789 let offsets = if self.is_inline() { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
790 self.get_offsets().clone() |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
791 } else { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
792 None |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
793 }; |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
794 self.bytes.remove(rev, offsets.as_deref())?; |
51264
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
795 if self.is_inline() { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
796 if let Some(offsets) = &mut *self.get_offsets_mut() { |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
797 offsets.truncate(rev.0 as usize) |
47a34afda7ad
rust-index: only access offsets if revlog is inline
Raphaël Gomès <rgomes@octobus.net>
parents:
51261
diff
changeset
|
798 } |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
799 } |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
800 self.clear_head_revs(); |
51195
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
801 Ok(()) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents:
51192
diff
changeset
|
802 } |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
803 |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
804 pub fn clear_caches(&self) { |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
805 // We need to get the 'inline' value from Python at init and use this |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
806 // instead of offsets to determine whether we're inline since we might |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
807 // clear caches. This implies re-populating the offsets on-demand. |
51234
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
808 *self |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
809 .offsets |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
810 .write() |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
811 .expect("RwLock on Index.offsets should not be poisoed") = None; |
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51233
diff
changeset
|
812 self.clear_head_revs(); |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
813 } |
51211
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
814 |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
815 /// Unchecked version of `is_snapshot`. |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
816 /// Assumes the caller checked that `rev` is within a valid revision range. |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
817 pub fn is_snapshot_unchecked( |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
818 &self, |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
819 mut rev: Revision, |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
820 ) -> Result<bool, RevlogError> { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
821 while rev.0 >= 0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
822 let entry = self.get_entry(rev).unwrap(); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
823 let mut base = entry.base_revision_or_base_of_delta_chain().0; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
824 if base == rev.0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
825 base = NULL_REVISION.0; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
826 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
827 if base == NULL_REVISION.0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
828 return Ok(true); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
829 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
830 let [mut p1, mut p2] = self |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
831 .parents(rev) |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
832 .map_err(|e| RevlogError::InvalidRevision(e.to_string()))?; |
51211
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
833 while let Some(p1_entry) = self.get_entry(p1) { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
834 if p1_entry.compressed_len() != 0 || p1.0 == 0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
835 break; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
836 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
837 let parent_base = |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
838 p1_entry.base_revision_or_base_of_delta_chain(); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
839 if parent_base.0 == p1.0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
840 break; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
841 } |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
842 p1 = self.check_revision(parent_base).ok_or( |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
843 RevlogError::InvalidRevision(parent_base.to_string()), |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
844 )?; |
51211
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
845 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
846 while let Some(p2_entry) = self.get_entry(p2) { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
847 if p2_entry.compressed_len() != 0 || p2.0 == 0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
848 break; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
849 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
850 let parent_base = |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
851 p2_entry.base_revision_or_base_of_delta_chain(); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
852 if parent_base.0 == p2.0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
853 break; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
854 } |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
855 p2 = self.check_revision(parent_base).ok_or( |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
856 RevlogError::InvalidRevision(parent_base.to_string()), |
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
857 )?; |
51211
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
858 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
859 if base == p1.0 || base == p2.0 { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
860 return Ok(false); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
861 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
862 rev = self |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
863 .check_revision(base.into()) |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
51979
diff
changeset
|
864 .ok_or(RevlogError::InvalidRevision(base.to_string()))?; |
51211
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
865 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
866 Ok(rev == NULL_REVISION) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
867 } |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
868 |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
869 /// Return whether the given revision is a snapshot. Returns an error if |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
870 /// `rev` is not within a valid revision range. |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
871 pub fn is_snapshot( |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
872 &self, |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
873 rev: UncheckedRevision, |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
874 ) -> Result<bool, RevlogError> { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
875 let rev = self |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
876 .check_revision(rev) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
877 .ok_or_else(|| RevlogError::corrupted("test"))?; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
878 self.is_snapshot_unchecked(rev) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents:
51209
diff
changeset
|
879 } |
51218
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
880 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
881 /// Slice revs to reduce the amount of unrelated data to be read from disk. |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
882 /// |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
883 /// The index is sliced into groups that should be read in one time. |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
884 /// |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
885 /// The initial chunk is sliced until the overall density |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
886 /// (payload/chunks-span ratio) is above `target_density`. |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
887 /// No gap smaller than `min_gap_size` is skipped. |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
888 pub fn slice_chunk_to_density( |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
889 &self, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
890 revs: &[Revision], |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
891 target_density: f64, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
892 min_gap_size: usize, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
893 ) -> Vec<Vec<Revision>> { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
894 if revs.is_empty() { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
895 return vec![]; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
896 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
897 if revs.len() == 1 { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
898 return vec![revs.to_owned()]; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
899 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
900 let delta_chain_span = self.segment_span(revs); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
901 if delta_chain_span < min_gap_size { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
902 return vec![revs.to_owned()]; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
903 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
904 let entries: Vec<_> = revs |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
905 .iter() |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
906 .map(|r| { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
907 (*r, self.get_entry(*r).unwrap_or_else(|| self.null_entry())) |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
908 }) |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
909 .collect(); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
910 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
911 let mut read_data = delta_chain_span; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
912 let chain_payload: u32 = |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
913 entries.iter().map(|(_r, e)| e.compressed_len()).sum(); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
914 let mut density = if delta_chain_span > 0 { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
915 chain_payload as f64 / delta_chain_span as f64 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
916 } else { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
917 1.0 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
918 }; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
919 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
920 if density >= target_density { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
921 return vec![revs.to_owned()]; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
922 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
923 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
924 // Store the gaps in a heap to have them sorted by decreasing size |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
925 let mut gaps = Vec::new(); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
926 let mut previous_end = None; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
927 |
52163
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
928 for (i, (rev, entry)) in entries.iter().enumerate() { |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
929 let start = self.start(*rev, entry); |
51218
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
930 let length = entry.compressed_len(); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
931 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
932 // Skip empty revisions to form larger holes |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
933 if length == 0 { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
934 continue; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
935 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
936 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
937 if let Some(end) = previous_end { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
938 let gap_size = start - end; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
939 // Only consider holes that are large enough |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
940 if gap_size > min_gap_size { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
941 gaps.push((gap_size, i)); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
942 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
943 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
944 previous_end = Some(start + length as usize); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
945 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
946 if gaps.is_empty() { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
947 return vec![revs.to_owned()]; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
948 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
949 // sort the gaps to pop them from largest to small |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
950 gaps.sort_unstable(); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
951 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
952 // Collect the indices of the largest holes until |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
953 // the density is acceptable |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
954 let mut selected = vec![]; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
955 while let Some((gap_size, gap_id)) = gaps.pop() { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
956 if density >= target_density { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
957 break; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
958 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
959 selected.push(gap_id); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
960 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
961 // The gap sizes are stored as negatives to be sorted decreasingly |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
962 // by the heap |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
963 read_data -= gap_size; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
964 density = if read_data > 0 { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
965 chain_payload as f64 / read_data as f64 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
966 } else { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
967 1.0 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
968 }; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
969 if density >= target_density { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
970 break; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
971 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
972 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
973 selected.sort_unstable(); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
974 selected.push(revs.len()); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
975 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
976 // Cut the revs at collected indices |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
977 let mut previous_idx = 0; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
978 let mut chunks = vec![]; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
979 for idx in selected { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
980 let chunk = self.trim_chunk(&entries, previous_idx, idx); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
981 if !chunk.is_empty() { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
982 chunks.push(chunk.iter().map(|(rev, _entry)| *rev).collect()); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
983 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
984 previous_idx = idx; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
985 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
986 let chunk = self.trim_chunk(&entries, previous_idx, entries.len()); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
987 if !chunk.is_empty() { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
988 chunks.push(chunk.iter().map(|(rev, _entry)| *rev).collect()); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
989 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
990 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
991 chunks |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
992 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
993 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
994 /// Get the byte span of a segment of sorted revisions. |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
995 /// |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
996 /// Occurrences of [`NULL_REVISION`] are ignored at the beginning of |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
997 /// the `revs` segment. |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
998 /// |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
999 /// panics: |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1000 /// - if `revs` is empty or only made of `NULL_REVISION` |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1001 /// - if cannot retrieve entry for the last or first not null element of |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1002 /// `revs`. |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1003 fn segment_span(&self, revs: &[Revision]) -> usize { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1004 if revs.is_empty() { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1005 return 0; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1006 } |
52163
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1007 let last_rev = revs[revs.len() - 1]; |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1008 let last_entry = &self.get_entry(last_rev).unwrap(); |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1009 let end = self.start(last_rev, last_entry) |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1010 + last_entry.compressed_len() as usize; |
51218
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1011 let first_rev = revs.iter().find(|r| r.0 != NULL_REVISION.0).unwrap(); |
52163
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1012 let first_entry = self.get_entry(*first_rev).unwrap(); |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1013 let start = self.start(*first_rev, &first_entry); |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1014 end - start |
51218
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1015 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1016 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1017 /// Returns `&revs[startidx..endidx]` without empty trailing revs |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1018 fn trim_chunk<'a>( |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1019 &'a self, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1020 revs: &'a [(Revision, IndexEntry)], |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1021 start: usize, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1022 mut end: usize, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1023 ) -> &'a [(Revision, IndexEntry)] { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1024 // Trim empty revs at the end, except the very first rev of a chain |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1025 let last_rev = revs[end - 1].0; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1026 if last_rev.0 < self.len() as BaseRevision { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1027 while end > 1 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1028 && end > start |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1029 && revs[end - 1].1.compressed_len() == 0 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1030 { |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1031 end -= 1 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1032 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1033 } |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1034 &revs[start..end] |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1035 } |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1036 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1037 /// Computes the set of revisions for each non-public phase from `roots`, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1038 /// which are the last known roots for each non-public phase. |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1039 pub fn compute_phases_map_sets( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1040 &self, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1041 roots: HashMap<Phase, Vec<Revision>>, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1042 ) -> Result<(usize, RootsPerPhase), GraphError> { |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1043 let mut phases = vec![Phase::Public; self.len()]; |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1044 let mut min_phase_rev = NULL_REVISION; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1045 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1046 for phase in Phase::non_public_phases() { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1047 if let Some(phase_roots) = roots.get(phase) { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1048 let min_rev = |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1049 self.add_roots_get_min(phase_roots, &mut phases, *phase); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1050 if min_rev != NULL_REVISION |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1051 && (min_phase_rev == NULL_REVISION |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1052 || min_rev < min_phase_rev) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1053 { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1054 min_phase_rev = min_rev; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1055 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1056 } else { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1057 continue; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1058 }; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1059 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1060 let mut phase_sets: RootsPerPhase = Default::default(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1061 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1062 if min_phase_rev == NULL_REVISION { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1063 min_phase_rev = Revision(self.len() as BaseRevision); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1064 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1065 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1066 for rev in min_phase_rev.0..self.len() as BaseRevision { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1067 let rev = Revision(rev); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1068 let [p1, p2] = self.parents(rev)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1069 |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1070 if p1.0 >= 0 && phases[p1.0 as usize] > phases[rev.0 as usize] { |
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1071 phases[rev.0 as usize] = phases[p1.0 as usize]; |
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1072 } |
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1073 if p2.0 >= 0 && phases[p2.0 as usize] > phases[rev.0 as usize] { |
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1074 phases[rev.0 as usize] = phases[p2.0 as usize]; |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1075 } |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1076 let set = match phases[rev.0 as usize] { |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1077 Phase::Public => continue, |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1078 phase => &mut phase_sets[phase as usize - 1], |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1079 }; |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1080 set.push(rev); |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1081 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1082 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1083 Ok((self.len(), phase_sets)) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1084 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1085 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1086 fn add_roots_get_min( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1087 &self, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1088 phase_roots: &[Revision], |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1089 phases: &mut [Phase], |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1090 phase: Phase, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1091 ) -> Revision { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1092 let mut min_rev = NULL_REVISION; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1093 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1094 for root in phase_roots { |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1095 phases[root.0 as usize] = phase; |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1096 if min_rev == NULL_REVISION || min_rev > *root { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1097 min_rev = *root; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1098 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1099 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1100 min_rev |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1101 } |
51222
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1102 |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1103 /// Return `(heads(::(<roots> and <roots>::<heads>)))` |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1104 /// If `include_path` is `true`, return `(<roots>::<heads>)`.""" |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1105 /// |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1106 /// `min_root` and `roots` are unchecked since they are just used as |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1107 /// a bound or for comparison and don't need to represent a valid revision. |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1108 /// In practice, the only invalid revision passed is the working directory |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1109 /// revision ([`i32::MAX`]). |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1110 pub fn reachable_roots( |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1111 &self, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1112 min_root: UncheckedRevision, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1113 mut heads: Vec<Revision>, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1114 roots: HashSet<UncheckedRevision>, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1115 include_path: bool, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1116 ) -> Result<HashSet<Revision>, GraphError> { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1117 if roots.is_empty() { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1118 return Ok(HashSet::new()); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1119 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1120 let mut reachable = HashSet::new(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1121 let mut seen = HashMap::new(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1122 |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1123 while let Some(rev) = heads.pop() { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1124 if roots.contains(&rev.into()) { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1125 reachable.insert(rev); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1126 if !include_path { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1127 continue; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1128 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1129 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1130 let parents = self.parents(rev)?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1131 seen.insert(rev, parents); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1132 for parent in parents { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1133 if parent.0 >= min_root.0 && !seen.contains_key(&parent) { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1134 heads.push(parent); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1135 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1136 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1137 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1138 if !include_path { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1139 return Ok(reachable); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1140 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1141 let mut revs: Vec<_> = seen.keys().collect(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1142 revs.sort_unstable(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1143 for rev in revs { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1144 for parent in seen[rev] { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1145 if reachable.contains(&parent) { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1146 reachable.insert(*rev); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1147 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1148 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1149 } |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1150 Ok(reachable) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents:
51220
diff
changeset
|
1151 } |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1152 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1153 /// Given a (possibly overlapping) set of revs, return all the |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1154 /// common ancestors heads: `heads(::args[0] and ::a[1] and ...)` |
51225
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1155 pub fn common_ancestor_heads( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1156 &self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1157 revisions: &[Revision], |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1158 ) -> Result<Vec<Revision>, GraphError> { |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1159 // given that revisions is expected to be small, we find this shortcut |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1160 // potentially acceptable, especially given that `hg-cpython` could |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1161 // very much bypass this, constructing a vector of unique values from |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1162 // the onset. |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1163 let as_set: HashSet<Revision> = revisions.iter().copied().collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1164 // Besides deduplicating, the C version also implements the shortcut |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1165 // for `NULL_REVISION`: |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1166 if as_set.contains(&NULL_REVISION) { |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1167 return Ok(vec![]); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1168 } |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1169 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1170 let revisions: Vec<Revision> = as_set.into_iter().collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1171 |
51229
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1172 if revisions.len() < 8 { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1173 self.find_gca_candidates::<u8>(&revisions) |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1174 } else if revisions.len() < 64 { |
51225
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1175 self.find_gca_candidates::<u64>(&revisions) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1176 } else { |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1177 self.find_gca_candidates::<NonStaticPoisonableBitSet>(&revisions) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1178 } |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1179 } |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1180 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1181 pub fn ancestors( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1182 &self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1183 revisions: &[Revision], |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1184 ) -> Result<Vec<Revision>, GraphError> { |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
1185 self.find_deepest_revs(&self.common_ancestor_heads(revisions)?) |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1186 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1187 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1188 /// Given a disjoint set of revs, return all candidates for the |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1189 /// greatest common ancestor. In revset notation, this is the set |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1190 /// `heads(::a and ::b and ...)` |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1191 fn find_gca_candidates<BS: PoisonableBitSet + Clone>( |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1192 &self, |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1193 revs: &[Revision], |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1194 ) -> Result<Vec<Revision>, GraphError> { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1195 if revs.is_empty() { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1196 return Ok(vec![]); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1197 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1198 let revcount = revs.len(); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1199 let mut candidates = vec![]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1200 let max_rev = revs.iter().max().unwrap(); |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1201 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1202 let mut seen = BS::vec_of_empty(revs.len(), (max_rev.0 + 1) as usize); |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1203 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1204 for (idx, rev) in revs.iter().enumerate() { |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1205 seen[rev.0 as usize].add(idx); |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1206 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1207 let mut current_rev = *max_rev; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1208 // Number of revisions whose inspection in the main loop |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1209 // will give a result or trigger inspection of other revisions |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1210 let mut interesting = revcount; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1211 |
51226
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1212 // The algorithm works on a vector of bit sets, indexed by revision |
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1213 // numbers and iterated on reverse order. |
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1214 // An entry in this vector is poisoned if and only if the corresponding |
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1215 // revision is a common, yet not maximal ancestor. |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1216 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1217 // The principle of the algorithm is as follows: |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1218 // For a revision `r`, when entering the loop, `seen[r]` is either |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1219 // poisoned or the sub set of `revs` of which `r` is an ancestor. |
51226
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1220 // In this sub set is full, then `r` is a solution and its parents |
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1221 // have to be poisoned. |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1222 // |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1223 // At each iteration, the bit sets of the parents are updated by |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1224 // union with `seen[r]`. |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1225 // As we walk the index from the end, we are sure we have encountered |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1226 // all children of `r` before `r`, hence we know that `seen[r]` is |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1227 // fully computed. |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1228 // |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1229 // On top of that there are several optimizations that make reading |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1230 // less obvious than the comment above: |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1231 // - The `interesting` counter allows to break early |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1232 // - The loop starts from `max(revs)` |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1233 // - Early return in case it is detected that one of the incoming revs |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1234 // is a common ancestor of all of them. |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1235 while current_rev.0 >= 0 && interesting > 0 { |
51226
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1236 let current_seen = seen[current_rev.0 as usize].clone(); |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1237 |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1238 if current_seen.is_empty() { |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1239 current_rev = Revision(current_rev.0 - 1); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1240 continue; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1241 } |
51226
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1242 let mut poison = current_seen.is_poisoned(); |
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1243 if !poison { |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1244 interesting -= 1; |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1245 if current_seen.is_full_range(revcount) { |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1246 candidates.push(current_rev); |
51226
83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51225
diff
changeset
|
1247 poison = true; |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1248 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1249 // Being a common ancestor, if `current_rev` is among |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1250 // the input revisions, it is *the* answer. |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1251 for rev in revs { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1252 if *rev == current_rev { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1253 return Ok(candidates); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1254 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1255 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1256 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1257 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1258 for parent in self.parents(current_rev)? { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1259 if parent == NULL_REVISION { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1260 continue; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1261 } |
51228
61a6ef876efd
rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51227
diff
changeset
|
1262 let parent_seen = &mut seen[parent.0 as usize]; |
51227
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1263 if poison { |
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1264 // this block is logically equivalent to poisoning parent |
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1265 // and counting it as non interesting if it |
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1266 // has been seen before (hence counted then as interesting) |
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1267 if !parent_seen.is_empty() && !parent_seen.is_poisoned() { |
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1268 interesting -= 1; |
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1269 } |
51228
61a6ef876efd
rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51227
diff
changeset
|
1270 parent_seen.poison(); |
51227
e553cd209215
rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
1271 } else { |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1272 if parent_seen.is_empty() { |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1273 interesting += 1; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1274 } |
51228
61a6ef876efd
rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51227
diff
changeset
|
1275 parent_seen.union(¤t_seen); |
51223
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1276 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1277 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1278 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1279 current_rev = Revision(current_rev.0 - 1); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1280 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1281 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1282 Ok(candidates) |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1283 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1284 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1285 /// Given a disjoint set of revs, return the subset with the longest path |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1286 /// to the root. |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1287 fn find_deepest_revs( |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1288 &self, |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1289 revs: &[Revision], |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1290 ) -> Result<Vec<Revision>, GraphError> { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1291 // TODO replace this all with just comparing rank? |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1292 // Also, the original implementations in C/Python are cryptic, not |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1293 // even sure we actually need this? |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1294 if revs.len() <= 1 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1295 return Ok(revs.to_owned()); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1296 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1297 let max_rev = revs.iter().max().unwrap().0; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1298 let mut interesting = HashMap::new(); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1299 let mut seen = vec![0; max_rev as usize + 1]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1300 let mut depth = vec![0; max_rev as usize + 1]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1301 let mut mapping = vec![]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1302 let mut revs = revs.to_owned(); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1303 revs.sort_unstable(); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1304 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1305 for (idx, rev) in revs.iter().enumerate() { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1306 depth[rev.0 as usize] = 1; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1307 let shift = 1 << idx; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1308 seen[rev.0 as usize] = shift; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1309 interesting.insert(shift, 1); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1310 mapping.push((shift, *rev)); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1311 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1312 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1313 let mut current_rev = Revision(max_rev); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1314 while current_rev.0 >= 0 && interesting.len() > 1 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1315 let current_depth = depth[current_rev.0 as usize]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1316 if current_depth == 0 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1317 current_rev = Revision(current_rev.0 - 1); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1318 continue; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1319 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1320 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1321 let current_seen = seen[current_rev.0 as usize]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1322 for parent in self.parents(current_rev)? { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1323 if parent == NULL_REVISION { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1324 continue; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1325 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1326 let parent_seen = seen[parent.0 as usize]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1327 let parent_depth = depth[parent.0 as usize]; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1328 if parent_depth <= current_depth { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1329 depth[parent.0 as usize] = current_depth + 1; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1330 if parent_seen != current_seen { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1331 *interesting.get_mut(¤t_seen).unwrap() += 1; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1332 seen[parent.0 as usize] = current_seen; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1333 if parent_seen != 0 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1334 let parent_interesting = |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1335 interesting.get_mut(&parent_seen).unwrap(); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1336 *parent_interesting -= 1; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1337 if *parent_interesting == 0 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1338 interesting.remove(&parent_seen); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1339 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1340 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1341 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1342 } else if current_depth == parent_depth - 1 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1343 let either_seen = parent_seen | current_seen; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1344 if either_seen == parent_seen { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1345 continue; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1346 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1347 seen[parent.0 as usize] = either_seen; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1348 interesting |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1349 .entry(either_seen) |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1350 .and_modify(|v| *v += 1) |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1351 .or_insert(1); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1352 *interesting.get_mut(&parent_seen).unwrap() -= 1; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1353 if interesting[&parent_seen] == 0 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1354 interesting.remove(&parent_seen); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1355 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1356 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1357 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1358 *interesting.get_mut(¤t_seen).unwrap() -= 1; |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1359 if interesting[¤t_seen] == 0 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1360 interesting.remove(¤t_seen); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1361 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1362 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1363 current_rev = Revision(current_rev.0 - 1); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1364 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1365 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1366 if interesting.len() != 1 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1367 return Ok(vec![]); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1368 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1369 let mask = interesting.keys().next().unwrap(); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1370 |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1371 Ok(mapping |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1372 .into_iter() |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1373 .filter_map(|(shift, rev)| { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1374 if (mask & shift) != 0 { |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1375 return Some(rev); |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1376 } |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1377 None |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1378 }) |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1379 .collect()) |
42c8dbdb88ad
rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents:
51222
diff
changeset
|
1380 } |
52163
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1381 |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1382 /// Return the offset into the data corresponding to `rev` (in the index |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1383 /// file if inline, in the data file otherwise). `entry` must be the entry |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1384 /// for `rev`: the API is done this way to reduce the number of lookups |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1385 /// since we sometimes already have the entry, and because very few places |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1386 /// actually use this function. |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1387 #[inline(always)] |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1388 pub fn start(&self, rev: Revision, entry: &IndexEntry<'_>) -> usize { |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1389 #[cfg(debug_assertions)] |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1390 { |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1391 assert_eq!(&self.get_entry(rev).unwrap(), entry); |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1392 } |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1393 let offset = entry.offset(); |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1394 if self.is_inline() { |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1395 offset + ((rev.0 as usize + 1) * INDEX_ENTRY_SIZE) |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1396 } else { |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1397 offset |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1398 } |
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1399 } |
52164
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1400 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1401 pub(crate) fn make_null_entry(&self) -> IndexEntry<'_> { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1402 IndexEntry { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1403 bytes: b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \ |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1404 \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \ |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1405 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1406 } |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Raphaël Gomès <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1407 } |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1408 } |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1409 |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1410 /// The kind of functionality needed by find_gca_candidates |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1411 /// |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1412 /// This is a bit mask which can be declared to be "poisoned", which callers |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1413 /// interpret to break out of some loops. |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1414 /// |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1415 /// The maximum capacity of the bit mask is up to the actual implementation |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1416 trait PoisonableBitSet: Sized + PartialEq { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1417 /// Return a vector of exactly n elements, initialized to be empty. |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1418 /// |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1419 /// Optimization can vastly depend on implementation. Those being `Copy` |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1420 /// and having constant capacity typically can have a very simple |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1421 /// implementation. |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1422 fn vec_of_empty(sets_size: usize, vec_len: usize) -> Vec<Self>; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1423 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1424 /// The size of the bit mask in memory |
51707
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
1425 #[allow(unused)] |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1426 fn size(&self) -> usize; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1427 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1428 /// The number of elements that can be represented in the set. |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1429 /// |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1430 /// Another way to put it is that it is the highest integer `C` such that |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1431 /// the set is guaranteed to always be a subset of the integer range |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1432 /// `[0, C)` |
51707
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
1433 #[allow(unused)] |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1434 fn capacity(&self) -> usize; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1435 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1436 /// Declare `n` to belong to the set |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1437 fn add(&mut self, n: usize); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1438 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1439 /// Declare `n` not to belong to the set |
51707
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
1440 #[allow(unused)] |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1441 fn discard(&mut self, n: usize); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1442 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1443 /// Replace this bit set by its union with other |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1444 fn union(&mut self, other: &Self); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1445 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1446 /// Poison the bit set |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1447 /// |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1448 /// Interpretation up to the caller |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1449 fn poison(&mut self); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1450 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1451 /// Is the bit set poisoned? |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1452 /// |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1453 /// Interpretation is up to the caller |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1454 fn is_poisoned(&self) -> bool; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1455 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1456 /// Is the bit set empty? |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1457 fn is_empty(&self) -> bool; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1458 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1459 /// return `true` if and only if the bit is the full range `[0, n)` |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1460 /// of integers |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1461 fn is_full_range(&self, n: usize) -> bool; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1462 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1463 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1464 const U64_POISON: u64 = 1 << 63; |
51229
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1465 const U8_POISON: u8 = 1 << 7; |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1466 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1467 impl PoisonableBitSet for u64 { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1468 fn vec_of_empty(_sets_size: usize, vec_len: usize) -> Vec<Self> { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1469 vec![0u64; vec_len] |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1470 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1471 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1472 fn size(&self) -> usize { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1473 8 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1474 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1475 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1476 fn capacity(&self) -> usize { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1477 63 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1478 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1479 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1480 fn add(&mut self, n: usize) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1481 (*self) |= 1u64 << n; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1482 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1483 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1484 fn discard(&mut self, n: usize) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1485 (*self) &= u64::MAX - (1u64 << n); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1486 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1487 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1488 fn union(&mut self, other: &Self) { |
51228
61a6ef876efd
rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51227
diff
changeset
|
1489 if *self != *other { |
61a6ef876efd
rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51227
diff
changeset
|
1490 (*self) |= *other; |
61a6ef876efd
rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents:
51227
diff
changeset
|
1491 } |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1492 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1493 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1494 fn is_full_range(&self, n: usize) -> bool { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1495 *self + 1 == (1u64 << n) |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1496 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1497 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1498 fn is_empty(&self) -> bool { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1499 *self == 0 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1500 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1501 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1502 fn poison(&mut self) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1503 *self = U64_POISON; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1504 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1505 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1506 fn is_poisoned(&self) -> bool { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1507 // equality comparison would be tempting but would not resist |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1508 // operations after poisoning (even if these should be bogus). |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1509 *self >= U64_POISON |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1510 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1511 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1512 |
51229
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1513 impl PoisonableBitSet for u8 { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1514 fn vec_of_empty(_sets_size: usize, vec_len: usize) -> Vec<Self> { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1515 vec![0; vec_len] |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1516 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1517 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1518 fn size(&self) -> usize { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1519 1 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1520 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1521 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1522 fn capacity(&self) -> usize { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1523 7 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1524 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1525 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1526 fn add(&mut self, n: usize) { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1527 (*self) |= 1 << n; |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1528 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1529 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1530 fn discard(&mut self, n: usize) { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1531 (*self) &= u8::MAX - (1 << n); |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1532 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1533 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1534 fn union(&mut self, other: &Self) { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1535 if *self != *other { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1536 (*self) |= *other; |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1537 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1538 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1539 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1540 fn is_full_range(&self, n: usize) -> bool { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1541 *self + 1 == (1 << n) |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1542 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1543 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1544 fn is_empty(&self) -> bool { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1545 *self == 0 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1546 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1547 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1548 fn poison(&mut self) { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1549 *self = U8_POISON; |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1550 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1551 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1552 fn is_poisoned(&self) -> bool { |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1553 // equality comparison would be tempting but would not resist |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1554 // operations after poisoning (even if these should be bogus). |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1555 *self >= U8_POISON |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1556 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1557 } |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51228
diff
changeset
|
1558 |
51224
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1559 /// A poisonable bit set whose capacity is not known at compile time but |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1560 /// is constant after initial construction |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1561 /// |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1562 /// This can be way further optimized if performance assessments (speed |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1563 /// and/or RAM) require it. |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1564 /// As far as RAM is concerned, for large vectors of these, the main problem |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1565 /// would be the repetition of set_size in each item. We would need a trait |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1566 /// to abstract over the idea of a vector of such bit sets to do better. |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1567 #[derive(Clone, PartialEq)] |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1568 struct NonStaticPoisonableBitSet { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1569 set_size: usize, |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1570 bit_set: Vec<u64>, |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1571 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1572 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1573 /// Number of `u64` needed for a [`NonStaticPoisonableBitSet`] of given size |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1574 fn non_static_poisonable_inner_len(set_size: usize) -> usize { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1575 1 + (set_size + 1) / 64 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1576 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1577 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1578 impl NonStaticPoisonableBitSet { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1579 /// The index of the sub-bit set for the given n, and the index inside |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1580 /// the latter |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1581 fn index(&self, n: usize) -> (usize, usize) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1582 (n / 64, n % 64) |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1583 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1584 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1585 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1586 /// Mock implementation to ensure that the trait makes sense |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1587 impl PoisonableBitSet for NonStaticPoisonableBitSet { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1588 fn vec_of_empty(set_size: usize, vec_len: usize) -> Vec<Self> { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1589 let tmpl = Self { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1590 set_size, |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1591 bit_set: vec![0u64; non_static_poisonable_inner_len(set_size)], |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1592 }; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1593 vec![tmpl; vec_len] |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1594 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1595 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1596 fn size(&self) -> usize { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1597 8 + self.bit_set.len() * 8 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1598 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1599 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1600 fn capacity(&self) -> usize { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1601 self.set_size |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1602 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1603 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1604 fn add(&mut self, n: usize) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1605 let (sub_bs, bit_pos) = self.index(n); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1606 self.bit_set[sub_bs] |= 1 << bit_pos |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1607 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1608 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1609 fn discard(&mut self, n: usize) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1610 let (sub_bs, bit_pos) = self.index(n); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1611 self.bit_set[sub_bs] |= u64::MAX - (1 << bit_pos) |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1612 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1613 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1614 fn union(&mut self, other: &Self) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1615 assert!( |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1616 self.set_size == other.set_size, |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1617 "Binary operations on bit sets can only be done on same size" |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1618 ); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1619 for i in 0..self.bit_set.len() - 1 { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1620 self.bit_set[i] |= other.bit_set[i] |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1621 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1622 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1623 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1624 fn is_full_range(&self, n: usize) -> bool { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1625 let (sub_bs, bit_pos) = self.index(n); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1626 self.bit_set[..sub_bs].iter().all(|bs| *bs == u64::MAX) |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1627 && self.bit_set[sub_bs] == (1 << (bit_pos + 1)) - 1 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1628 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1629 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1630 fn is_empty(&self) -> bool { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1631 self.bit_set.iter().all(|bs| *bs == 0u64) |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1632 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1633 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1634 fn poison(&mut self) { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1635 let (sub_bs, bit_pos) = self.index(self.set_size); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1636 self.bit_set[sub_bs] = 1 << bit_pos; |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1637 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1638 |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1639 fn is_poisoned(&self) -> bool { |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1640 let (sub_bs, bit_pos) = self.index(self.set_size); |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1641 self.bit_set[sub_bs] >= 1 << bit_pos |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1642 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1643 } |
43241f31cf5b
rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51223
diff
changeset
|
1644 |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1645 /// Set of roots of all non-public phases |
51425
7c6d0b9dde37
rust-index: improve phase computation speed
Raphaël Gomès <rgomes@octobus.net>
parents:
51397
diff
changeset
|
1646 pub type RootsPerPhase = [Vec<Revision>; Phase::non_public_phases().len()]; |
51220
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1647 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1648 #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)] |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1649 pub enum Phase { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1650 Public = 0, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1651 Draft = 1, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1652 Secret = 2, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1653 Archived = 3, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1654 Internal = 4, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1655 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1656 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1657 impl TryFrom<usize> for Phase { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1658 type Error = RevlogError; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1659 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1660 fn try_from(value: usize) -> Result<Self, Self::Error> { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1661 Ok(match value { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1662 0 => Self::Public, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1663 1 => Self::Draft, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1664 2 => Self::Secret, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1665 32 => Self::Archived, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1666 96 => Self::Internal, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1667 v => { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1668 return Err(RevlogError::corrupted(format!( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1669 "invalid phase value {}", |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1670 v |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1671 ))) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1672 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1673 }) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1674 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1675 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1676 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1677 impl Phase { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1678 pub const fn all_phases() -> &'static [Self] { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1679 &[ |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1680 Self::Public, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1681 Self::Draft, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1682 Self::Secret, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1683 Self::Archived, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1684 Self::Internal, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1685 ] |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1686 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1687 pub const fn non_public_phases() -> &'static [Self] { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1688 &[Self::Draft, Self::Secret, Self::Archived, Self::Internal] |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1689 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1690 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents:
51218
diff
changeset
|
1691 |
51197
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1692 fn inline_scan(bytes: &[u8]) -> (usize, Vec<usize>) { |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1693 let mut offset: usize = 0; |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1694 let mut offsets = Vec::new(); |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1695 |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1696 while offset + INDEX_ENTRY_SIZE <= bytes.len() { |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1697 offsets.push(offset); |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1698 let end = offset + INDEX_ENTRY_SIZE; |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1699 let entry = IndexEntry { |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1700 bytes: &bytes[offset..end], |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1701 }; |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1702 |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1703 offset += INDEX_ENTRY_SIZE + entry.compressed_len() as usize; |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1704 } |
4e6620b7fbbb
rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents:
51195
diff
changeset
|
1705 (offset, offsets) |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1706 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1707 |
46090
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1708 impl super::RevlogIndex for Index { |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1709 fn len(&self) -> usize { |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1710 self.len() |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1711 } |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1712 |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1713 fn node(&self, rev: Revision) -> Option<&Node> { |
51209
e9d47e2f5dcf
rust-index: add missing special case for null rev
Raphaël Gomès <rgomes@octobus.net>
parents:
51205
diff
changeset
|
1714 if rev == NULL_REVISION { |
e9d47e2f5dcf
rust-index: add missing special case for null rev
Raphaël Gomès <rgomes@octobus.net>
parents:
51205
diff
changeset
|
1715 return Some(&NULL_NODE); |
e9d47e2f5dcf
rust-index: add missing special case for null rev
Raphaël Gomès <rgomes@octobus.net>
parents:
51205
diff
changeset
|
1716 } |
46090
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1717 self.get_entry(rev).map(|entry| entry.hash()) |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1718 } |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1719 } |
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1720 |
52163
44823c5011fe
rust-index: fix the computation of data start
Raphaël Gomès <rgomes@octobus.net>
parents:
52162
diff
changeset
|
1721 #[derive(Debug, PartialEq, Eq)] |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1722 pub struct IndexEntry<'a> { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1723 bytes: &'a [u8], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1724 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1725 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1726 impl<'a> IndexEntry<'a> { |
45593
da30e4b553c3
hg-core: minor docstring update (D8958#inline-14991 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45592
diff
changeset
|
1727 /// Return the offset of the data. |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1728 pub fn offset(&self) -> usize { |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
1729 let mut bytes = [0; 8]; |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
1730 bytes[2..8].copy_from_slice(&self.bytes[0..=5]); |
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
1731 BigEndian::read_u64(&bytes[..]) as usize |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1732 } |
51205
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
1733 pub fn raw_offset(&self) -> u64 { |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
1734 BigEndian::read_u64(&self.bytes[0..8]) |
002b49905aac
rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents:
51203
diff
changeset
|
1735 } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1736 |
48546
e91aa800ae5b
rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents:
48543
diff
changeset
|
1737 pub fn flags(&self) -> u16 { |
e91aa800ae5b
rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents:
48543
diff
changeset
|
1738 BigEndian::read_u16(&self.bytes[6..=7]) |
e91aa800ae5b
rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents:
48543
diff
changeset
|
1739 } |
e91aa800ae5b
rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents:
48543
diff
changeset
|
1740 |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1741 /// Return the compressed length of the data. |
48543
0a4ac916673e
rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents:
48458
diff
changeset
|
1742 pub fn compressed_len(&self) -> u32 { |
0a4ac916673e
rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents:
48458
diff
changeset
|
1743 BigEndian::read_u32(&self.bytes[8..=11]) |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1744 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1745 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1746 /// Return the uncompressed length of the data. |
48543
0a4ac916673e
rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents:
48458
diff
changeset
|
1747 pub fn uncompressed_len(&self) -> i32 { |
0a4ac916673e
rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents:
48458
diff
changeset
|
1748 BigEndian::read_i32(&self.bytes[12..=15]) |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1749 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1750 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1751 /// Return the revision upon which the data has been derived. |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1752 pub fn base_revision_or_base_of_delta_chain(&self) -> UncheckedRevision { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1753 // TODO Maybe return an Option when base_revision == rev? |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1754 // Requires to add rev to IndexEntry |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1755 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1756 BigEndian::read_i32(&self.bytes[16..]).into() |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1757 } |
45531
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1758 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1759 pub fn link_revision(&self) -> UncheckedRevision { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1760 BigEndian::read_i32(&self.bytes[20..]).into() |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1761 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1762 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1763 pub fn p1(&self) -> UncheckedRevision { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1764 BigEndian::read_i32(&self.bytes[24..]).into() |
45531
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1765 } |
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1766 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1767 pub fn p2(&self) -> UncheckedRevision { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
1768 BigEndian::read_i32(&self.bytes[28..]).into() |
45531
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1769 } |
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1770 |
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1771 /// Return the hash of revision's full text. |
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1772 /// |
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1773 /// Currently, SHA-1 is used and only the first 20 bytes of this field |
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1774 /// are used. |
46090
9eb07ab3f2d4
rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents:
46033
diff
changeset
|
1775 pub fn hash(&self) -> &'a Node { |
46033
88e741bf2d93
rust: use NodePrefix::from_hex instead of hex::decode directly
Simon Sapin <simon-commits@exyr.org>
parents:
45602
diff
changeset
|
1776 (&self.bytes[32..52]).try_into().unwrap() |
45531
b0d6309ff50c
hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45526
diff
changeset
|
1777 } |
51203
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
1778 |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
1779 pub fn as_bytes(&self) -> &'a [u8] { |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
1780 self.bytes |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Raphaël Gomès <rgomes@octobus.net>
parents:
51198
diff
changeset
|
1781 } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1782 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1783 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1784 #[cfg(test)] |
51707
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
1785 pub use tests::IndexEntryBuilder; |
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
1786 |
ec7171748350
rust: apply clippy lints
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
1787 #[cfg(test)] |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1788 mod tests { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1789 use super::*; |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1790 use crate::node::NULL_NODE; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1791 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1792 #[cfg(test)] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1793 #[derive(Debug, Copy, Clone)] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1794 pub struct IndexEntryBuilder { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1795 is_first: bool, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1796 is_inline: bool, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1797 is_general_delta: bool, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1798 version: u16, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1799 offset: usize, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1800 compressed_len: usize, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1801 uncompressed_len: usize, |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1802 base_revision_or_base_of_delta_chain: Revision, |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1803 link_revision: Revision, |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1804 p1: Revision, |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1805 p2: Revision, |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1806 node: Node, |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1807 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1808 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1809 #[cfg(test)] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1810 impl IndexEntryBuilder { |
49926
0780371d6b1e
rust-clippy: tell `clippy` we don't need to declare a default here
Raphaël Gomès <rgomes@octobus.net>
parents:
49631
diff
changeset
|
1811 #[allow(clippy::new_without_default)] |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1812 pub fn new() -> Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1813 Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1814 is_first: false, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1815 is_inline: false, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1816 is_general_delta: true, |
49092
d200ecb76c72
rust-revlog: change default version from 2 to 1 in test builder
Martin von Zweigbergk <martinvonz@google.com>
parents:
48546
diff
changeset
|
1817 version: 1, |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1818 offset: 0, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1819 compressed_len: 0, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1820 uncompressed_len: 0, |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1821 base_revision_or_base_of_delta_chain: Revision(0), |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
1822 link_revision: Revision(0), |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1823 p1: NULL_REVISION, |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1824 p2: NULL_REVISION, |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1825 node: NULL_NODE, |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1826 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1827 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1828 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1829 pub fn is_first(&mut self, value: bool) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1830 self.is_first = value; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1831 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1832 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1833 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1834 pub fn with_inline(&mut self, value: bool) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1835 self.is_inline = value; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1836 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1837 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1838 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1839 pub fn with_general_delta(&mut self, value: bool) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1840 self.is_general_delta = value; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1841 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1842 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1843 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1844 pub fn with_version(&mut self, value: u16) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1845 self.version = value; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1846 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1847 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1848 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1849 pub fn with_offset(&mut self, value: usize) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1850 self.offset = value; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1851 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1852 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1853 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1854 pub fn with_compressed_len(&mut self, value: usize) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1855 self.compressed_len = value; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1856 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1857 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1858 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1859 pub fn with_uncompressed_len(&mut self, value: usize) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1860 self.uncompressed_len = value; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1861 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1862 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1863 |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1864 pub fn with_base_revision_or_base_of_delta_chain( |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1865 &mut self, |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1866 value: Revision, |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1867 ) -> &mut Self { |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1868 self.base_revision_or_base_of_delta_chain = value; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1869 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1870 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1871 |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1872 pub fn with_link_revision(&mut self, value: Revision) -> &mut Self { |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1873 self.link_revision = value; |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1874 self |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1875 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1876 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1877 pub fn with_p1(&mut self, value: Revision) -> &mut Self { |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1878 self.p1 = value; |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1879 self |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1880 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1881 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1882 pub fn with_p2(&mut self, value: Revision) -> &mut Self { |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1883 self.p2 = value; |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1884 self |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1885 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1886 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1887 pub fn with_node(&mut self, value: Node) -> &mut Self { |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1888 self.node = value; |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1889 self |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1890 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1891 |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1892 pub fn build(&self) -> Vec<u8> { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1893 let mut bytes = Vec::with_capacity(INDEX_ENTRY_SIZE); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1894 if self.is_first { |
51272
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1895 bytes.extend(match (self.is_general_delta, self.is_inline) { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1896 (false, false) => [0u8, 0], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1897 (false, true) => [0u8, 1], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1898 (true, false) => [0u8, 2], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1899 (true, true) => [0u8, 3], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1900 }); |
51272
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1901 bytes.extend(self.version.to_be_bytes()); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1902 // Remaining offset bytes. |
51272
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1903 bytes.extend([0u8; 2]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1904 } else { |
46887
6d5a26e94d9e
unit-tests: Fix `cargo test` on 32-bit platforms
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
1905 // Offset stored on 48 bits (6 bytes) |
6d5a26e94d9e
unit-tests: Fix `cargo test` on 32-bit platforms
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
1906 bytes.extend(&(self.offset as u64).to_be_bytes()[2..]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1907 } |
51272
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1908 bytes.extend([0u8; 2]); // Revision flags. |
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1909 bytes.extend((self.compressed_len as u32).to_be_bytes()); |
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1910 bytes.extend((self.uncompressed_len as u32).to_be_bytes()); |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1911 bytes.extend( |
51272
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1912 self.base_revision_or_base_of_delta_chain.0.to_be_bytes(), |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
1913 ); |
51272
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1914 bytes.extend(self.link_revision.0.to_be_bytes()); |
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1915 bytes.extend(self.p1.0.to_be_bytes()); |
c4cbb515b006
rust-clippy: apply some more trivial fixes
Raphaël Gomès <rgomes@octobus.net>
parents:
51264
diff
changeset
|
1916 bytes.extend(self.p2.0.to_be_bytes()); |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1917 bytes.extend(self.node.as_bytes()); |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
1918 bytes.extend(vec![0u8; 12]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1919 bytes |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1920 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1921 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1922 |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1923 pub fn is_inline(index_bytes: &[u8]) -> bool { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1924 IndexHeader::parse(index_bytes) |
52162
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
1925 .expect("invalid header") |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1926 .format_flags() |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1927 .is_inline() |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1928 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1929 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1930 pub fn uses_generaldelta(index_bytes: &[u8]) -> bool { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1931 IndexHeader::parse(index_bytes) |
52162
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
1932 .expect("invalid header") |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1933 .format_flags() |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1934 .uses_generaldelta() |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1935 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1936 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1937 pub fn get_version(index_bytes: &[u8]) -> u16 { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1938 IndexHeader::parse(index_bytes) |
52162
f2eab4967bfc
rust-index: return an error on a bad index header
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
1939 .expect("invalid header") |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1940 .format_version() |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1941 } |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1942 |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1943 #[test] |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1944 fn flags_when_no_inline_flag_test() { |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1945 let bytes = IndexEntryBuilder::new() |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1946 .is_first(true) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1947 .with_general_delta(false) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1948 .with_inline(false) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1949 .build(); |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1950 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
1951 assert!(!is_inline(&bytes)); |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
1952 assert!(!uses_generaldelta(&bytes)); |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1953 } |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1954 |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1955 #[test] |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1956 fn flags_when_inline_flag_test() { |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1957 let bytes = IndexEntryBuilder::new() |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1958 .is_first(true) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1959 .with_general_delta(false) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1960 .with_inline(true) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1961 .build(); |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1962 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
1963 assert!(is_inline(&bytes)); |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
1964 assert!(!uses_generaldelta(&bytes)); |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1965 } |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1966 |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1967 #[test] |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
1968 fn flags_when_inline_and_generaldelta_flags_test() { |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1969 let bytes = IndexEntryBuilder::new() |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1970 .is_first(true) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1971 .with_general_delta(true) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1972 .with_inline(true) |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1973 .build(); |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1974 |
49930
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
1975 assert!(is_inline(&bytes)); |
e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents:
49926
diff
changeset
|
1976 assert!(uses_generaldelta(&bytes)); |
45601
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1977 } |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1978 |
900b9b79b99c
hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45593
diff
changeset
|
1979 #[test] |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1980 fn test_offset() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1981 let bytes = IndexEntryBuilder::new().with_offset(1).build(); |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
1982 let entry = IndexEntry { bytes: &bytes }; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1983 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1984 assert_eq!(entry.offset(), 1) |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1985 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1986 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1987 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1988 fn test_compressed_len() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1989 let bytes = IndexEntryBuilder::new().with_compressed_len(1).build(); |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
1990 let entry = IndexEntry { bytes: &bytes }; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1991 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1992 assert_eq!(entry.compressed_len(), 1) |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1993 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1994 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1995 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1996 fn test_uncompressed_len() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1997 let bytes = IndexEntryBuilder::new().with_uncompressed_len(1).build(); |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
1998 let entry = IndexEntry { bytes: &bytes }; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1999 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2000 assert_eq!(entry.uncompressed_len(), 1) |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2001 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2002 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2003 #[test] |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
2004 fn test_base_revision_or_base_of_delta_chain() { |
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
2005 let bytes = IndexEntryBuilder::new() |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
2006 .with_base_revision_or_base_of_delta_chain(Revision(1)) |
48458
96ea4db4741b
rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48457
diff
changeset
|
2007 .build(); |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
2008 let entry = IndexEntry { bytes: &bytes }; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2009 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
2010 assert_eq!(entry.base_revision_or_base_of_delta_chain(), 1.into()) |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2011 } |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2012 |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2013 #[test] |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2014 fn link_revision_test() { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
2015 let bytes = IndexEntryBuilder::new() |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
2016 .with_link_revision(Revision(123)) |
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
2017 .build(); |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2018 |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
2019 let entry = IndexEntry { bytes: &bytes }; |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2020 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
2021 assert_eq!(entry.link_revision(), 123.into()); |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2022 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2023 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2024 #[test] |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2025 fn p1_test() { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
2026 let bytes = IndexEntryBuilder::new().with_p1(Revision(123)).build(); |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2027 |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
2028 let entry = IndexEntry { bytes: &bytes }; |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2029 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
2030 assert_eq!(entry.p1(), 123.into()); |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2031 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2032 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2033 #[test] |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2034 fn p2_test() { |
50979
4c5f6e95df84
rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents:
50978
diff
changeset
|
2035 let bytes = IndexEntryBuilder::new().with_p2(Revision(123)).build(); |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2036 |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
2037 let entry = IndexEntry { bytes: &bytes }; |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2038 |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49930
diff
changeset
|
2039 assert_eq!(entry.p2(), 123.into()); |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2040 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2041 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2042 #[test] |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2043 fn node_test() { |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2044 let node = Node::from_hex("0123456789012345678901234567890123456789") |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2045 .unwrap(); |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2046 let bytes = IndexEntryBuilder::new().with_node(node).build(); |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2047 |
51445
d2858d97af6c
rust-index: drop offset_override
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51425
diff
changeset
|
2048 let entry = IndexEntry { bytes: &bytes }; |
49093
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2049 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2050 assert_eq!(*entry.hash(), node); |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2051 } |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2052 |
2a9a55ffe24f
rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents:
49092
diff
changeset
|
2053 #[test] |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2054 fn version_test() { |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2055 let bytes = IndexEntryBuilder::new() |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2056 .is_first(true) |
49092
d200ecb76c72
rust-revlog: change default version from 2 to 1 in test builder
Martin von Zweigbergk <martinvonz@google.com>
parents:
48546
diff
changeset
|
2057 .with_version(2) |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2058 .build(); |
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2059 |
49092
d200ecb76c72
rust-revlog: change default version from 2 to 1 in test builder
Martin von Zweigbergk <martinvonz@google.com>
parents:
48546
diff
changeset
|
2060 assert_eq!(get_version(&bytes), 2) |
48457
1fb3615dfce2
rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48226
diff
changeset
|
2061 } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2062 } |