view rust/rhg/src/commands/debugrhgsparse.rs @ 50215:ae61851e6fe2 stable

dirstate: add a way to test races happening during status We add the `devel.sync.status.pre-dirstate-write-file` config option to easily test what happens when other operations happen during the window where `hg status` is done working but has not updated the cache on disk yet. We introduce the framework for testing such races too, actual tests will be added in the next changesets. For now the test is only checking dirstate-v1. We will extend the test coverage later too. Check test documentation for details. Code change from Rapha?l Gom?s <rgomes@octobus.net> Test change from Pierre-Yves David <pierre-yves.david@octobus.net>
author Rapha?l Gom?s <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 28 Feb 2023 15:25:47 +0100
parents 85f5d11c77dd
children 37bc3edef76f
line wrap: on
line source

use std::os::unix::prelude::OsStrExt;

use crate::error::CommandError;
use clap::SubCommand;
use hg::{self, utils::hg_path::HgPath};

pub const HELP_TEXT: &str = "";

pub fn args() -> clap::App<'static, 'static> {
    SubCommand::with_name("debugrhgsparse")
        .arg(
            clap::Arg::with_name("files")
                .required(true)
                .multiple(true)
                .empty_values(false)
                .value_name("FILES")
                .help("Files to check against sparse profile"),
        )
        .about(HELP_TEXT)
}

pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    let repo = invocation.repo?;

    let (matcher, _warnings) = hg::sparse::matcher(&repo).unwrap();
    let files = invocation.subcommand_args.values_of_os("files");
    if let Some(files) = files {
        for file in files {
            invocation.ui.write_stdout(b"matches: ")?;
            invocation.ui.write_stdout(
                if matcher.matches(HgPath::new(file.as_bytes())) {
                    b"yes"
                } else {
                    b"no"
                },
            )?;
            invocation.ui.write_stdout(b" | file: ")?;
            invocation.ui.write_stdout(file.as_bytes())?;
            invocation.ui.write_stdout(b"\n")?;
        }
    }
    Ok(())
}