Debian Codegraph @

rust/hg-core/src/operations/debugdata.rs

raw
1 // debugdata.rs
2 //
3 // Copyright 2020 Antoine Cezar <[email protected]>
4 //
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
7
8 use crate::errors::HgError;
9 use crate::exit_codes;
10 use crate::repo::Repo;
11 use crate::revlog::options::default_revlog_options;
12 use crate::revlog::Revlog;
13 use crate::revlog::RevlogError;
14 use crate::revlog::RevlogType;
15
16 /// Dump the contents data of a revision.
17 pub fn debug_data(
18 repo: &Repo,
19 revset: &str,
20 kind: RevlogType,
21 ) -> Result<Vec<u8>, RevlogError> {
22 let index_file = match kind {
23 RevlogType::Changelog => "00changelog.i",
24 RevlogType::Manifestlog => "00manifest.i",
25 _ => {
26 return Err(RevlogError::Other(HgError::abort(
27 format!("invalid revlog type {}", kind),
28 exit_codes::ABORT,
29 None,
30 )))
31 }
32 };
33 let revlog = Revlog::open(
34 &repo.store_vfs(),
35 index_file,
36 None,
37 default_revlog_options(repo.config(), repo.requirements(), kind)?,
38 kind,
39 )?;
40 let rev = crate::revset::resolve_rev_number_or_hex_prefix(revset, &revlog)?;
41 let data = revlog.get_data(rev)?;
42 Ok(data.into())
43 }