Show More
@@ -2,6 +2,7 b' use std::ops::Deref;' | |||||
2 |
|
2 | |||
3 | use byteorder::{BigEndian, ByteOrder}; |
|
3 | use byteorder::{BigEndian, ByteOrder}; | |
4 |
|
4 | |||
|
5 | use crate::revlog::revlog::RevlogError; | |||
5 | use crate::revlog::{Revision, NULL_REVISION}; |
|
6 | use crate::revlog::{Revision, NULL_REVISION}; | |
6 |
|
7 | |||
7 | pub const INDEX_ENTRY_SIZE: usize = 64; |
|
8 | pub const INDEX_ENTRY_SIZE: usize = 64; | |
@@ -17,7 +18,9 b' pub struct Index {' | |||||
17 | impl Index { |
|
18 | impl Index { | |
18 | /// Create an index from bytes. |
|
19 | /// Create an index from bytes. | |
19 | /// Calculate the start of each entry when is_inline is true. |
|
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 | if is_inline(&bytes) { |
|
24 | if is_inline(&bytes) { | |
22 | let mut offset: usize = 0; |
|
25 | let mut offset: usize = 0; | |
23 | let mut offsets = Vec::new(); |
|
26 | let mut offsets = Vec::new(); | |
@@ -33,15 +36,19 b' impl Index {' | |||||
33 | offset += INDEX_ENTRY_SIZE + entry.compressed_len(); |
|
36 | offset += INDEX_ENTRY_SIZE + entry.compressed_len(); | |
34 | } |
|
37 | } | |
35 |
|
38 | |||
36 | Self { |
|
39 | if offset == bytes.len() { | |
37 |
|
|
40 | Ok(Self { | |
38 | offsets: Some(offsets), |
|
41 | bytes, | |
|
42 | offsets: Some(offsets), | |||
|
43 | }) | |||
|
44 | } else { | |||
|
45 | Err(RevlogError::Corrupted) | |||
39 | } |
|
46 | } | |
40 | } else { |
|
47 | } else { | |
41 | Self { |
|
48 | Ok(Self { | |
42 | bytes, |
|
49 | bytes, | |
43 | offsets: None, |
|
50 | offsets: None, | |
44 | } |
|
51 | }) | |
45 | } |
|
52 | } | |
46 | } |
|
53 | } | |
47 |
|
54 |
@@ -56,7 +56,7 b' impl Revlog {' | |||||
56 | return Err(RevlogError::UnsuportedVersion(version)); |
|
56 | return Err(RevlogError::UnsuportedVersion(version)); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | let index = Index::new(Box::new(index_mmap)); |
|
59 | let index = Index::new(Box::new(index_mmap))?; | |
60 |
|
60 | |||
61 | // TODO load data only when needed // |
|
61 | // TODO load data only when needed // | |
62 | // type annotation required |
|
62 | // type annotation required |
General Comments 0
You need to be logged in to leave comments.
Login now