diff rust/hg-core/src/revlog/index.rs @ 46037: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
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/index.rs	Mon Nov 30 19:34:49 2020 +0100
+++ b/rust/hg-core/src/revlog/index.rs	Wed Dec 02 15:00:49 2020 +0100
@@ -1,7 +1,9 @@
+use std::convert::TryInto;
 use std::ops::Deref;
 
 use byteorder::{BigEndian, ByteOrder};
 
+use crate::revlog::node::Node;
 use crate::revlog::revlog::RevlogError;
 use crate::revlog::{Revision, NULL_REVISION};
 
@@ -188,8 +190,8 @@
     ///
     /// Currently, SHA-1 is used and only the first 20 bytes of this field
     /// are used.
-    pub fn hash(&self) -> &[u8] {
-        &self.bytes[32..52]
+    pub fn hash(&self) -> &Node {
+        (&self.bytes[32..52]).try_into().unwrap()
     }
 }