| 1 |
use std::io::Read; |
| 2 |
|
| 3 |
use hg::errors::IoResultExt; |
| 4 |
use hg::narrow::patterns_from_spec; |
| 5 |
use hg::narrow::shape::ShardTreeNode; |
| 6 |
use hg::utils::strings::SliceExt; |
| 7 |
use hg::warnings::HgWarningContext; |
| 8 |
|
| 9 |
use crate::error::CommandError; |
| 10 |
|
| 11 |
pub const HELP_TEXT: &str = " |
| 12 |
Temporary debug command to help the transition from old narrow to new |
| 13 |
shape-based narrow |
| 14 |
"; |
| 15 |
|
| 16 |
pub fn args() -> clap::Command { |
| 17 |
clap::command!("debug::narrow-fingerprint").about(HELP_TEXT) |
| 18 |
} |
| 19 |
|
| 20 |
#[tracing::instrument( |
| 21 |
level = "debug", |
| 22 |
skip_all, |
| 23 |
name = "rhg debug::narrow-fingerprint" |
| 24 |
)] |
| 25 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
| 26 |
let warning_context = HgWarningContext::new(); |
| 27 |
|
| 28 |
let mut spec = vec![]; |
| 29 |
std::io::stdin().read_to_end(&mut spec).when_reading_file("stdin")?; |
| 30 |
if spec.is_empty() { |
| 31 |
return Err(CommandError::abort("empty narrowspec given")); |
| 32 |
} |
| 33 |
let mut stdout = invocation.ui.stdout_buffer(); |
| 34 |
|
| 35 |
let patterns = patterns_from_spec(warning_context.sender(), &spec)?; |
| 36 |
let (includes, excludes) = patterns.unwrap_or((vec![], vec![])); |
| 37 |
let tree = ShardTreeNode::from_patterns(&includes, &excludes)?; |
| 38 |
stdout.write_all(&tree.fingerprint().to_hex_bytes())?; |
| 39 |
stdout.write_all(b"\n")?; |
| 40 |
|
| 41 |
stdout.flush()?; |
| 42 |
|
| 43 |
Ok(()) |
| 44 |
} |