rust/hg-core/src/revlog/node.rs
changeset 46443 43d63979a75e
parent 46435 2e2033081274
child 46595 98a455a62699
equal deleted inserted replaced
46442:02d3bb972121 46443:43d63979a75e
     6 //! Definitions and utilities for Revision nodes
     6 //! Definitions and utilities for Revision nodes
     7 //!
     7 //!
     8 //! In Mercurial code base, it is customary to call "a node" the binary SHA
     8 //! In Mercurial code base, it is customary to call "a node" the binary SHA
     9 //! of a revision.
     9 //! of a revision.
    10 
    10 
       
    11 use crate::errors::HgError;
    11 use bytes_cast::BytesCast;
    12 use bytes_cast::BytesCast;
    12 use std::convert::{TryFrom, TryInto};
    13 use std::convert::{TryFrom, TryInto};
    13 use std::fmt;
    14 use std::fmt;
    14 
    15 
    15 /// The length in bytes of a `Node`
    16 /// The length in bytes of a `Node`
   132         if prefix.nybbles_len() == NODE_NYBBLES_LENGTH {
   133         if prefix.nybbles_len() == NODE_NYBBLES_LENGTH {
   133             Ok(Self { data: prefix.data })
   134             Ok(Self { data: prefix.data })
   134         } else {
   135         } else {
   135             Err(FromHexError)
   136             Err(FromHexError)
   136         }
   137         }
       
   138     }
       
   139 
       
   140     /// `from_hex`, but for input from an internal file of the repository such
       
   141     /// as a changelog or manifest entry.
       
   142     ///
       
   143     /// An error is treated as repository corruption.
       
   144     pub fn from_hex_for_repo(hex: impl AsRef<[u8]>) -> Result<Node, HgError> {
       
   145         Self::from_hex(hex.as_ref()).map_err(|FromHexError| {
       
   146             HgError::CorruptedRepository(format!(
       
   147                 "Expected a full hexadecimal node ID, found {}",
       
   148                 String::from_utf8_lossy(hex.as_ref())
       
   149             ))
       
   150         })
   137     }
   151     }
   138 
   152 
   139     /// Provide access to binary data
   153     /// Provide access to binary data
   140     ///
   154     ///
   141     /// This is needed by FFI layers, for instance to return expected
   155     /// This is needed by FFI layers, for instance to return expected