annotate rust/rhg/src/blackbox.rs @ 47859:155a2ec8a9dc

merge with stable
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 22 Aug 2021 16:32:06 -0400
parents 7284b524b441
children abbecb5cd6f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
1 //! Logging for repository events, including commands run in the repository.
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
2
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
3 use crate::CliInvocation;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
4 use format_bytes::format_bytes;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
5 use hg::errors::HgError;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
6 use hg::repo::Repo;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
7 use hg::utils::{files::get_bytes_from_os_str, shell_quote};
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
8
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
9 const ONE_MEBIBYTE: u64 = 1 << 20;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
10
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
11 // TODO: somehow keep defaults in sync with `configitem` in `hgext/blackbox.py`
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
12 const DEFAULT_MAX_SIZE: u64 = ONE_MEBIBYTE;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
13 const DEFAULT_MAX_FILES: u32 = 7;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
14
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
15 // Python does not support %.3f, only %f
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
16 const DEFAULT_DATE_FORMAT: &str = "%Y/%m/%d %H:%M:%S%.3f";
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
17
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
18 type DateTime = chrono::DateTime<chrono::Local>;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
19
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
20 pub struct ProcessStartTime {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
21 /// For measuring duration
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
22 monotonic_clock: std::time::Instant,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
23 /// For formatting with year, month, day, etc.
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
24 calendar_based: DateTime,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
25 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
26
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
27 impl ProcessStartTime {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
28 pub fn now() -> Self {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
29 Self {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
30 monotonic_clock: std::time::Instant::now(),
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
31 calendar_based: chrono::Local::now(),
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
32 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
33 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
34 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
35
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
36 pub struct Blackbox<'a> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
37 process_start_time: &'a ProcessStartTime,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
38 /// Do nothing if this is `None`
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
39 configured: Option<ConfiguredBlackbox<'a>>,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
40 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
41
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
42 struct ConfiguredBlackbox<'a> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
43 repo: &'a Repo,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
44 max_size: u64,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
45 max_files: u32,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
46 date_format: &'a str,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
47 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
48
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
49 impl<'a> Blackbox<'a> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
50 pub fn new(
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
51 invocation: &'a CliInvocation<'a>,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
52 process_start_time: &'a ProcessStartTime,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
53 ) -> Result<Self, HgError> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
54 let configured = if let Ok(repo) = invocation.repo {
46665
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
55 if invocation.config.get(b"extensions", b"blackbox").is_none() {
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
56 // The extension is not enabled
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
57 None
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
58 } else {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
59 Some(ConfiguredBlackbox {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
60 repo,
46665
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
61 max_size: invocation
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
62 .config
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
63 .get_byte_size(b"blackbox", b"maxsize")?
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
64 .unwrap_or(DEFAULT_MAX_SIZE),
46665
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
65 max_files: invocation
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
66 .config
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
67 .get_u32(b"blackbox", b"maxfiles")?
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
68 .unwrap_or(DEFAULT_MAX_FILES),
46665
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
69 date_format: invocation
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
70 .config
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
71 .get_str(b"blackbox", b"date-format")?
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
72 .unwrap_or(DEFAULT_DATE_FORMAT),
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
73 })
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
74 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
75 } else {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
76 // Without a local repository there’s no `.hg/blackbox.log` to
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
77 // write to.
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
78 None
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
79 };
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
80 Ok(Self {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
81 process_start_time,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
82 configured,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
83 })
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
84 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
85
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
86 pub fn log_command_start(&self) {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
87 if let Some(configured) = &self.configured {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
88 let message = format_bytes!(b"(rust) {}", format_cli_args());
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
89 configured.log(&self.process_start_time.calendar_based, &message);
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
90 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
91 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
92
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
93 pub fn log_command_end(&self, exit_code: i32) {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
94 if let Some(configured) = &self.configured {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
95 let now = chrono::Local::now();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
96 let duration = self
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
97 .process_start_time
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
98 .monotonic_clock
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
99 .elapsed()
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
100 .as_secs_f64();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
101 let message = format_bytes!(
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
102 b"(rust) {} exited {} after {} seconds",
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
103 format_cli_args(),
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
104 exit_code,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
105 format_bytes::Utf8(format_args!("{:.03}", duration))
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
106 );
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
107 configured.log(&now, &message);
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
108 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
109 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
110 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
111
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
112 impl ConfiguredBlackbox<'_> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
113 fn log(&self, date_time: &DateTime, message: &[u8]) {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
114 let date = format_bytes::Utf8(date_time.format(self.date_format));
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
115 let user = users::get_current_username().map(get_bytes_from_os_str);
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
116 let user = user.as_deref().unwrap_or(b"???");
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
117 let rev = format_bytes::Utf8(match self.repo.dirstate_parents() {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
118 Ok(parents) if parents.p2 == hg::revlog::node::NULL_NODE => {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
119 format!("{:x}", parents.p1)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
120 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
121 Ok(parents) => format!("{:x}+{:x}", parents.p1, parents.p2),
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
122 Err(_dirstate_corruption_error) => {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
123 // TODO: log a non-fatal warning to stderr
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
124 "???".to_owned()
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
125 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
126 });
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
127 let pid = std::process::id();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
128 let line = format_bytes!(
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
129 b"{} {} @{} ({})> {}\n",
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
130 date,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
131 user,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
132 rev,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
133 pid,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
134 message
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
135 );
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
136 let result =
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
137 hg::logging::LogFile::new(self.repo.hg_vfs(), "blackbox.log")
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
138 .max_size(Some(self.max_size))
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
139 .max_files(self.max_files)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
140 .write(&line);
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
141 match result {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
142 Ok(()) => {}
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
143 Err(_io_error) => {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
144 // TODO: log a non-fatal warning to stderr
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
145 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
146 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
147 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
148 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
149
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
150 fn format_cli_args() -> Vec<u8> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
151 let mut args = std::env::args_os();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
152 let _ = args.next(); // Skip the first (or zeroth) arg, the name of the `rhg` executable
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
153 let mut args = args.map(|arg| shell_quote(&get_bytes_from_os_str(arg)));
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
154 let mut formatted = Vec::new();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
155 if let Some(arg) = args.next() {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
156 formatted.extend(arg)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
157 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
158 for arg in args {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
159 formatted.push(b' ');
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
160 formatted.extend(arg)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
161 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
162 formatted
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
163 }