Mercurial > hg
comparison rust/hg-core/src/revlog/index.rs @ 45531:b0d6309ff50c
hg-core: check data integrity in `Revlog`
Check that the hash of the data reconstructed from deltas
matches the hash stored in the revision.
Differential Revision: https://phab.mercurial-scm.org/D9005
author | Antoine Cezar <antoine.cezar@octobus.net> |
---|---|
date | Wed, 02 Sep 2020 15:23:25 +0200 |
parents | 26c53ee51c68 |
children | 639f33f22faf |
comparison
equal
deleted
inserted
replaced
45530:b1cea0dc9db0 | 45531:b0d6309ff50c |
---|---|
1 use byteorder::{BigEndian, ByteOrder}; | |
2 | |
1 use crate::revlog::{Revision, NULL_REVISION}; | 3 use crate::revlog::{Revision, NULL_REVISION}; |
2 use byteorder::{BigEndian, ByteOrder}; | |
3 | 4 |
4 pub const INDEX_ENTRY_SIZE: usize = 64; | 5 pub const INDEX_ENTRY_SIZE: usize = 64; |
5 | 6 |
6 /// A Revlog index | 7 /// A Revlog index |
7 #[derive(Debug)] | 8 #[derive(Debug)] |
138 pub fn base_revision(&self) -> Revision { | 139 pub fn base_revision(&self) -> Revision { |
139 // TODO Maybe return an Option when base_revision == rev? | 140 // TODO Maybe return an Option when base_revision == rev? |
140 // Requires to add rev to IndexEntry | 141 // Requires to add rev to IndexEntry |
141 | 142 |
142 BigEndian::read_i32(&self.bytes[16..]) | 143 BigEndian::read_i32(&self.bytes[16..]) |
144 } | |
145 | |
146 pub fn p1(&self) -> Revision { | |
147 BigEndian::read_i32(&self.bytes[24..]) | |
148 } | |
149 | |
150 pub fn p2(&self) -> Revision { | |
151 BigEndian::read_i32(&self.bytes[28..]) | |
152 } | |
153 | |
154 /// Return the hash of revision's full text. | |
155 /// | |
156 /// Currently, SHA-1 is used and only the first 20 bytes of this field | |
157 /// are used. | |
158 pub fn hash(&self) -> &[u8] { | |
159 &self.bytes[32..52] | |
143 } | 160 } |
144 } | 161 } |
145 | 162 |
146 #[cfg(test)] | 163 #[cfg(test)] |
147 mod tests { | 164 mod tests { |