comparison rust/hg-core/src/revlog/index.rs @ 46033:88e741bf2d93

rust: use NodePrefix::from_hex instead of hex::decode directly This adds support for prefixes with an odd number of hex digits. Differential Revision: https://phab.mercurial-scm.org/D9490
author Simon Sapin <simon-commits@exyr.org>
date Wed, 02 Dec 2020 15:00:49 +0100
parents 1cef583541c0
children 9eb07ab3f2d4
comparison
equal deleted inserted replaced
46032:8d6164098782 46033:88e741bf2d93
1 use std::convert::TryInto;
1 use std::ops::Deref; 2 use std::ops::Deref;
2 3
3 use byteorder::{BigEndian, ByteOrder}; 4 use byteorder::{BigEndian, ByteOrder};
4 5
6 use crate::revlog::node::Node;
5 use crate::revlog::revlog::RevlogError; 7 use crate::revlog::revlog::RevlogError;
6 use crate::revlog::{Revision, NULL_REVISION}; 8 use crate::revlog::{Revision, NULL_REVISION};
7 9
8 pub const INDEX_ENTRY_SIZE: usize = 64; 10 pub const INDEX_ENTRY_SIZE: usize = 64;
9 11
186 188
187 /// Return the hash of revision's full text. 189 /// Return the hash of revision's full text.
188 /// 190 ///
189 /// Currently, SHA-1 is used and only the first 20 bytes of this field 191 /// Currently, SHA-1 is used and only the first 20 bytes of this field
190 /// are used. 192 /// are used.
191 pub fn hash(&self) -> &[u8] { 193 pub fn hash(&self) -> &Node {
192 &self.bytes[32..52] 194 (&self.bytes[32..52]).try_into().unwrap()
193 } 195 }
194 } 196 }
195 197
196 /// Value of the inline flag. 198 /// Value of the inline flag.
197 pub fn is_inline(index_bytes: &[u8]) -> bool { 199 pub fn is_inline(index_bytes: &[u8]) -> bool {