annotate rust/hg-core/src/revlog/index.rs @ 51236:eb676c35a29b

rust-index: support `unionrepo`'s compressed length hack Explanations inline.
author Raphaël Gomès <rgomes@octobus.net>
date Tue, 31 Oct 2023 17:58:56 +0100
parents 456e0fe702e8
children e74dd6d73cb5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51215
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
1 use std::collections::hash_map::RandomState;
51220
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
2 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
3 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
4 use std::ops::Deref;
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
5 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
6
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;
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
21 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
22
51218
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
23 #[derive(Debug)]
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
24 pub struct IndexHeader {
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
25 pub(super) header_bytes: [u8; 4],
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
26 }
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 #[derive(Copy, Clone)]
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
29 pub struct IndexHeaderFlags {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
30 flags: u16,
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
31 }
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 /// 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
34 impl IndexHeaderFlags {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
35 /// Corresponds to FLAG_INLINE_DATA in python
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
36 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
37 self.flags & 1 != 0
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
38 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
39 /// Corresponds to FLAG_GENERALDELTA in python
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
40 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
41 self.flags & 2 != 0
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
42 }
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 /// Corresponds to the INDEX_HEADER structure,
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
46 /// 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
47 impl IndexHeader {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
48 fn format_flags(&self) -> IndexHeaderFlags {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
49 // 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
50 // be.
49930
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
51 IndexHeaderFlags {
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
52 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
53 }
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
54 }
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 /// The only revlog version currently supported by rhg.
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
57 const REVLOGV1: u16 = 1;
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
58
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
59 /// Corresponds to `_format_version` in Python.
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
60 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
61 BigEndian::read_u16(&self.header_bytes[2..4])
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
62 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
63
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
64 pub fn parse(index_bytes: &[u8]) -> Result<Option<IndexHeader>, HgError> {
49930
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
65 if index_bytes.is_empty() {
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
66 return Ok(None);
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
67 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
68 if index_bytes.len() < 4 {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
69 return Err(HgError::corrupted(
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
70 "corrupted revlog: can't read the index format header",
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
71 ));
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
72 }
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
73 Ok(Some(IndexHeader {
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
74 header_bytes: {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
75 let bytes: [u8; 4] =
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
76 index_bytes[0..4].try_into().expect("impossible");
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
77 bytes
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
78 },
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
79 }))
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
80 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
81 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
82
51188
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
83 /// 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
84 /// 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
85 /// 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
86 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
87 /// 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
88 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
89 /// 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
90 /// 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
91 /// `bytes` field.
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
92 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
93 /// 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
94 added: Vec<u8>,
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
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
97 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
98 pub fn new(bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>) -> 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
99 Self {
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
100 bytes,
51195
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
101 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
102 added: vec![],
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
103 }
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
104 }
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
105
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
106 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
107 match self.truncation {
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
108 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
109 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
110 }
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
111 }
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
112
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
113 fn remove(
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
114 &mut self,
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
115 rev: Revision,
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
116 offsets: Option<&[usize]>,
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
117 ) -> Result<(), RevlogError> {
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
118 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
119 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
120 offsets[rev]
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
121 } else {
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
122 rev * INDEX_ENTRY_SIZE
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
123 };
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
124 if truncation < self.bytes.len() {
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
125 self.truncation = Some(truncation);
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
126 self.added.clear();
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
127 } else {
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
128 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
129 }
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
130 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
131 }
51205
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
132
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
133 fn is_new(&self) -> bool {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
134 self.bytes.is_empty()
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
135 }
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 }
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
137
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
138 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
139 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
140
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
141 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
142 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
143 let end = index.end;
51195
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
144 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
145 Some(truncation) => truncation,
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
146 None => self.bytes.len(),
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
147 };
51188
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
148 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
149 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
150 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
151 }
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
152 &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
153 } else {
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
154 &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
155 }
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 }
1ef4a36a934d rust-index: add an abstraction to support bytes added at runtimes
Raphaël Gomès <rgomes@octobus.net>
parents: 50979
diff changeset
158
51205
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
159 #[derive(Debug, PartialEq, Eq)]
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
160 pub struct RevisionDataParams {
51192
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
161 pub flags: u16,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
162 pub data_offset: u64,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
163 pub data_compressed_length: i32,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
164 pub data_uncompressed_length: i32,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
165 pub data_delta_base: i32,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
166 pub link_rev: i32,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
167 pub parent_rev_1: i32,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
168 pub parent_rev_2: i32,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
169 pub node_id: [u8; NODE_BYTES_LENGTH],
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
170 pub _sidedata_offset: u64,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
171 pub _sidedata_compressed_length: i32,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
172 pub data_compression_mode: u8,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
173 pub _sidedata_compression_mode: u8,
65c9032e2e5a rust-index: synchronize append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51191
diff changeset
174 pub _rank: i32,
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
175 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
176
51205
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
177 impl Default for RevisionDataParams {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
178 fn default() -> Self {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
179 Self {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
180 flags: 0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
181 data_offset: 0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
182 data_compressed_length: 0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
183 data_uncompressed_length: 0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
184 data_delta_base: -1,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
185 link_rev: -1,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
186 parent_rev_1: -1,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
187 parent_rev_2: -1,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
188 node_id: [0; NODE_BYTES_LENGTH],
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
189 _sidedata_offset: 0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
190 _sidedata_compressed_length: 0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
191 data_compression_mode: COMPRESSION_MODE_INLINE,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
192 _sidedata_compression_mode: COMPRESSION_MODE_INLINE,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
193 _rank: -1,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
194 }
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
195 }
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
196 }
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
197
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
198 #[derive(BytesCast)]
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
199 #[repr(C)]
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
200 pub struct RevisionDataV1 {
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
201 data_offset_or_flags: unaligned::U64Be,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
202 data_compressed_length: unaligned::I32Be,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
203 data_uncompressed_length: unaligned::I32Be,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
204 data_delta_base: unaligned::I32Be,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
205 link_rev: unaligned::I32Be,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
206 parent_rev_1: unaligned::I32Be,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
207 parent_rev_2: unaligned::I32Be,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
208 node_id: [u8; STORED_NODE_ID_BYTES],
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
209 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
210
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
211 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
212 let _ = std::mem::transmute::<RevisionDataV1, [u8; 64]>;
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
213 }
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 impl RevisionDataParams {
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
216 pub fn validate(&self) -> Result<(), RevlogError> {
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
217 if self.flags & !REVIDX_KNOWN_FLAGS != 0 {
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
218 return Err(RevlogError::corrupted(format!(
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
219 "unknown revlog index flags: {}",
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
220 self.flags
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
221 )));
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
222 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
223 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
224 return Err(RevlogError::corrupted(format!(
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
225 "invalid data compression mode: {}",
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
226 self.data_compression_mode
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 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
229 // 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
230 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
231 return Err(RevlogError::corrupted(format!(
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
232 "invalid sidedata compression mode: {}",
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
233 self._sidedata_compression_mode
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
234 )));
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
235 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
236 Ok(())
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
237 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
238
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
239 pub fn into_v1(self) -> RevisionDataV1 {
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
240 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
241 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
242 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
243 RevisionDataV1 {
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
244 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
245 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
246 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
247 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
248 link_rev: self.link_rev.into(),
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
249 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
250 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
251 node_id,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
252 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
253 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
254 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
255
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
256 /// 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
257 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
258 bytes: IndexData,
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
259 /// 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
260 /// 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
261 offsets: RwLock<Option<Vec<usize>>>,
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
262 uses_generaldelta: bool,
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
263 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
264 /// 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
265 ///
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
266 /// 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
267 /// 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
268 /// 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
269 /// we haven't changed filters when returning the cached `head_revs`.
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
270 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
271 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
272
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
273 impl Debug for Index {
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
274 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
275 f.debug_struct("Index")
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
276 .field("offsets", &self.offsets)
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
277 .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
278 .finish()
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
279 }
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
280 }
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
281
50978
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
282 impl Graph for Index {
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
283 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
284 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
285 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
286 Some(entry) => {
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
287 // 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
288 // before returning
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
289 Ok([
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
290 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
291 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
292 ])
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
293 }
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
294 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
295 }
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
296 }
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
297 }
27e773aa607d rust: implement the `Graph` trait for all revlogs
Raphaël Gomès <rgomes@octobus.net>
parents: 50977
diff changeset
298
51212
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
299 /// 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
300 ///
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
301 /// 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
302 /// values sets of [`BaseRevision`]
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
303 ///
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
304 /// 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
305 /// 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
306 /// 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
307 /// 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
308 pub trait SnapshotsCache {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
309 fn insert_for(
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
310 &mut self,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
311 rev: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
312 value: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
313 ) -> Result<(), RevlogError>;
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
314 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
315
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
316 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
317 fn insert_for(
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
318 &mut self,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
319 rev: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
320 value: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
321 ) -> Result<(), RevlogError> {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
322 let all_values = self.entry(rev).or_insert_with(HashSet::new);
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
323 all_values.insert(value);
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
324 Ok(())
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
325 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
326 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
327
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
328 impl Index {
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
329 /// Create an index from bytes.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
330 /// 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
331 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
332 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
333 default_header: IndexHeader,
47963
001d747c2baf rust: Return HgError instead of RevlogError in revlog constructors
Simon Sapin <simon.sapin@octobus.net>
parents: 46887
diff changeset
334 ) -> Result<Self, HgError> {
51191
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents: 51189
diff changeset
335 let header =
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents: 51189
diff changeset
336 IndexHeader::parse(bytes.as_ref())?.unwrap_or(default_header);
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
337
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
338 if header.format_version() != IndexHeader::REVLOGV1 {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
339 // 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
340 // requirement.
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
341 return Err(HgError::corrupted("unsupported revlog version"));
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
342 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
343
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
344 // This is only correct because we know version is REVLOGV1.
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
345 // In v2 we always use generaldelta, while in v0 we never use
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
346 // generaldelta. Similar for [is_inline] (it's only used in v1).
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
347 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
348
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
349 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
350 let mut offset: usize = 0;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
351 let mut offsets = Vec::new();
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
352
45590
11f3c3f408fd hg-core: minor code style change (D8958#inline-14993 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45536
diff changeset
353 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
354 offsets.push(offset);
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
355 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
356 let entry = IndexEntry {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
357 bytes: &bytes[offset..end],
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
358 offset_override: None,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
359 };
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
360
48543
0a4ac916673e rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents: 48458
diff changeset
361 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
362 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
363
45602
1cef583541c0 hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents: 45601
diff changeset
364 if offset == bytes.len() {
1cef583541c0 hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents: 45601
diff changeset
365 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
366 bytes: IndexData::new(bytes),
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
367 offsets: RwLock::new(Some(offsets)),
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
368 uses_generaldelta,
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
369 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
370 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
371 })
1cef583541c0 hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents: 45601
diff changeset
372 } else {
49930
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
373 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
374 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
375 } else {
45602
1cef583541c0 hg-core: return Err if `offset != bytes.len()`
Antoine cezar<acezar@chwitlabs.fr>
parents: 45601
diff changeset
376 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
377 bytes: IndexData::new(bytes),
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
378 offsets: RwLock::new(None),
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
379 uses_generaldelta,
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
380 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
381 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
382 })
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
383 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
384 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
385
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
386 pub fn uses_generaldelta(&self) -> bool {
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
387 self.uses_generaldelta
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
388 }
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
389
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
390 /// 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
391 pub fn is_inline(&self) -> bool {
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
392 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
393 }
900b9b79b99c hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45593
diff changeset
394
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 /// 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
396 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
397 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
398 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
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 &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
401 }
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
45536
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
403 /// 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
404 pub fn len(&self) -> usize {
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
405 if let Some(offsets) = &*self.get_offsets() {
45536
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
406 offsets.len()
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
407 } else {
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
408 self.bytes.len() / INDEX_ENTRY_SIZE
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
409 }
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
410 }
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
411
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
412 pub fn get_offsets(&self) -> RwLockReadGuard<Option<Vec<usize>>> {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
413 if self.is_inline() {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
414 {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
415 // Wrap in a block to drop the read guard
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
416 // TODO perf?
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
417 let mut offsets = self.offsets.write().unwrap();
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
418 if offsets.is_none() {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
419 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
420 }
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
421 }
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
422 }
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
423 self.offsets.read().unwrap()
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
424 }
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
425
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
426 pub fn get_offsets_mut(&mut self) -> RwLockWriteGuard<Option<Vec<usize>>> {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
427 let mut offsets = self.offsets.write().unwrap();
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
428 if self.is_inline() && offsets.is_none() {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
429 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
430 }
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
431 offsets
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
432 }
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
433
45536
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
434 /// 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
435 pub fn is_empty(&self) -> bool {
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
436 self.len() == 0
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
437 }
639f33f22faf hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45531
diff changeset
438
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
439 /// 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
440 /// 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
441 ///
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
442 /// 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
443 /// if it was validated by this index.
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
444 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
445 if rev == NULL_REVISION {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
446 return None;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
447 }
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
448 Some(if let Some(offsets) = &*self.get_offsets() {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
449 self.get_entry_inline(rev, offsets.as_ref())
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
450 } else {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
451 self.get_entry_separated(rev)
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
452 })
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
453 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
454
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
455 /// 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
456 ///
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
457 /// 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
458 /// 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
459 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
460 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
461 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
462 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
463 &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
464 } 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
465 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
466 }
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
467 })
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
468 }
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
51205
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
470 pub fn entry_as_params(
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
471 &self,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
472 rev: UncheckedRevision,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
473 ) -> Option<RevisionDataParams> {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
474 let rev = self.check_revision(rev)?;
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
475 self.get_entry(rev).map(|e| RevisionDataParams {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
476 flags: e.flags(),
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
477 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
478 e.flags() as u64
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
479 } else {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
480 e.raw_offset()
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
481 },
51236
eb676c35a29b rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents: 51235
diff changeset
482 data_compressed_length: e
eb676c35a29b rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents: 51235
diff changeset
483 .compressed_len()
eb676c35a29b rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents: 51235
diff changeset
484 .try_into()
eb676c35a29b rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents: 51235
diff changeset
485 .unwrap_or_else(|_| {
eb676c35a29b rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents: 51235
diff changeset
486 // 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
487 // `-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
488 // 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
489 // 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
490 // 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
491 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
492 NULL_REVISION.0
eb676c35a29b rust-index: support `unionrepo`'s compressed length hack
Raphaël Gomès <rgomes@octobus.net>
parents: 51235
diff changeset
493 }),
51205
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
494 data_uncompressed_length: e.uncompressed_len(),
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
495 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
496 link_rev: e.link_revision().0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
497 parent_rev_1: e.p1().0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
498 parent_rev_2: e.p2().0,
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
499 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
500 ..Default::default()
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
501 })
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
502 }
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
503
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
504 fn get_entry_inline(
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
505 &self,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
506 rev: Revision,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
507 offsets: &[usize],
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
508 ) -> IndexEntry {
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
509 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
510 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
511 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
512
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
513 // See IndexEntry for an explanation of this override.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
514 let offset_override = Some(end);
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
515
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
516 IndexEntry {
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
517 bytes,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
518 offset_override,
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
519 }
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
520 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
521
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
522 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
523 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
524 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
525 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
526
45591
f38adf8b0711 hg-core: Explain offset override of first revision
Antoine cezar<acezar@chwitlabs.fr>
parents: 45590
diff changeset
527 // Override the offset of the first revision as its bytes are used
f38adf8b0711 hg-core: Explain offset override of first revision
Antoine cezar<acezar@chwitlabs.fr>
parents: 45590
diff changeset
528 // for the index's metadata (saving space because it is always 0)
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
529 let offset_override = if rev == Revision(0) { Some(0) } else { None };
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
530
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
531 IndexEntry {
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
532 bytes,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
533 offset_override,
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
534 }
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
535 }
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
536
51218
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
537 fn null_entry(&self) -> IndexEntry {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
538 IndexEntry {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
539 bytes: &[0; INDEX_ENTRY_SIZE],
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
540 offset_override: Some(0),
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
541 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
542 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
543
51215
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
544 /// 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
545 pub fn head_revs(&self) -> Result<Vec<Revision>, GraphError> {
51216
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
546 self.head_revs_filtered(&HashSet::new())
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
547 }
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
548
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
549 /// Return the head revisions of this index
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
550 pub fn head_revs_filtered(
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
551 &self,
51216
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
552 filtered_revs: &HashSet<Revision>,
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
553 ) -> Result<Vec<Revision>, GraphError> {
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
554 {
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
555 let guard = 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
556 .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
557 .read()
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
558 .expect("RwLock on Index.head_revs should not be poisoned");
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
559 let self_head_revs = &guard.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
560 let self_filtered_revs = &guard.1;
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
561 if !self_head_revs.is_empty()
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
562 && filtered_revs == self_filtered_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
563 {
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
564 return Ok(self_head_revs.to_owned());
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
565 }
51215
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
566 }
51216
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
567 let mut revs: HashSet<Revision, RandomState> =
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
568 if filtered_revs.is_empty() {
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
569 (0..self.len())
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
570 .into_iter()
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
571 .map(|i| Revision(i as BaseRevision))
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
572 .collect()
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
573 } else {
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
574 (0..self.len())
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
575 .into_iter()
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
576 .filter_map(|i| {
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
577 let r = Revision(i as BaseRevision);
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
578 if filtered_revs.contains(&r) {
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
579 None
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
580 } else {
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
581 Some(r)
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
582 }
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
583 })
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
584 .collect()
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Raphaël Gomès <rgomes@octobus.net>
parents: 51215
diff changeset
585 };
51215
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
586 dagops::retain_heads(self, &mut revs)?;
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
587 if self.is_empty() {
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
588 revs.insert(NULL_REVISION);
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
589 }
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
590 let mut as_vec: Vec<Revision> =
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
591 revs.into_iter().map(Into::into).collect();
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
592 as_vec.sort_unstable();
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
593 *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
594 .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
595 .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
596 .expect("RwLock on Index.head_revs should not be poisoned") =
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
597 (as_vec.to_owned(), filtered_revs.to_owned());
51215
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
598 Ok(as_vec)
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
599 }
a7bba7df9189 rust-index: implement headrevs
Raphaël Gomès <rgomes@octobus.net>
parents: 51213
diff changeset
600
51213
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
601 /// 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
602 ///
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
603 /// `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
604 /// 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
605 ///
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
606 /// 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
607 /// 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
608 /// `stoprev` was hit.
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
609 pub fn delta_chain(
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
610 &self,
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
611 rev: Revision,
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
612 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
613 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
614 ) -> 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
615 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
616 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
617 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
618 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
619 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
620 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
621 && 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
622 {
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
623 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
624 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
625 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
626 } else {
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
627 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
628 };
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
629 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
630 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
631 })?;
51218
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
632 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
633 break;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
634 }
51213
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
635 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
636 }
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
637
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
638 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
639 true
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
640 } else {
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
641 chain.push(current_rev);
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
642 false
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
643 };
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
644 chain.reverse();
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
645 Ok((chain, stopped))
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
646 }
62e39bef36ca rust-index: add support for delta-chain computation
Raphaël Gomès <rgomes@octobus.net>
parents: 51212
diff changeset
647
51212
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
648 pub fn find_snapshots(
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
649 &self,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
650 start_rev: UncheckedRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
651 end_rev: UncheckedRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
652 cache: &mut impl SnapshotsCache,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
653 ) -> Result<(), RevlogError> {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
654 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
655 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
656 end_rev += 1;
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
657 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
658 if end_rev > len {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
659 end_rev = len;
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
660 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
661 if start_rev < 0 {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
662 start_rev = 0;
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
663 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
664 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
665 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
666 continue;
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
667 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
668 let mut base = self
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
669 .get_entry(Revision(rev))
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
670 .unwrap()
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
671 .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
672 if base.0 == rev {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
673 base = NULL_REVISION.into();
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
674 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
675 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
676 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
677 Ok(())
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
678 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Raphaël Gomès <rgomes@octobus.net>
parents: 51211
diff changeset
679
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
680 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
681 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
682 .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
683 .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
684 .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
685 .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
686 }
59183a19954e rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51233
diff changeset
687
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
688 /// 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
689 pub fn append(
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
690 &mut self,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
691 revision_data: RevisionDataParams,
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
692 ) -> Result<(), RevlogError> {
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
693 revision_data.validate()?;
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
694 let new_offset = self.bytes.len();
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
695 if let Some(offsets) = &mut *self.get_offsets_mut() {
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
696 offsets.push(new_offset)
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
697 }
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
698 self.bytes.added.extend(revision_data.into_v1().as_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
699 self.clear_head_revs();
51189
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
700 Ok(())
b4d152a28742 rust-index: add append method
Raphaël Gomès <rgomes@octobus.net>
parents: 51188
diff changeset
701 }
51195
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
702
51198
51cc12158f97 rust-index: add `pack_header` support
Raphaël Gomès <rgomes@octobus.net>
parents: 51197
diff changeset
703 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
704 header.to_be_bytes()
51cc12158f97 rust-index: add `pack_header` support
Raphaël Gomès <rgomes@octobus.net>
parents: 51197
diff changeset
705 }
51cc12158f97 rust-index: add `pack_header` support
Raphaël Gomès <rgomes@octobus.net>
parents: 51197
diff changeset
706
51195
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
707 pub fn remove(&mut self, rev: Revision) -> Result<(), RevlogError> {
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
708 let offsets = self.get_offsets().clone();
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
709 self.bytes.remove(rev, offsets.as_deref())?;
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
710 if let Some(offsets) = &mut *self.get_offsets_mut() {
51195
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
711 offsets.truncate(rev.0 as usize)
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
712 }
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
713 self.clear_head_revs();
51195
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
714 Ok(())
f6403bcd9f96 rust-index: synchronize remove to Rust index
Raphaël Gomès <rgomes@octobus.net>
parents: 51192
diff changeset
715 }
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
716
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
717 pub fn clear_caches(&self) {
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
718 // 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
719 // 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
720 // 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
721 *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
722 .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
723 .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
724 .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
725 self.clear_head_revs();
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
726 }
51211
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
727
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
728 /// Unchecked version of `is_snapshot`.
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
729 /// 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
730 pub fn is_snapshot_unchecked(
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
731 &self,
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
732 mut rev: Revision,
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
733 ) -> Result<bool, RevlogError> {
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
734 while rev.0 >= 0 {
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
735 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
736 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
737 if base == rev.0 {
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
738 base = NULL_REVISION.0;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
739 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
740 if base == NULL_REVISION.0 {
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
741 return Ok(true);
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
742 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
743 let [mut p1, mut p2] = self
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
744 .parents(rev)
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
745 .map_err(|_| RevlogError::InvalidRevision)?;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
746 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
747 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
748 break;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
749 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
750 let parent_base =
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
751 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
752 if parent_base.0 == p1.0 {
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
753 break;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
754 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
755 p1 = self
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
756 .check_revision(parent_base)
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
757 .ok_or(RevlogError::InvalidRevision)?;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
758 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
759 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
760 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
761 break;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
762 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
763 let parent_base =
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
764 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
765 if parent_base.0 == p2.0 {
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
766 break;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
767 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
768 p2 = self
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
769 .check_revision(parent_base)
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
770 .ok_or(RevlogError::InvalidRevision)?;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
771 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
772 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
773 return Ok(false);
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
774 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
775 rev = self
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
776 .check_revision(base.into())
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
777 .ok_or(RevlogError::InvalidRevision)?;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
778 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
779 Ok(rev == NULL_REVISION)
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
780 }
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
781
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
782 /// 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
783 /// `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
784 pub fn is_snapshot(
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
785 &self,
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
786 rev: UncheckedRevision,
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
787 ) -> Result<bool, RevlogError> {
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
788 let rev = self
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
789 .check_revision(rev)
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
790 .ok_or_else(|| RevlogError::corrupted("test"))?;
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
791 self.is_snapshot_unchecked(rev)
b8c89957a6b7 rust-index: add `is_snapshot` method
Raphaël Gomès <rgomes@octobus.net>
parents: 51209
diff changeset
792 }
51218
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
793
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
794 /// 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
795 ///
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
796 /// 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
797 ///
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
798 /// 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
799 /// (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
800 /// 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
801 pub fn slice_chunk_to_density(
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
802 &self,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
803 revs: &[Revision],
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
804 target_density: f64,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
805 min_gap_size: usize,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
806 ) -> Vec<Vec<Revision>> {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
807 if revs.is_empty() {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
808 return vec![];
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
809 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
810 if revs.len() == 1 {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
811 return vec![revs.to_owned()];
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
812 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
813 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
814 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
815 return vec![revs.to_owned()];
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
816 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
817 let entries: Vec<_> = revs
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
818 .iter()
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
819 .map(|r| {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
820 (*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
821 })
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
822 .collect();
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
823
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
824 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
825 let chain_payload: u32 =
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
826 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
827 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
828 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
829 } else {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
830 1.0
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
831 };
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
832
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
833 if density >= target_density {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
834 return vec![revs.to_owned()];
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
835 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
836
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
837 // 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
838 let mut gaps = Vec::new();
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
839 let mut previous_end = None;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
840
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
841 for (i, (_rev, entry)) in entries.iter().enumerate() {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
842 let start = entry.c_start() as usize;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
843 let length = entry.compressed_len();
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
844
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
845 // 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
846 if length == 0 {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
847 continue;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
848 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
849
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
850 if let Some(end) = previous_end {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
851 let gap_size = start - end;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
852 // 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
853 if gap_size > min_gap_size {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
854 gaps.push((gap_size, i));
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
855 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
856 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
857 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
858 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
859 if gaps.is_empty() {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
860 return vec![revs.to_owned()];
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
861 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
862 // 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
863 gaps.sort_unstable();
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
864
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
865 // 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
866 // the density is acceptable
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
867 let mut selected = vec![];
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
868 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
869 if density >= target_density {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
870 break;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
871 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
872 selected.push(gap_id);
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
873
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
874 // 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
875 // by the heap
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
876 read_data -= gap_size;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
877 density = if read_data > 0 {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
878 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
879 } else {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
880 1.0
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
881 };
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
882 if density >= target_density {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
883 break;
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 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
886 selected.sort_unstable();
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
887 selected.push(revs.len());
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
888
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
889 // Cut the revs at collected indices
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
890 let mut previous_idx = 0;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
891 let mut chunks = vec![];
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
892 for idx in selected {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
893 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
894 if !chunk.is_empty() {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
895 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
896 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
897 previous_idx = idx;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
898 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
899 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
900 if !chunk.is_empty() {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
901 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
902 }
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 chunks
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
905 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
906
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
907 /// 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
908 ///
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
909 /// 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
910 /// the `revs` segment.
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
911 ///
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
912 /// panics:
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
913 /// - 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
914 /// - 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
915 /// `revs`.
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
916 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
917 if revs.is_empty() {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
918 return 0;
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 let last_entry = &self.get_entry(revs[revs.len() - 1]).unwrap();
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
921 let end = last_entry.c_start() + last_entry.compressed_len() as u64;
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
922 let first_rev = revs.iter().find(|r| r.0 != NULL_REVISION.0).unwrap();
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
923 let start = if (*first_rev).0 == 0 {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
924 0
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
925 } else {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
926 self.get_entry(*first_rev).unwrap().c_start()
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
927 };
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
928 (end - start) as usize
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
929 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
930
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
931 /// 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
932 fn trim_chunk<'a>(
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
933 &'a self,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
934 revs: &'a [(Revision, IndexEntry)],
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
935 start: usize,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
936 mut end: usize,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
937 ) -> &'a [(Revision, IndexEntry)] {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
938 // 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
939 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
940 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
941 while end > 1
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
942 && end > start
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
943 && 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
944 {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
945 end -= 1
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
946 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
947 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
948 &revs[start..end]
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
949 }
51220
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
950
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
951 /// 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
952 /// 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
953 pub fn compute_phases_map_sets(
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
954 &self,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
955 roots: HashMap<Phase, Vec<Revision>>,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
956 ) -> Result<(usize, RootsPerPhase), GraphError> {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
957 let mut phases = HashMap::new();
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
958 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
959
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
960 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
961 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
962 let min_rev =
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
963 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
964 if min_rev != NULL_REVISION
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
965 && (min_phase_rev == NULL_REVISION
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
966 || min_rev < min_phase_rev)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
967 {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
968 min_phase_rev = min_rev;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
969 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
970 } else {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
971 continue;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
972 };
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
973 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
974 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
975
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
976 if min_phase_rev == NULL_REVISION {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
977 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
978 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
979
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
980 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
981 let rev = Revision(rev);
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
982 let [p1, p2] = self.parents(rev)?;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
983
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
984 const DEFAULT_PHASE: &Phase = &Phase::Public;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
985 if p1.0 >= 0
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
986 && phases.get(&p1).unwrap_or(DEFAULT_PHASE)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
987 > phases.get(&rev).unwrap_or(DEFAULT_PHASE)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
988 {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
989 phases.insert(rev, phases[&p1]);
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
990 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
991 if p2.0 >= 0
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
992 && phases.get(&p2).unwrap_or(DEFAULT_PHASE)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
993 > phases.get(&rev).unwrap_or(DEFAULT_PHASE)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
994 {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
995 phases.insert(rev, phases[&p2]);
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
996 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
997 let set = match phases.get(&rev).unwrap_or(DEFAULT_PHASE) {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
998 Phase::Public => continue,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
999 phase => &mut phase_sets[*phase as usize - 1],
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1000 };
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1001 set.insert(rev);
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1002 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1003
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1004 Ok((self.len(), phase_sets))
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1005 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1006
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1007 fn add_roots_get_min(
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1008 &self,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1009 phase_roots: &[Revision],
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1010 phases: &mut HashMap<Revision, Phase>,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1011 phase: Phase,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1012 ) -> Revision {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1013 let mut min_rev = NULL_REVISION;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1014
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1015 for root in phase_roots {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1016 phases.insert(*root, phase);
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1017 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
1018 min_rev = *root;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1019 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1020 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1021 min_rev
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1022 }
51222
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1023
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1024 /// Return `(heads(::(<roots> and <roots>::<heads>)))`
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1025 /// 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
1026 ///
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1027 /// `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
1028 /// 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
1029 /// 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
1030 /// revision ([`i32::MAX`]).
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1031 pub fn reachable_roots(
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1032 &self,
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1033 min_root: UncheckedRevision,
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1034 mut heads: Vec<Revision>,
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1035 roots: HashSet<UncheckedRevision>,
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1036 include_path: bool,
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1037 ) -> Result<HashSet<Revision>, GraphError> {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1038 if roots.is_empty() {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1039 return Ok(HashSet::new());
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1040 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1041 let mut reachable = HashSet::new();
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1042 let mut seen = HashMap::new();
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1043
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1044 while let Some(rev) = heads.pop() {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1045 if roots.contains(&rev.into()) {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1046 reachable.insert(rev);
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1047 if !include_path {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1048 continue;
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1049 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1050 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1051 let parents = self.parents(rev)?;
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1052 seen.insert(rev, parents);
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1053 for parent in parents {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1054 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
1055 heads.push(parent);
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1056 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1057 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1058 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1059 if !include_path {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1060 return Ok(reachable);
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1061 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1062 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
1063 revs.sort_unstable();
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1064 for rev in revs {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1065 for parent in seen[rev] {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1066 if reachable.contains(&parent) {
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1067 reachable.insert(*rev);
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1068 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1069 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1070 }
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1071 Ok(reachable)
fc05dd74e907 rust-index: add support for `reachableroots2`
Raphaël Gomès <rgomes@octobus.net>
parents: 51220
diff changeset
1072 }
51223
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1073
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1074 /// 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
1075 /// 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
1076 pub fn common_ancestor_heads(
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1077 &self,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1078 revisions: &[Revision],
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1079 ) -> Result<Vec<Revision>, GraphError> {
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1080 // 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
1081 // 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
1082 // 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
1083 // the onset.
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1084 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
1085 // 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
1086 // for `NULL_REVISION`:
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1087 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
1088 return Ok(vec![]);
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1089 }
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1090
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1091 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
1092
51229
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1093 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
1094 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
1095 } 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
1096 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
1097 } else {
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1098 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
1099 }
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1100 }
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1101
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1102 pub fn ancestors(
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1103 &self,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1104 revisions: &[Revision],
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1105 ) -> Result<Vec<Revision>, GraphError> {
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51224
diff changeset
1106 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
1107 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1108
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1109 /// 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
1110 /// 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
1111 /// `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
1112 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
1113 &self,
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1114 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
1115 ) -> 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
1116 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
1117 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
1118 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1119 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
1120 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
1121 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
1122
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1123 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
1124
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1125 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
1126 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
1127 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1128 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
1129 // 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
1130 // 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
1131 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
1132
51226
83091c14058c rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51225
diff changeset
1133 // 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
1134 // 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
1135 // 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
1136 // 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
1137
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1138 // 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
1139 // 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
1140 // 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
1141 // 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
1142 // 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
1143 //
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1144 // 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
1145 // 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
1146 // 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
1147 // 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
1148 // 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
1149 //
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1150 // 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
1151 // 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
1152 // - 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
1153 // - 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
1154 // - 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
1155 // 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
1156 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
1157 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
1158
51224
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1159 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
1160 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
1161 continue;
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1162 }
51226
83091c14058c rust-index: avoid some cloning in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51225
diff changeset
1163 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
1164 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
1165 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
1166 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
1167 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
1168 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
1169
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1170 // 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
1171 // 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
1172 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
1173 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
1174 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
1175 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1176 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1177 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1178 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1179 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
1180 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
1181 continue;
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1182 }
51228
61a6ef876efd rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51227
diff changeset
1183 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
1184 if poison {
e553cd209215 rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51226
diff changeset
1185 // 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
1186 // 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
1187 // 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
1188 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
1189 interesting -= 1;
e553cd209215 rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51226
diff changeset
1190 }
51228
61a6ef876efd rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51227
diff changeset
1191 parent_seen.poison();
51227
e553cd209215 rust-index: avoid double negation in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51226
diff changeset
1192 } else {
51224
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1193 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
1194 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
1195 }
51228
61a6ef876efd rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51227
diff changeset
1196 parent_seen.union(&current_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
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 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1199
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1200 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
1201 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1202
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1203 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
1204 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1205
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1206 /// 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
1207 /// 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
1208 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
1209 &self,
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1210 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
1211 ) -> 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
1212 // 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
1213 // 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
1214 // 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
1215 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
1216 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
1217 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1218 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
1219 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
1220 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
1221 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
1222 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
1223 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
1224 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
1225
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1226 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
1227 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
1228 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
1229 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
1230 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
1231 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
1232 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1233
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1234 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
1235 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
1236 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
1237 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
1238 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
1239 continue;
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1240 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1241
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1242 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
1243 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
1244 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
1245 continue;
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1246 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1247 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
1248 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
1249 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
1250 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
1251 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
1252 *interesting.get_mut(&current_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
1253 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
1254 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
1255 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
1256 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
1257 *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
1258 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
1259 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
1260 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1261 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1262 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1263 } 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
1264 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
1265 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
1266 continue;
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1267 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1268 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
1269 interesting
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1270 .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
1271 .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
1272 .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
1273 *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
1274 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
1275 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
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 *interesting.get_mut(&current_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
1280 if interesting[&current_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
1281 interesting.remove(&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
1282 }
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 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
1285 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1286
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1287 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
1288 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
1289 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1290 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
1291
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1292 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
1293 .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
1294 .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
1295 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
1296 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
1297 }
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1298 None
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1299 })
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1300 .collect())
42c8dbdb88ad rust-index: core impl for find_gca_candidates and find_deepest
Raphaël Gomès <rgomes@octobus.net>
parents: 51222
diff changeset
1301 }
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1302 }
51220
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1303
51224
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1304 /// 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
1305 ///
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1306 /// 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
1307 /// 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
1308 ///
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1309 /// 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
1310 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
1311 /// 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
1312 ///
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1313 /// 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
1314 /// 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
1315 /// implementation.
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1316 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
1317
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1318 /// The size of the bit mask in memory
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1319 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
1320
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1321 /// 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
1322 ///
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1323 /// 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
1324 /// 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
1325 /// `[0, C)`
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1326 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
1327
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1328 /// 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
1329 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
1330
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1331 /// Declare `n` not 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
1332 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
1333
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1334 /// 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
1335 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
1336
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1337 /// 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
1338 ///
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1339 /// 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
1340 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
1341
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1342 /// 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
1343 ///
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1344 /// 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
1345 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
1346
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1347 /// 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
1348 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
1349
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1350 /// 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
1351 /// of integers
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1352 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
1353 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1354
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1355 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
1356 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
1357
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1358 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
1359 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
1360 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
1361 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1362
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1363 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
1364 8
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1365 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1366
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1367 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
1368 63
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1369 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1370
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1371 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
1372 (*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
1373 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1374
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1375 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
1376 (*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
1377 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1378
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1379 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
1380 if *self != *other {
61a6ef876efd rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51227
diff changeset
1381 (*self) |= *other;
61a6ef876efd rust-index: simplification in find_gca_candidates()
Georges Racinet <georges.racinet@octobus.net>
parents: 51227
diff changeset
1382 }
51224
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1383 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1384
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1385 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
1386 *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
1387 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1388
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1389 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
1390 *self == 0
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1391 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1392
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1393 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
1394 *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
1395 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1396
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1397 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
1398 // 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
1399 // 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
1400 *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
1401 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1402 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1403
51229
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1404 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
1405 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
1406 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
1407 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1408
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1409 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
1410 1
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1411 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1412
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1413 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
1414 7
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1415 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1416
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1417 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
1418 (*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
1419 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1420
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1421 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
1422 (*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
1423 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1424
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1425 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
1426 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
1427 (*self) |= *other;
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1428 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1429 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1430
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1431 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
1432 *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
1433 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1434
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1435 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
1436 *self == 0
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1437 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1438
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1439 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
1440 *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
1441 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1442
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1443 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
1444 // 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
1445 // 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
1446 *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
1447 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1448 }
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51228
diff changeset
1449
51224
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1450 /// 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
1451 /// 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
1452 ///
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1453 /// 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
1454 /// 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
1455 /// 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
1456 /// 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
1457 /// 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
1458 #[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
1459 struct NonStaticPoisonableBitSet {
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1460 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
1461 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
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 /// 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
1465 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
1466 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
1467 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1468
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1469 impl NonStaticPoisonableBitSet {
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1470 /// 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
1471 /// the latter
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1472 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
1473 (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
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
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1477 /// 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
1478 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
1479 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
1480 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
1481 set_size,
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1482 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
1483 };
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1484 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
1485 }
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 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
1488 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
1489 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1490
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1491 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
1492 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
1493 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1494
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1495 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
1496 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
1497 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
1498 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1499
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1500 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
1501 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
1502 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
1503 }
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 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
1506 assert!(
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1507 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
1508 "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
1509 );
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1510 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
1511 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
1512 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1513 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1514
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1515 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
1516 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
1517 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
1518 && 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
1519 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1520
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1521 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
1522 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
1523 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1524
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1525 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
1526 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
1527 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
1528 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1529
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1530 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
1531 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
1532 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
1533 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1534 }
43241f31cf5b rust-index: find_gca_candidates bit sets genericization
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51223
diff changeset
1535
51220
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1536 /// Set of roots of all non-public phases
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1537 pub type RootsPerPhase = [HashSet<Revision>; Phase::non_public_phases().len()];
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1538
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1539 #[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
1540 pub enum Phase {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1541 Public = 0,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1542 Draft = 1,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1543 Secret = 2,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1544 Archived = 3,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1545 Internal = 4,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1546 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1547
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1548 impl TryFrom<usize> for Phase {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1549 type Error = RevlogError;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1550
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1551 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
1552 Ok(match value {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1553 0 => Self::Public,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1554 1 => Self::Draft,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1555 2 => Self::Secret,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1556 32 => Self::Archived,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1557 96 => Self::Internal,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1558 v => {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1559 return Err(RevlogError::corrupted(format!(
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1560 "invalid phase value {}",
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1561 v
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1562 )))
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1563 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1564 })
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1565 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1566 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1567
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1568 impl Phase {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1569 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
1570 &[
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1571 Self::Public,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1572 Self::Draft,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1573 Self::Secret,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1574 Self::Archived,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1575 Self::Internal,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1576 ]
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1577 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1578 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
1579 &[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
1580 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1581 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Raphaël Gomès <rgomes@octobus.net>
parents: 51218
diff changeset
1582
51197
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1583 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
1584 let mut offset: usize = 0;
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1585 let mut offsets = Vec::new();
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1586
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1587 while offset + INDEX_ENTRY_SIZE <= bytes.len() {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1588 offsets.push(offset);
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1589 let end = offset + INDEX_ENTRY_SIZE;
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1590 let entry = IndexEntry {
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1591 bytes: &bytes[offset..end],
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1592 offset_override: None,
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1593 };
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1594
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1595 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
1596 }
4e6620b7fbbb rust-index: support cache clearing
Raphaël Gomès <rgomes@octobus.net>
parents: 51195
diff changeset
1597 (offset, offsets)
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1598 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1599
46090
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1600 impl super::RevlogIndex for Index {
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1601 fn len(&self) -> usize {
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1602 self.len()
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1603 }
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1604
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1605 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
1606 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
1607 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
1608 }
46090
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1609 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
1610 }
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1611 }
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1612
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1613 #[derive(Debug)]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1614 pub struct IndexEntry<'a> {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1615 bytes: &'a [u8],
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1616 /// Allows to override the offset value of the entry.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1617 ///
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1618 /// For interleaved index and data, the offset stored in the index
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1619 /// corresponds to the separated data offset.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1620 /// It has to be overridden with the actual offset in the interleaved
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1621 /// index which is just after the index block.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1622 ///
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1623 /// For separated index and data, the offset stored in the first index
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1624 /// entry is mixed with the index headers.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1625 /// It has to be overridden with 0.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1626 offset_override: Option<usize>,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1627 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1628
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1629 impl<'a> IndexEntry<'a> {
45593
da30e4b553c3 hg-core: minor docstring update (D8958#inline-14991 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45592
diff changeset
1630 /// 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
1631 pub fn offset(&self) -> usize {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1632 if let Some(offset_override) = self.offset_override {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1633 offset_override
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1634 } else {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1635 let mut bytes = [0; 8];
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1636 bytes[2..8].copy_from_slice(&self.bytes[0..=5]);
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1637 BigEndian::read_u64(&bytes[..]) as usize
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1638 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1639 }
51205
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
1640 pub fn raw_offset(&self) -> u64 {
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
1641 BigEndian::read_u64(&self.bytes[0..8])
002b49905aac rust-index: implementation of __getitem__
Raphaël Gomès <rgomes@octobus.net>
parents: 51203
diff changeset
1642 }
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1643
51218
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
1644 /// Same result (except potentially for rev 0) as C `index_get_start()`
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
1645 fn c_start(&self) -> u64 {
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
1646 self.raw_offset() >> 16
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
1647 }
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Raphaël Gomès <rgomes@octobus.net>
parents: 51216
diff changeset
1648
48546
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48543
diff changeset
1649 pub fn flags(&self) -> u16 {
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48543
diff changeset
1650 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
1651 }
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48543
diff changeset
1652
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1653 /// 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
1654 pub fn compressed_len(&self) -> u32 {
0a4ac916673e rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents: 48458
diff changeset
1655 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
1656 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1657
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1658 /// 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
1659 pub fn uncompressed_len(&self) -> i32 {
0a4ac916673e rhg: RevlogEntry::uncompressed_len is signed
Simon Sapin <simon.sapin@octobus.net>
parents: 48458
diff changeset
1660 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
1661 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1662
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1663 /// 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
1664 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
1665 // 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
1666 // 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
1667
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1668 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
1669 }
45531
b0d6309ff50c hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45526
diff changeset
1670
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1671 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
1672 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
1673 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1674
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1675 pub fn p1(&self) -> UncheckedRevision {
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1676 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
1677 }
b0d6309ff50c hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45526
diff changeset
1678
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1679 pub fn p2(&self) -> UncheckedRevision {
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1680 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
1681 }
b0d6309ff50c hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45526
diff changeset
1682
b0d6309ff50c hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45526
diff changeset
1683 /// 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
1684 ///
b0d6309ff50c hg-core: check data integrity in `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45526
diff changeset
1685 /// 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
1686 /// are used.
46090
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 46033
diff changeset
1687 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
1688 (&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
1689 }
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
1690
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
1691 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
1692 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
1693 }
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1694 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1695
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1696 #[cfg(test)]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1697 mod tests {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1698 use super::*;
49093
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1699 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
1700
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1701 #[cfg(test)]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1702 #[derive(Debug, Copy, Clone)]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1703 pub struct IndexEntryBuilder {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1704 is_first: bool,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1705 is_inline: bool,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1706 is_general_delta: bool,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1707 version: u16,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1708 offset: usize,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1709 compressed_len: usize,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1710 uncompressed_len: usize,
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
1711 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
1712 link_revision: Revision,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1713 p1: Revision,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1714 p2: Revision,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1715 node: Node,
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1716 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1717
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1718 #[cfg(test)]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1719 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
1720 #[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
1721 pub fn new() -> Self {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1722 Self {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1723 is_first: false,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1724 is_inline: false,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1725 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
1726 version: 1,
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1727 offset: 0,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1728 compressed_len: 0,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1729 uncompressed_len: 0,
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1730 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
1731 link_revision: Revision(0),
49093
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1732 p1: NULL_REVISION,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1733 p2: NULL_REVISION,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1734 node: NULL_NODE,
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1735 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1736 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1737
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1738 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
1739 self.is_first = value;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1740 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1741 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1742
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1743 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
1744 self.is_inline = value;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1745 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1746 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1747
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1748 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
1749 self.is_general_delta = value;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1750 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1751 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1752
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1753 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
1754 self.version = value;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1755 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1756 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1757
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1758 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
1759 self.offset = value;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1760 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1761 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1762
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1763 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
1764 self.compressed_len = value;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1765 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1766 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1767
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1768 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
1769 self.uncompressed_len = value;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1770 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1771 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1772
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
1773 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
1774 &mut self,
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
1775 value: Revision,
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
1776 ) -> &mut Self {
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
1777 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
1778 self
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1779 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1780
49093
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1781 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
1782 self.link_revision = value;
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1783 self
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1784 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1785
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1786 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
1787 self.p1 = value;
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1788 self
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1789 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1790
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1791 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
1792 self.p2 = value;
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1793 self
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1794 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1795
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1796 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
1797 self.node = value;
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1798 self
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1799 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1800
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1801 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
1802 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
1803 if self.is_first {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1804 bytes.extend(&match (self.is_general_delta, self.is_inline) {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1805 (false, false) => [0u8, 0],
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1806 (false, true) => [0u8, 1],
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1807 (true, false) => [0u8, 2],
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1808 (true, true) => [0u8, 3],
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1809 });
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1810 bytes.extend(&self.version.to_be_bytes());
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1811 // Remaining offset bytes.
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1812 bytes.extend(&[0u8; 2]);
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1813 } else {
46887
6d5a26e94d9e unit-tests: Fix `cargo test` on 32-bit platforms
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
1814 // 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
1815 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
1816 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1817 bytes.extend(&[0u8; 2]); // Revision flags.
46887
6d5a26e94d9e unit-tests: Fix `cargo test` on 32-bit platforms
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
1818 bytes.extend(&(self.compressed_len as u32).to_be_bytes());
6d5a26e94d9e unit-tests: Fix `cargo test` on 32-bit platforms
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
1819 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
1820 bytes.extend(
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1821 &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
1822 );
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1823 bytes.extend(&self.link_revision.0.to_be_bytes());
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1824 bytes.extend(&self.p1.0.to_be_bytes());
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1825 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
1826 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
1827 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
1828 bytes
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1829 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1830 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1831
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1832 pub fn is_inline(index_bytes: &[u8]) -> bool {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1833 IndexHeader::parse(index_bytes)
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1834 .expect("too short")
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
1835 .unwrap()
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1836 .format_flags()
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1837 .is_inline()
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1838 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1839
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1840 pub fn uses_generaldelta(index_bytes: &[u8]) -> bool {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1841 IndexHeader::parse(index_bytes)
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1842 .expect("too short")
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
1843 .unwrap()
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1844 .format_flags()
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1845 .uses_generaldelta()
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1846 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1847
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1848 pub fn get_version(index_bytes: &[u8]) -> u16 {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1849 IndexHeader::parse(index_bytes)
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1850 .expect("too short")
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
1851 .unwrap()
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1852 .format_version()
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1853 }
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1854
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1855 #[test]
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1856 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
1857 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
1858 .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
1859 .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
1860 .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
1861 .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
1862
49930
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
1863 assert!(!is_inline(&bytes));
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
1864 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
1865 }
900b9b79b99c hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45593
diff changeset
1866
900b9b79b99c hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45593
diff changeset
1867 #[test]
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1868 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
1869 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
1870 .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
1871 .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
1872 .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
1873 .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
1874
49930
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
1875 assert!(is_inline(&bytes));
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
1876 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
1877 }
900b9b79b99c hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45593
diff changeset
1878
900b9b79b99c hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45593
diff changeset
1879 #[test]
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1880 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
1881 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
1882 .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
1883 .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
1884 .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
1885 .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
1886
49930
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
1887 assert!(is_inline(&bytes));
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Raphaël Gomès <rgomes@octobus.net>
parents: 49926
diff changeset
1888 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
1889 }
900b9b79b99c hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45593
diff changeset
1890
900b9b79b99c hg-core: make `Index` owner of its bytes (D8958#inline-14994 followup 1/2)
Antoine cezar<acezar@chwitlabs.fr>
parents: 45593
diff changeset
1891 #[test]
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1892 fn test_offset() {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1893 let bytes = IndexEntryBuilder::new().with_offset(1).build();
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1894 let entry = IndexEntry {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1895 bytes: &bytes,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1896 offset_override: None,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1897 };
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1898
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1899 assert_eq!(entry.offset(), 1)
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1900 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1901
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1902 #[test]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1903 fn test_with_overridden_offset() {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1904 let bytes = IndexEntryBuilder::new().with_offset(1).build();
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1905 let entry = IndexEntry {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1906 bytes: &bytes,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1907 offset_override: Some(2),
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1908 };
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1909
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1910 assert_eq!(entry.offset(), 2)
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1911 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1912
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1913 #[test]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1914 fn test_compressed_len() {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1915 let bytes = IndexEntryBuilder::new().with_compressed_len(1).build();
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1916 let entry = IndexEntry {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1917 bytes: &bytes,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1918 offset_override: None,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1919 };
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 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
1922 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1923
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1924 #[test]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1925 fn test_uncompressed_len() {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1926 let bytes = IndexEntryBuilder::new().with_uncompressed_len(1).build();
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1927 let entry = IndexEntry {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1928 bytes: &bytes,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1929 offset_override: None,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1930 };
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1931
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1932 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
1933 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1934
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1935 #[test]
48458
96ea4db4741b rhg: fix a crash on non-generaldelta revlogs
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48457
diff changeset
1936 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
1937 let bytes = IndexEntryBuilder::new()
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1938 .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
1939 .build();
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1940 let entry = IndexEntry {
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1941 bytes: &bytes,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1942 offset_override: None,
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1943 };
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
1944
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1945 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
1946 }
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1947
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
1948 #[test]
49093
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1949 fn link_revision_test() {
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1950 let bytes = IndexEntryBuilder::new()
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1951 .with_link_revision(Revision(123))
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1952 .build();
49093
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1953
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1954 let entry = IndexEntry {
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1955 bytes: &bytes,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1956 offset_override: None,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1957 };
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1958
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1959 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
1960 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1961
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1962 #[test]
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1963 fn p1_test() {
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1964 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
1965
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1966 let entry = IndexEntry {
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1967 bytes: &bytes,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1968 offset_override: None,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1969 };
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1970
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1971 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
1972 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1973
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1974 #[test]
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1975 fn p2_test() {
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 50978
diff changeset
1976 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
1977
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1978 let entry = IndexEntry {
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1979 bytes: &bytes,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1980 offset_override: None,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1981 };
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1982
50977
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents: 49930
diff changeset
1983 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
1984 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1985
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1986 #[test]
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1987 fn node_test() {
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1988 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
1989 .unwrap();
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1990 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
1991
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1992 let entry = IndexEntry {
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1993 bytes: &bytes,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1994 offset_override: None,
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1995 };
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1996
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1997 assert_eq!(*entry.hash(), node);
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1998 }
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
1999
2a9a55ffe24f rust-revlog: make `IndexEntryBuilder` build a whole entry
Martin von Zweigbergk <martinvonz@google.com>
parents: 49092
diff changeset
2000 #[test]
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
2001 fn version_test() {
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
2002 let bytes = IndexEntryBuilder::new()
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
2003 .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
2004 .with_version(2)
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
2005 .build();
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
2006
49092
d200ecb76c72 rust-revlog: change default version from 2 to 1 in test builder
Martin von Zweigbergk <martinvonz@google.com>
parents: 48546
diff changeset
2007 assert_eq!(get_version(&bytes), 2)
48457
1fb3615dfce2 rhg: centralize index header parsing
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48226
diff changeset
2008 }
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
2009 }
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
2010
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
2011 #[cfg(test)]
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
2012 pub use tests::IndexEntryBuilder;