Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/revlog/node.rs @ 46511:43d63979a75e
rust: use HgError in RevlogError and Vfs
Differential Revision: https://phab.mercurial-scm.org/D9897
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 27 Jan 2021 14:45:25 +0100 |
parents | 2e2033081274 |
children | 98a455a62699 |
line wrap: on
line diff
--- 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