| 1 |
use clap::Arg; |
| 2 |
use clap::ArgGroup; |
| 3 |
use hg::operations::debug_data; |
| 4 |
use hg::revlog::RevlogType; |
| 5 |
|
| 6 |
use crate::error::CommandError; |
| 7 |
|
| 8 |
pub const HELP_TEXT: &str = " |
| 9 |
Dump the contents of a data file revision |
| 10 |
"; |
| 11 |
|
| 12 |
pub fn args() -> clap::Command { |
| 13 |
clap::command!("debugdata") |
| 14 |
.args_override_self(true) |
| 15 |
.arg( |
| 16 |
Arg::new("changelog") |
| 17 |
.help("open changelog") |
| 18 |
.short('c') |
| 19 |
.action(clap::ArgAction::SetTrue), |
| 20 |
) |
| 21 |
.arg( |
| 22 |
Arg::new("manifest") |
| 23 |
.help("open manifest") |
| 24 |
.short('m') |
| 25 |
.action(clap::ArgAction::SetTrue), |
| 26 |
) |
| 27 |
.group( |
| 28 |
ArgGroup::new("revlog") |
| 29 |
.args(["changelog", "manifest"]) |
| 30 |
.required(true), |
| 31 |
) |
| 32 |
.arg(Arg::new("rev").help("revision").required(true).value_name("REV")) |
| 33 |
.about(HELP_TEXT) |
| 34 |
} |
| 35 |
|
| 36 |
#[tracing::instrument(level = "debug", skip_all, name = "rhg debugdata")] |
| 37 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
| 38 |
let args = invocation.subcommand_args; |
| 39 |
let rev = args |
| 40 |
.get_one::<String>("rev") |
| 41 |
.expect("rev should be a required argument"); |
| 42 |
let kind = match ( |
| 43 |
args.get_one::<bool>("changelog").unwrap(), |
| 44 |
args.get_one::<bool>("manifest").unwrap(), |
| 45 |
) { |
| 46 |
(true, false) => RevlogType::Changelog, |
| 47 |
(false, true) => RevlogType::Manifestlog, |
| 48 |
(true, true) => { |
| 49 |
unreachable!("Should not happen since options are exclusive") |
| 50 |
} |
| 51 |
(false, false) => { |
| 52 |
unreachable!("Should not happen since options are required") |
| 53 |
} |
| 54 |
}; |
| 55 |
|
| 56 |
let repo = invocation.repo?; |
| 57 |
if repo.has_narrow() { |
| 58 |
return Err(CommandError::unsupported( |
| 59 |
"support for ellipsis nodes is missing and repo has narrow enabled", |
| 60 |
)); |
| 61 |
} |
| 62 |
let data = debug_data(repo, rev, kind)?; |
| 63 |
|
| 64 |
let mut stdout = invocation.ui.stdout_buffer(); |
| 65 |
stdout.write_all(&data)?; |
| 66 |
stdout.flush()?; |
| 67 |
|
| 68 |
Ok(()) |
| 69 |
} |