rust/rhg/src/commands/debugdata.rs
author Matt Harbison <matt_harbison@yahoo.com>
Fri, 04 Oct 2024 01:40:35 -0400
changeset 51952 f4c038081561
parent 51867 69b804c8e09e
permissions -rw-r--r--
run-tests: bump the default timeout on Windows to 4x the normal value There are a ridiculous number of tests that timeout on Windows with the 360 sec default (~60). And because of the bug where timed out tests still run to completion before the results are thrown away[1], the timeout does nothing but waste time, so there's no reason to try to find a lower value that still works. For reference on my system: # Ran 909 tests, 116 skipped, 119 failed. python hash seed: 2052473208 real 151m44.322s user 0m0.077s sys 0m0.046s [1] I thought that I wrote a bug for this, but search isn't finding it.

use crate::error::CommandError;
use clap::Arg;
use clap::ArgGroup;
use hg::operations::debug_data;
use hg::RevlogType;

pub const HELP_TEXT: &str = "
Dump the contents of a data file revision
";

pub fn args() -> clap::Command {
    clap::command!("debugdata")
        .arg(
            Arg::new("changelog")
                .help("open changelog")
                .short('c')
                .action(clap::ArgAction::SetTrue),
        )
        .arg(
            Arg::new("manifest")
                .help("open manifest")
                .short('m')
                .action(clap::ArgAction::SetTrue),
        )
        .group(
            ArgGroup::new("revlog")
                .args(["changelog", "manifest"])
                .required(true),
        )
        .arg(
            Arg::new("rev")
                .help("revision")
                .required(true)
                .value_name("REV"),
        )
        .about(HELP_TEXT)
}

#[logging_timer::time("trace")]
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    let args = invocation.subcommand_args;
    let rev = args
        .get_one::<String>("rev")
        .expect("rev should be a required argument");
    let kind = match (
        args.get_one::<bool>("changelog").unwrap(),
        args.get_one::<bool>("manifest").unwrap(),
    ) {
        (true, false) => RevlogType::Changelog,
        (false, true) => RevlogType::Manifestlog,
        (true, true) => {
            unreachable!("Should not happen since options are exclusive")
        }
        (false, false) => {
            unreachable!("Should not happen since options are required")
        }
    };

    let repo = invocation.repo?;
    if repo.has_narrow() {
        return Err(CommandError::unsupported(
            "support for ellipsis nodes is missing and repo has narrow enabled",
        ));
    }
    let data = debug_data(repo, rev, kind).map_err(|e| (e, rev.as_ref()))?;

    let mut stdout = invocation.ui.stdout_buffer();
    stdout.write_all(&data)?;
    stdout.flush()?;

    Ok(())
}