Show More
@@ -2,6 +2,7 b' use std::ops::Deref;' | |||
|
2 | 2 | |
|
3 | 3 | use byteorder::{BigEndian, ByteOrder}; |
|
4 | 4 | |
|
5 | use crate::revlog::revlog::RevlogError; | |
|
5 | 6 | use crate::revlog::{Revision, NULL_REVISION}; |
|
6 | 7 | |
|
7 | 8 | pub const INDEX_ENTRY_SIZE: usize = 64; |
@@ -17,7 +18,9 b' pub struct Index {' | |||
|
17 | 18 | impl Index { |
|
18 | 19 | /// Create an index from bytes. |
|
19 | 20 | /// Calculate the start of each entry when is_inline is true. |
|
20 | pub fn new(bytes: Box<dyn Deref<Target = [u8]> + Send>) -> Self { | |
|
21 | pub fn new( | |
|
22 | bytes: Box<dyn Deref<Target = [u8]> + Send>, | |
|
23 | ) -> Result<Self, RevlogError> { | |
|
21 | 24 | if is_inline(&bytes) { |
|
22 | 25 | let mut offset: usize = 0; |
|
23 | 26 | let mut offsets = Vec::new(); |
@@ -33,15 +36,19 b' impl Index {' | |||
|
33 | 36 | offset += INDEX_ENTRY_SIZE + entry.compressed_len(); |
|
34 | 37 | } |
|
35 | 38 | |
|
36 | Self { | |
|
37 |
|
|
|
38 | offsets: Some(offsets), | |
|
39 | if offset == bytes.len() { | |
|
40 | Ok(Self { | |
|
41 | bytes, | |
|
42 | offsets: Some(offsets), | |
|
43 | }) | |
|
44 | } else { | |
|
45 | Err(RevlogError::Corrupted) | |
|
39 | 46 | } |
|
40 | 47 | } else { |
|
41 | Self { | |
|
48 | Ok(Self { | |
|
42 | 49 | bytes, |
|
43 | 50 | offsets: None, |
|
44 | } | |
|
51 | }) | |
|
45 | 52 | } |
|
46 | 53 | } |
|
47 | 54 |
General Comments 0
You need to be logged in to leave comments.
Login now