view rust/hg-core/src/operations/debugdata.rs @ 52970:e4ff37b5317c

stream-bundle: simple use of `mode` argument of `os.open` This argument have been around for a while and simplify the code. This is especially true as Windows does not have `os.fchmod` so we would have had to deal with this special case.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 18 Feb 2025 17:21:42 +0100
parents a3fa37bdb7ec
children
line wrap: on
line source

// debugdata.rs
//
// Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.

use crate::errors::HgError;
use crate::exit_codes;
use crate::repo::Repo;
use crate::revlog::options::default_revlog_options;
use crate::revlog::{Revlog, RevlogError, RevlogType};

/// Dump the contents data of a revision.
pub fn debug_data(
    repo: &Repo,
    revset: &str,
    kind: RevlogType,
) -> Result<Vec<u8>, RevlogError> {
    let index_file = match kind {
        RevlogType::Changelog => "00changelog.i",
        RevlogType::Manifestlog => "00manifest.i",
        _ => {
            return Err(RevlogError::Other(HgError::abort(
                format!("invalid revlog type {}", kind),
                exit_codes::ABORT,
                None,
            )))
        }
    };
    let revlog = Revlog::open(
        &repo.store_vfs(),
        index_file,
        None,
        default_revlog_options(
            repo.config(),
            repo.requirements(),
            RevlogType::Changelog,
        )?,
    )?;
    let rev =
        crate::revset::resolve_rev_number_or_hex_prefix(revset, &revlog)?;
    let data = revlog.get_data(rev)?;
    Ok(data.into_owned())
}