--- a/rust/hg-core/src/revlog/node.rs Wed Jan 27 14:59:09 2021 +0100
+++ b/rust/hg-core/src/revlog/node.rs Wed Jan 27 14:45:25 2021 +0100
@@ -8,6 +8,7 @@
//! In Mercurial code base, it is customary to call "a node" the binary SHA
//! of a revision.
+use crate::errors::HgError;
use bytes_cast::BytesCast;
use std::convert::{TryFrom, TryInto};
use std::fmt;
@@ -136,6 +137,19 @@
}
}
+ /// `from_hex`, but for input from an internal file of the repository such
+ /// as a changelog or manifest entry.
+ ///
+ /// An error is treated as repository corruption.
+ pub fn from_hex_for_repo(hex: impl AsRef<[u8]>) -> Result<Node, HgError> {
+ Self::from_hex(hex.as_ref()).map_err(|FromHexError| {
+ HgError::CorruptedRepository(format!(
+ "Expected a full hexadecimal node ID, found {}",
+ String::from_utf8_lossy(hex.as_ref())
+ ))
+ })
+ }
+
/// Provide access to binary data
///
/// This is needed by FFI layers, for instance to return expected