rust/hg-core/src/operations/debugdata.rs
changeset 46437 b274aa2f20fd
parent 46435 2e2033081274
child 48541 f2f57724d4eb
equal deleted inserted replaced
46436:252d1bdba33d 46437:b274aa2f20fd
    13 pub enum DebugDataKind {
    13 pub enum DebugDataKind {
    14     Changelog,
    14     Changelog,
    15     Manifest,
    15     Manifest,
    16 }
    16 }
    17 
    17 
    18 /// Error type for `debug_data`
       
    19 #[derive(Debug, derive_more::From)]
       
    20 pub enum DebugDataError {
       
    21     /// Error when reading a `revlog` file.
       
    22     #[from]
       
    23     IoError(std::io::Error),
       
    24     /// The revision has not been found.
       
    25     InvalidRevision,
       
    26     /// Found more than one revision whose ID match the requested prefix
       
    27     AmbiguousPrefix,
       
    28     /// A `revlog` file is corrupted.
       
    29     CorruptedRevlog,
       
    30     /// The `revlog` format version is not supported.
       
    31     UnsuportedRevlogVersion(u16),
       
    32     /// The `revlog` data format is not supported.
       
    33     UnknowRevlogDataFormat(u8),
       
    34 }
       
    35 
       
    36 impl From<RevlogError> for DebugDataError {
       
    37     fn from(err: RevlogError) -> Self {
       
    38         match err {
       
    39             RevlogError::IoError(err) => DebugDataError::IoError(err),
       
    40             RevlogError::UnsuportedVersion(version) => {
       
    41                 DebugDataError::UnsuportedRevlogVersion(version)
       
    42             }
       
    43             RevlogError::InvalidRevision => DebugDataError::InvalidRevision,
       
    44             RevlogError::AmbiguousPrefix => DebugDataError::AmbiguousPrefix,
       
    45             RevlogError::Corrupted => DebugDataError::CorruptedRevlog,
       
    46             RevlogError::UnknowDataFormat(format) => {
       
    47                 DebugDataError::UnknowRevlogDataFormat(format)
       
    48             }
       
    49         }
       
    50     }
       
    51 }
       
    52 
       
    53 /// Dump the contents data of a revision.
    18 /// Dump the contents data of a revision.
    54 pub fn debug_data(
    19 pub fn debug_data(
    55     repo: &Repo,
    20     repo: &Repo,
    56     revset: &str,
    21     revset: &str,
    57     kind: DebugDataKind,
    22     kind: DebugDataKind,
    58 ) -> Result<Vec<u8>, DebugDataError> {
    23 ) -> Result<Vec<u8>, RevlogError> {
    59     let index_file = match kind {
    24     let index_file = match kind {
    60         DebugDataKind::Changelog => "00changelog.i",
    25         DebugDataKind::Changelog => "00changelog.i",
    61         DebugDataKind::Manifest => "00manifest.i",
    26         DebugDataKind::Manifest => "00manifest.i",
    62     };
    27     };
    63     let revlog = Revlog::open(repo, index_file, None)?;
    28     let revlog = Revlog::open(repo, index_file, None)?;