| 1 |
use std::ffi::OsStr; |
| 2 |
use std::ffi::OsString; |
| 3 |
use std::os::unix::prelude::OsStrExt; |
| 4 |
|
| 5 |
use hg::utils::hg_path::HgPath; |
| 6 |
use hg::warnings::HgWarningContext; |
| 7 |
use hg::{self}; |
| 8 |
|
| 9 |
use crate::error::CommandError; |
| 10 |
use crate::ui::print_warnings; |
| 11 |
|
| 12 |
pub const HELP_TEXT: &str = ""; |
| 13 |
|
| 14 |
pub fn args() -> clap::Command { |
| 15 |
clap::command!("debugrhgsparse") |
| 16 |
.args_override_self(true) |
| 17 |
.arg( |
| 18 |
clap::Arg::new("files") |
| 19 |
.value_name("FILES") |
| 20 |
.required(true) |
| 21 |
.num_args(1..) |
| 22 |
.value_parser(clap::value_parser!(std::ffi::OsString)) |
| 23 |
.help("Files to check against sparse profile"), |
| 24 |
) |
| 25 |
.about(HELP_TEXT) |
| 26 |
} |
| 27 |
|
| 28 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
| 29 |
let repo = invocation.repo?; |
| 30 |
|
| 31 |
let warning_context = HgWarningContext::new(); |
| 32 |
let matcher = |
| 33 |
hg::sparse::matcher(repo, None, warning_context.sender()).unwrap(); |
| 34 |
|
| 35 |
print_warnings( |
| 36 |
invocation.ui, |
| 37 |
warning_context, |
| 38 |
repo.working_directory_path(), |
| 39 |
); |
| 40 |
let files = invocation.subcommand_args.get_many::<OsString>("files"); |
| 41 |
if let Some(files) = files { |
| 42 |
let files: Vec<&OsStr> = |
| 43 |
files.filter(|s| !s.is_empty()).map(|s| s.as_os_str()).collect(); |
| 44 |
for file in files { |
| 45 |
invocation.ui.write_stdout(b"matches: ")?; |
| 46 |
invocation.ui.write_stdout( |
| 47 |
if matcher.matches(HgPath::new(file.as_bytes())) { |
| 48 |
b"yes" |
| 49 |
} else { |
| 50 |
b"no" |
| 51 |
}, |
| 52 |
)?; |
| 53 |
invocation.ui.write_stdout(b" | file: ")?; |
| 54 |
invocation.ui.write_stdout(file.as_bytes())?; |
| 55 |
invocation.ui.write_stdout(b"\n")?; |
| 56 |
} |
| 57 |
} |
| 58 |
Ok(()) |
| 59 |
} |