Mercurial > hg-stable
comparison rust/rhg/src/commands/cat.rs @ 46757: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 |
comparison
equal
deleted
inserted
replaced
46756:84a3deca963a | 46757:b1f2c2b336ec |
---|---|
1 use crate::error::CommandError; | 1 use crate::error::CommandError; |
2 use clap::Arg; | 2 use clap::Arg; |
3 use format_bytes::format_bytes; | |
3 use hg::operations::cat; | 4 use hg::operations::cat; |
4 use hg::utils::hg_path::HgPathBuf; | 5 use hg::utils::hg_path::HgPathBuf; |
5 use micro_timer::timed; | 6 use micro_timer::timed; |
6 use std::convert::TryFrom; | 7 use std::convert::TryFrom; |
7 | 8 |
56 files.push(hg_file); | 57 files.push(hg_file); |
57 } | 58 } |
58 | 59 |
59 match rev { | 60 match rev { |
60 Some(rev) => { | 61 Some(rev) => { |
61 let data = cat(&repo, rev, &files).map_err(|e| (e, rev))?; | 62 let output = cat(&repo, rev, &files).map_err(|e| (e, rev))?; |
62 invocation.ui.write_stdout(&data)?; | 63 invocation.ui.write_stdout(&output.concatenated)?; |
63 Ok(()) | 64 if !output.missing.is_empty() { |
65 let short = format!("{:x}", output.node.short()).into_bytes(); | |
66 for path in &output.missing { | |
67 invocation.ui.write_stderr(&format_bytes!( | |
68 b"{}: no such file in rev {}\n", | |
69 path.as_bytes(), | |
70 short | |
71 ))?; | |
72 } | |
73 } | |
74 if output.found_any { | |
75 Ok(()) | |
76 } else { | |
77 Err(CommandError::Unsuccessful) | |
78 } | |
64 } | 79 } |
65 None => Err(CommandError::unsupported( | 80 None => Err(CommandError::unsupported( |
66 "`rhg cat` without `--rev` / `-r`", | 81 "`rhg cat` without `--rev` / `-r`", |
67 )), | 82 )), |
68 } | 83 } |