##// END OF EJS Templates
rust-node: binary Node ID and conversion utilities...
Georges Racinet -
r44601:7f86426f default
parent child Browse files
Show More
@@ -0,0 +1,191 b''
1 // Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
2 //
3 // This software may be used and distributed according to the terms of the
4 // GNU General Public License version 2 or any later version.
5
6 //! Definitions and utilities for Revision nodes
7 //!
8 //! In Mercurial code base, it is customary to call "a node" the binary SHA
9 //! of a revision.
10
11 use hex::{self, FromHex, FromHexError};
12
13 /// The length in bytes of a `Node`
14 ///
15 /// This constant is meant to ease refactors of this module, and
16 /// are private so that calling code does not expect all nodes have
17 /// the same size, should we support several formats concurrently in
18 /// the future.
19 const NODE_BYTES_LENGTH: usize = 20;
20
21 /// The length in bytes of a `Node`
22 ///
23 /// see also `NODES_BYTES_LENGTH` about it being private.
24 const NODE_NYBBLES_LENGTH: usize = 2 * NODE_BYTES_LENGTH;
25
26 /// Private alias for readability and to ease future change
27 type NodeData = [u8; NODE_BYTES_LENGTH];
28
29 /// Binary revision SHA
30 ///
31 /// ## Future changes of hash size
32 ///
33 /// To accomodate future changes of hash size, Rust callers
34 /// should use the conversion methods at the boundaries (FFI, actual
35 /// computation of hashes and I/O) only, and only if required.
36 ///
37 /// All other callers outside of unit tests should just handle `Node` values
38 /// and never make any assumption on the actual length, using [`nybbles_len`]
39 /// if they need a loop boundary.
40 ///
41 /// All methods that create a `Node` either take a type that enforces
42 /// the size or fail immediately at runtime with [`ExactLengthRequired`].
43 ///
44 /// [`nybbles_len`]: #method.nybbles_len
45 /// [`ExactLengthRequired`]: struct.NodeError#variant.ExactLengthRequired
46 #[derive(Clone, Debug, PartialEq)]
47 pub struct Node {
48 data: NodeData,
49 }
50
51 /// The node value for NULL_REVISION
52 pub const NULL_NODE: Node = Node {
53 data: [0; NODE_BYTES_LENGTH],
54 };
55
56 impl From<NodeData> for Node {
57 fn from(data: NodeData) -> Node {
58 Node { data }
59 }
60 }
61
62 #[derive(Debug, PartialEq)]
63 pub enum NodeError {
64 ExactLengthRequired(usize, String),
65 HexError(FromHexError, String),
66 }
67
68 /// Low level utility function, also for prefixes
69 fn get_nybble(s: &[u8], i: usize) -> u8 {
70 if i % 2 == 0 {
71 s[i / 2] >> 4
72 } else {
73 s[i / 2] & 0x0f
74 }
75 }
76
77 impl Node {
78 /// Retrieve the `i`th half-byte of the binary data.
79 ///
80 /// This is also the `i`th hexadecimal digit in numeric form,
81 /// also called a [nybble](https://en.wikipedia.org/wiki/Nibble).
82 pub fn get_nybble(&self, i: usize) -> u8 {
83 get_nybble(&self.data, i)
84 }
85
86 /// Length of the data, in nybbles
87 pub fn nybbles_len(&self) -> usize {
88 // public exposure as an instance method only, so that we can
89 // easily support several sizes of hashes if needed in the future.
90 NODE_NYBBLES_LENGTH
91 }
92
93 /// Convert from hexadecimal string representation
94 ///
95 /// Exact length is required.
96 ///
97 /// To be used in FFI and I/O only, in order to facilitate future
98 /// changes of hash format.
99 pub fn from_hex(hex: &str) -> Result<Node, NodeError> {
100 Ok(NodeData::from_hex(hex)
101 .map_err(|e| NodeError::from((e, hex)))?
102 .into())
103 }
104
105 /// Convert to hexadecimal string representation
106 ///
107 /// To be used in FFI and I/O only, in order to facilitate future
108 /// changes of hash format.
109 pub fn encode_hex(&self) -> String {
110 hex::encode(self.data)
111 }
112
113 /// Provide access to binary data
114 ///
115 /// This is needed by FFI layers, for instance to return expected
116 /// binary values to Python.
117 pub fn as_bytes(&self) -> &[u8] {
118 &self.data
119 }
120 }
121
122 impl From<(FromHexError, &str)> for NodeError {
123 fn from(err_offender: (FromHexError, &str)) -> Self {
124 let (err, offender) = err_offender;
125 match err {
126 FromHexError::InvalidStringLength => {
127 NodeError::ExactLengthRequired(
128 NODE_NYBBLES_LENGTH,
129 offender.to_string(),
130 )
131 }
132 _ => NodeError::HexError(err, offender.to_string()),
133 }
134 }
135 }
136
137 #[cfg(test)]
138 mod tests {
139 use super::*;
140
141 fn sample_node() -> Node {
142 let mut data = [0; NODE_BYTES_LENGTH];
143 data.copy_from_slice(&[
144 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba,
145 0x98, 0x76, 0x54, 0x32, 0x10, 0xde, 0xad, 0xbe, 0xef,
146 ]);
147 data.into()
148 }
149
150 /// Pad an hexadecimal string to reach `NODE_NYBBLES_LENGTH`
151 ///
152 /// The padding is made with zeros
153 fn hex_pad_right(hex: &str) -> String {
154 let mut res = hex.to_string();
155 while res.len() < NODE_NYBBLES_LENGTH {
156 res.push('0');
157 }
158 res
159 }
160
161 fn sample_node_hex() -> String {
162 hex_pad_right("0123456789abcdeffedcba9876543210deadbeef")
163 }
164
165 #[test]
166 fn test_node_from_hex() {
167 assert_eq!(Node::from_hex(&sample_node_hex()), Ok(sample_node()));
168
169 let mut short = hex_pad_right("0123");
170 short.pop();
171 short.pop();
172 assert_eq!(
173 Node::from_hex(&short),
174 Err(NodeError::ExactLengthRequired(NODE_NYBBLES_LENGTH, short)),
175 );
176
177 let not_hex = hex_pad_right("012... oops");
178 assert_eq!(
179 Node::from_hex(&not_hex),
180 Err(NodeError::HexError(
181 FromHexError::InvalidHexCharacter { c: '.', index: 3 },
182 not_hex,
183 )),
184 );
185 }
186
187 #[test]
188 fn test_node_encode_hex() {
189 assert_eq!(sample_node().encode_hex(), sample_node_hex());
190 }
191 }
@@ -1,524 +1,531 b''
1 1 # This file is automatically @generated by Cargo.
2 2 # It is not intended for manual editing.
3 3 [[package]]
4 4 name = "aho-corasick"
5 5 version = "0.7.6"
6 6 source = "registry+https://github.com/rust-lang/crates.io-index"
7 7 dependencies = [
8 8 "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
9 9 ]
10 10
11 11 [[package]]
12 12 name = "arrayvec"
13 13 version = "0.4.12"
14 14 source = "registry+https://github.com/rust-lang/crates.io-index"
15 15 dependencies = [
16 16 "nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
17 17 ]
18 18
19 19 [[package]]
20 20 name = "autocfg"
21 21 version = "0.1.6"
22 22 source = "registry+https://github.com/rust-lang/crates.io-index"
23 23
24 24 [[package]]
25 25 name = "bitflags"
26 26 version = "1.2.1"
27 27 source = "registry+https://github.com/rust-lang/crates.io-index"
28 28
29 29 [[package]]
30 30 name = "byteorder"
31 31 version = "1.3.2"
32 32 source = "registry+https://github.com/rust-lang/crates.io-index"
33 33
34 34 [[package]]
35 35 name = "c2-chacha"
36 36 version = "0.2.2"
37 37 source = "registry+https://github.com/rust-lang/crates.io-index"
38 38 dependencies = [
39 39 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
40 40 "ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
41 41 ]
42 42
43 43 [[package]]
44 44 name = "cfg-if"
45 45 version = "0.1.10"
46 46 source = "registry+https://github.com/rust-lang/crates.io-index"
47 47
48 48 [[package]]
49 49 name = "cloudabi"
50 50 version = "0.0.3"
51 51 source = "registry+https://github.com/rust-lang/crates.io-index"
52 52 dependencies = [
53 53 "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
54 54 ]
55 55
56 56 [[package]]
57 57 name = "cpython"
58 58 version = "0.3.0"
59 59 source = "registry+https://github.com/rust-lang/crates.io-index"
60 60 dependencies = [
61 61 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
62 62 "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
63 63 "python27-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
64 64 "python3-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
65 65 ]
66 66
67 67 [[package]]
68 68 name = "crossbeam-deque"
69 69 version = "0.7.1"
70 70 source = "registry+https://github.com/rust-lang/crates.io-index"
71 71 dependencies = [
72 72 "crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
73 73 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
74 74 ]
75 75
76 76 [[package]]
77 77 name = "crossbeam-epoch"
78 78 version = "0.7.2"
79 79 source = "registry+https://github.com/rust-lang/crates.io-index"
80 80 dependencies = [
81 81 "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
82 82 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
83 83 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
84 84 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
85 85 "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
86 86 "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
87 87 ]
88 88
89 89 [[package]]
90 90 name = "crossbeam-queue"
91 91 version = "0.1.2"
92 92 source = "registry+https://github.com/rust-lang/crates.io-index"
93 93 dependencies = [
94 94 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
95 95 ]
96 96
97 97 [[package]]
98 98 name = "crossbeam-utils"
99 99 version = "0.6.6"
100 100 source = "registry+https://github.com/rust-lang/crates.io-index"
101 101 dependencies = [
102 102 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
103 103 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
104 104 ]
105 105
106 106 [[package]]
107 107 name = "either"
108 108 version = "1.5.3"
109 109 source = "registry+https://github.com/rust-lang/crates.io-index"
110 110
111 111 [[package]]
112 112 name = "fuchsia-cprng"
113 113 version = "0.1.1"
114 114 source = "registry+https://github.com/rust-lang/crates.io-index"
115 115
116 116 [[package]]
117 117 name = "getrandom"
118 118 version = "0.1.12"
119 119 source = "registry+https://github.com/rust-lang/crates.io-index"
120 120 dependencies = [
121 121 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
122 122 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
123 123 "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
124 124 ]
125 125
126 126 [[package]]
127 name = "hex"
128 version = "0.4.0"
129 source = "registry+https://github.com/rust-lang/crates.io-index"
130
131 [[package]]
127 132 name = "hg-core"
128 133 version = "0.1.0"
129 134 dependencies = [
130 135 "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
136 "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
131 137 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
132 138 "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
133 139 "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
134 140 "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
135 141 "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
136 142 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
137 143 "twox-hash 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
138 144 ]
139 145
140 146 [[package]]
141 147 name = "hg-cpython"
142 148 version = "0.1.0"
143 149 dependencies = [
144 150 "cpython 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
145 151 "hg-core 0.1.0",
146 152 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
147 153 ]
148 154
149 155 [[package]]
150 156 name = "hgdirectffi"
151 157 version = "0.1.0"
152 158 dependencies = [
153 159 "hg-core 0.1.0",
154 160 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
155 161 ]
156 162
157 163 [[package]]
158 164 name = "lazy_static"
159 165 version = "1.4.0"
160 166 source = "registry+https://github.com/rust-lang/crates.io-index"
161 167
162 168 [[package]]
163 169 name = "libc"
164 170 version = "0.2.64"
165 171 source = "registry+https://github.com/rust-lang/crates.io-index"
166 172
167 173 [[package]]
168 174 name = "memchr"
169 175 version = "2.2.1"
170 176 source = "registry+https://github.com/rust-lang/crates.io-index"
171 177
172 178 [[package]]
173 179 name = "memoffset"
174 180 version = "0.5.1"
175 181 source = "registry+https://github.com/rust-lang/crates.io-index"
176 182 dependencies = [
177 183 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
178 184 ]
179 185
180 186 [[package]]
181 187 name = "nodrop"
182 188 version = "0.1.14"
183 189 source = "registry+https://github.com/rust-lang/crates.io-index"
184 190
185 191 [[package]]
186 192 name = "num-traits"
187 193 version = "0.2.8"
188 194 source = "registry+https://github.com/rust-lang/crates.io-index"
189 195 dependencies = [
190 196 "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
191 197 ]
192 198
193 199 [[package]]
194 200 name = "num_cpus"
195 201 version = "1.10.1"
196 202 source = "registry+https://github.com/rust-lang/crates.io-index"
197 203 dependencies = [
198 204 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
199 205 ]
200 206
201 207 [[package]]
202 208 name = "ppv-lite86"
203 209 version = "0.2.5"
204 210 source = "registry+https://github.com/rust-lang/crates.io-index"
205 211
206 212 [[package]]
207 213 name = "python27-sys"
208 214 version = "0.3.0"
209 215 source = "registry+https://github.com/rust-lang/crates.io-index"
210 216 dependencies = [
211 217 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
212 218 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
213 219 ]
214 220
215 221 [[package]]
216 222 name = "python3-sys"
217 223 version = "0.3.0"
218 224 source = "registry+https://github.com/rust-lang/crates.io-index"
219 225 dependencies = [
220 226 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
221 227 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
222 228 ]
223 229
224 230 [[package]]
225 231 name = "rand"
226 232 version = "0.6.5"
227 233 source = "registry+https://github.com/rust-lang/crates.io-index"
228 234 dependencies = [
229 235 "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
230 236 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
231 237 "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
232 238 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
233 239 "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
234 240 "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
235 241 "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
236 242 "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
237 243 "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
238 244 "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
239 245 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
240 246 ]
241 247
242 248 [[package]]
243 249 name = "rand"
244 250 version = "0.7.2"
245 251 source = "registry+https://github.com/rust-lang/crates.io-index"
246 252 dependencies = [
247 253 "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
248 254 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
249 255 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
250 256 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
251 257 "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
252 258 ]
253 259
254 260 [[package]]
255 261 name = "rand_chacha"
256 262 version = "0.1.1"
257 263 source = "registry+https://github.com/rust-lang/crates.io-index"
258 264 dependencies = [
259 265 "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
260 266 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
261 267 ]
262 268
263 269 [[package]]
264 270 name = "rand_chacha"
265 271 version = "0.2.1"
266 272 source = "registry+https://github.com/rust-lang/crates.io-index"
267 273 dependencies = [
268 274 "c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
269 275 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
270 276 ]
271 277
272 278 [[package]]
273 279 name = "rand_core"
274 280 version = "0.3.1"
275 281 source = "registry+https://github.com/rust-lang/crates.io-index"
276 282 dependencies = [
277 283 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
278 284 ]
279 285
280 286 [[package]]
281 287 name = "rand_core"
282 288 version = "0.4.2"
283 289 source = "registry+https://github.com/rust-lang/crates.io-index"
284 290
285 291 [[package]]
286 292 name = "rand_core"
287 293 version = "0.5.1"
288 294 source = "registry+https://github.com/rust-lang/crates.io-index"
289 295 dependencies = [
290 296 "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
291 297 ]
292 298
293 299 [[package]]
294 300 name = "rand_hc"
295 301 version = "0.1.0"
296 302 source = "registry+https://github.com/rust-lang/crates.io-index"
297 303 dependencies = [
298 304 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
299 305 ]
300 306
301 307 [[package]]
302 308 name = "rand_hc"
303 309 version = "0.2.0"
304 310 source = "registry+https://github.com/rust-lang/crates.io-index"
305 311 dependencies = [
306 312 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
307 313 ]
308 314
309 315 [[package]]
310 316 name = "rand_isaac"
311 317 version = "0.1.1"
312 318 source = "registry+https://github.com/rust-lang/crates.io-index"
313 319 dependencies = [
314 320 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
315 321 ]
316 322
317 323 [[package]]
318 324 name = "rand_jitter"
319 325 version = "0.1.4"
320 326 source = "registry+https://github.com/rust-lang/crates.io-index"
321 327 dependencies = [
322 328 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
323 329 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
324 330 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
325 331 ]
326 332
327 333 [[package]]
328 334 name = "rand_os"
329 335 version = "0.1.3"
330 336 source = "registry+https://github.com/rust-lang/crates.io-index"
331 337 dependencies = [
332 338 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
333 339 "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
334 340 "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)",
335 341 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
336 342 "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
337 343 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
338 344 ]
339 345
340 346 [[package]]
341 347 name = "rand_pcg"
342 348 version = "0.1.2"
343 349 source = "registry+https://github.com/rust-lang/crates.io-index"
344 350 dependencies = [
345 351 "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
346 352 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
347 353 ]
348 354
349 355 [[package]]
350 356 name = "rand_xorshift"
351 357 version = "0.1.1"
352 358 source = "registry+https://github.com/rust-lang/crates.io-index"
353 359 dependencies = [
354 360 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
355 361 ]
356 362
357 363 [[package]]
358 364 name = "rayon"
359 365 version = "1.2.0"
360 366 source = "registry+https://github.com/rust-lang/crates.io-index"
361 367 dependencies = [
362 368 "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
363 369 "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
364 370 "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
365 371 ]
366 372
367 373 [[package]]
368 374 name = "rayon-core"
369 375 version = "1.6.0"
370 376 source = "registry+https://github.com/rust-lang/crates.io-index"
371 377 dependencies = [
372 378 "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
373 379 "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
374 380 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
375 381 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
376 382 "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
377 383 ]
378 384
379 385 [[package]]
380 386 name = "rdrand"
381 387 version = "0.4.0"
382 388 source = "registry+https://github.com/rust-lang/crates.io-index"
383 389 dependencies = [
384 390 "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
385 391 ]
386 392
387 393 [[package]]
388 394 name = "regex"
389 395 version = "1.3.1"
390 396 source = "registry+https://github.com/rust-lang/crates.io-index"
391 397 dependencies = [
392 398 "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
393 399 "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
394 400 "regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
395 401 "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
396 402 ]
397 403
398 404 [[package]]
399 405 name = "regex-syntax"
400 406 version = "0.6.12"
401 407 source = "registry+https://github.com/rust-lang/crates.io-index"
402 408
403 409 [[package]]
404 410 name = "rustc_version"
405 411 version = "0.2.3"
406 412 source = "registry+https://github.com/rust-lang/crates.io-index"
407 413 dependencies = [
408 414 "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
409 415 ]
410 416
411 417 [[package]]
412 418 name = "scopeguard"
413 419 version = "1.0.0"
414 420 source = "registry+https://github.com/rust-lang/crates.io-index"
415 421
416 422 [[package]]
417 423 name = "semver"
418 424 version = "0.9.0"
419 425 source = "registry+https://github.com/rust-lang/crates.io-index"
420 426 dependencies = [
421 427 "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
422 428 ]
423 429
424 430 [[package]]
425 431 name = "semver-parser"
426 432 version = "0.7.0"
427 433 source = "registry+https://github.com/rust-lang/crates.io-index"
428 434
429 435 [[package]]
430 436 name = "thread_local"
431 437 version = "0.3.6"
432 438 source = "registry+https://github.com/rust-lang/crates.io-index"
433 439 dependencies = [
434 440 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
435 441 ]
436 442
437 443 [[package]]
438 444 name = "twox-hash"
439 445 version = "1.5.0"
440 446 source = "registry+https://github.com/rust-lang/crates.io-index"
441 447 dependencies = [
442 448 "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
443 449 ]
444 450
445 451 [[package]]
446 452 name = "wasi"
447 453 version = "0.7.0"
448 454 source = "registry+https://github.com/rust-lang/crates.io-index"
449 455
450 456 [[package]]
451 457 name = "winapi"
452 458 version = "0.3.8"
453 459 source = "registry+https://github.com/rust-lang/crates.io-index"
454 460 dependencies = [
455 461 "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
456 462 "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
457 463 ]
458 464
459 465 [[package]]
460 466 name = "winapi-i686-pc-windows-gnu"
461 467 version = "0.4.0"
462 468 source = "registry+https://github.com/rust-lang/crates.io-index"
463 469
464 470 [[package]]
465 471 name = "winapi-x86_64-pc-windows-gnu"
466 472 version = "0.4.0"
467 473 source = "registry+https://github.com/rust-lang/crates.io-index"
468 474
469 475 [metadata]
470 476 "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
471 477 "checksum arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9"
472 478 "checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875"
473 479 "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
474 480 "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
475 481 "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
476 482 "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
477 483 "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
478 484 "checksum cpython 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85532c648315aeb0829ad216a6a29aa3212cf9319bc7f6daf1404aa0bdd1485f"
479 485 "checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71"
480 486 "checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9"
481 487 "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
482 488 "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
483 489 "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
484 490 "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
485 491 "checksum getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "473a1265acc8ff1e808cd0a1af8cee3c2ee5200916058a2ca113c29f2d903571"
492 "checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e"
486 493 "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
487 494 "checksum libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)" = "74dfca3d9957906e8d1e6a0b641dc9a59848e793f1da2165889fd4f62d10d79c"
488 495 "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
489 496 "checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f"
490 497 "checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
491 498 "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
492 499 "checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
493 500 "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b"
494 501 "checksum python27-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "372555e88a6bc8109eb641380240dc8d25a128fc48363ec9075664daadffdd5b"
495 502 "checksum python3-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f3a8ebed3f1201fda179f3960609dbbc10cd8c75e9f2afcb03788278f367d8ea"
496 503 "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
497 504 "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412"
498 505 "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
499 506 "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
500 507 "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
501 508 "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
502 509 "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
503 510 "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
504 511 "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
505 512 "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
506 513 "checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
507 514 "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
508 515 "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
509 516 "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
510 517 "checksum rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123"
511 518 "checksum rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98dcf634205083b17d0861252431eb2acbfb698ab7478a2d20de07954f47ec7b"
512 519 "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
513 520 "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
514 521 "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
515 522 "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
516 523 "checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
517 524 "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
518 525 "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
519 526 "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
520 527 "checksum twox-hash 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56"
521 528 "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
522 529 "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
523 530 "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
524 531 "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
@@ -1,19 +1,20 b''
1 1 [package]
2 2 name = "hg-core"
3 3 version = "0.1.0"
4 4 authors = ["Georges Racinet <gracinet@anybox.fr>"]
5 5 description = "Mercurial pure Rust core library, with no assumption on Python bindings (FFI)"
6 6 edition = "2018"
7 7
8 8 [lib]
9 9 name = "hg"
10 10
11 11 [dependencies]
12 12 byteorder = "1.3.1"
13 hex = "0.4.0"
13 14 lazy_static = "1.3.0"
14 15 memchr = "2.2.0"
15 16 rand = "0.6.5"
16 17 rand_pcg = "0.1.1"
17 18 rayon = "1.2.0"
18 19 regex = "1.1.0"
19 20 twox-hash = "1.5.0"
@@ -1,40 +1,42 b''
1 1 // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net>
2 2 // and Mercurial contributors
3 3 //
4 4 // This software may be used and distributed according to the terms of the
5 5 // GNU General Public License version 2 or any later version.
6 6 //! Mercurial concepts for handling revision history
7 7
8 pub mod node;
8 9 pub mod nodemap;
10 pub use node::{Node, NodeError};
9 11
10 12 /// Mercurial revision numbers
11 13 ///
12 14 /// As noted in revlog.c, revision numbers are actually encoded in
13 15 /// 4 bytes, and are liberally converted to ints, whence the i32
14 16 pub type Revision = i32;
15 17
16 18 /// Marker expressing the absence of a parent
17 19 ///
18 20 /// Independently of the actual representation, `NULL_REVISION` is guaranteed
19 21 /// to be smaller than all existing revisions.
20 22 pub const NULL_REVISION: Revision = -1;
21 23
22 24 /// Same as `mercurial.node.wdirrev`
23 25 ///
24 26 /// This is also equal to `i32::max_value()`, but it's better to spell
25 27 /// it out explicitely, same as in `mercurial.node`
26 28 pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff;
27 29
28 30 /// The simplest expression of what we need of Mercurial DAGs.
29 31 pub trait Graph {
30 32 /// Return the two parents of the given `Revision`.
31 33 ///
32 34 /// Each of the parents can be independently `NULL_REVISION`
33 35 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>;
34 36 }
35 37
36 38 #[derive(Clone, Debug, PartialEq)]
37 39 pub enum GraphError {
38 40 ParentOutOfRange(Revision),
39 41 WorkingDirectoryUnsupported,
40 42 }
General Comments 0
You need to be logged in to leave comments. Login now