Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/commands/cat.rs @ 46744:b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
And exit with an error code if no file was matched.
This matches the behavior of Python-based hg.
Differential Revision: https://phab.mercurial-scm.org/D10142
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 03 Mar 2021 16:40:03 +0100 |
parents | 97ac588b6d9e |
children | d919b0ca8449 |
line wrap: on
line diff
--- a/rust/rhg/src/commands/cat.rs Mon Mar 08 19:07:29 2021 +0100 +++ b/rust/rhg/src/commands/cat.rs Wed Mar 03 16:40:03 2021 +0100 @@ -1,5 +1,6 @@ use crate::error::CommandError; use clap::Arg; +use format_bytes::format_bytes; use hg::operations::cat; use hg::utils::hg_path::HgPathBuf; use micro_timer::timed; @@ -58,9 +59,23 @@ match rev { Some(rev) => { - let data = cat(&repo, rev, &files).map_err(|e| (e, rev))?; - invocation.ui.write_stdout(&data)?; - Ok(()) + let output = cat(&repo, rev, &files).map_err(|e| (e, rev))?; + invocation.ui.write_stdout(&output.concatenated)?; + if !output.missing.is_empty() { + let short = format!("{:x}", output.node.short()).into_bytes(); + for path in &output.missing { + invocation.ui.write_stderr(&format_bytes!( + b"{}: no such file in rev {}\n", + path.as_bytes(), + short + ))?; + } + } + if output.found_any { + Ok(()) + } else { + Err(CommandError::Unsuccessful) + } } None => Err(CommandError::unsupported( "`rhg cat` without `--rev` / `-r`",