Mercurial > hg
annotate rust/rhg/src/blackbox.rs @ 49070:137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
This refactoring makes it easy to patch some command-line preprocessing into rhg.
We use this to support using rhg as a shebang interpreter, for example.
Differential Revision: https://phab.mercurial-scm.org/D12543
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Tue, 12 Apr 2022 20:01:49 +0100 |
parents | abbecb5cd6f3 |
children | d39ac3468ad4 |
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}; |
49070
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
8 use std::ffi::OsString; |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
9 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
10 const ONE_MEBIBYTE: u64 = 1 << 20; |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
11 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
12 // 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
|
13 const DEFAULT_MAX_SIZE: u64 = ONE_MEBIBYTE; |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
14 const DEFAULT_MAX_FILES: u32 = 7; |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
15 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
16 // Python does not support %.3f, only %f |
48574
abbecb5cd6f3
blackbox: change year in logs to ISO 8601 format
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46665
diff
changeset
|
17 const DEFAULT_DATE_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.3f"; |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
18 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
19 type DateTime = chrono::DateTime<chrono::Local>; |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
20 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
21 pub struct ProcessStartTime { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
22 /// For measuring duration |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
23 monotonic_clock: std::time::Instant, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
24 /// For formatting with year, month, day, etc. |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
25 calendar_based: DateTime, |
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 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
28 impl ProcessStartTime { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
29 pub fn now() -> Self { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
30 Self { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
31 monotonic_clock: std::time::Instant::now(), |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
32 calendar_based: chrono::Local::now(), |
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 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
37 pub struct Blackbox<'a> { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
38 process_start_time: &'a ProcessStartTime, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
39 /// Do nothing if this is `None` |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
40 configured: Option<ConfiguredBlackbox<'a>>, |
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 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
43 struct ConfiguredBlackbox<'a> { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
44 repo: &'a Repo, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
45 max_size: u64, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
46 max_files: u32, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
47 date_format: &'a str, |
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 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
50 impl<'a> Blackbox<'a> { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
51 pub fn new( |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
52 invocation: &'a CliInvocation<'a>, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
53 process_start_time: &'a ProcessStartTime, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
54 ) -> Result<Self, HgError> { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
55 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
|
56 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
|
57 // The extension is not enabled |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
58 None |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
59 } else { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
60 Some(ConfiguredBlackbox { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
61 repo, |
46665
7284b524b441
rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents:
46601
diff
changeset
|
62 max_size: invocation |
7284b524b441
rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents:
46601
diff
changeset
|
63 .config |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
64 .get_byte_size(b"blackbox", b"maxsize")? |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
65 .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
|
66 max_files: invocation |
7284b524b441
rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents:
46601
diff
changeset
|
67 .config |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
68 .get_u32(b"blackbox", b"maxfiles")? |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
69 .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
|
70 date_format: invocation |
7284b524b441
rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents:
46601
diff
changeset
|
71 .config |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
72 .get_str(b"blackbox", b"date-format")? |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
73 .unwrap_or(DEFAULT_DATE_FORMAT), |
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 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
76 } else { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
77 // 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
|
78 // write to. |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
79 None |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
80 }; |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
81 Ok(Self { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
82 process_start_time, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
83 configured, |
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 |
49070
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
87 pub fn log_command_start<'arg>( |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
88 &self, |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
89 argv: impl Iterator<Item = &'arg OsString>, |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
90 ) { |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
91 if let Some(configured) = &self.configured { |
49070
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
92 let message = format_bytes!(b"(rust) {}", format_cli_args(argv)); |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
93 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
|
94 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
95 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
96 |
49070
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
97 pub fn log_command_end<'arg>( |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
98 &self, |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
99 argv: impl Iterator<Item = &'arg OsString>, |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
100 exit_code: i32, |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
101 ) { |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
102 if let Some(configured) = &self.configured { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
103 let now = chrono::Local::now(); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
104 let duration = self |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
105 .process_start_time |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
106 .monotonic_clock |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
107 .elapsed() |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
108 .as_secs_f64(); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
109 let message = format_bytes!( |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
110 b"(rust) {} exited {} after {} seconds", |
49070
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
111 format_cli_args(argv), |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
112 exit_code, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
113 format_bytes::Utf8(format_args!("{:.03}", duration)) |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
114 ); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
115 configured.log(&now, &message); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
116 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
117 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
118 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
119 |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
120 impl ConfiguredBlackbox<'_> { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 format!("{:x}", parents.p1) |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
128 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
129 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
|
130 Err(_dirstate_corruption_error) => { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
131 // 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
|
132 "???".to_owned() |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
133 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
134 }); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
135 let pid = std::process::id(); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
136 let line = format_bytes!( |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
137 b"{} {} @{} ({})> {}\n", |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
138 date, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
139 user, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
140 rev, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
141 pid, |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
142 message |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
143 ); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
144 let result = |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
145 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
|
146 .max_size(Some(self.max_size)) |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
147 .max_files(self.max_files) |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
148 .write(&line); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
149 match result { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
150 Ok(()) => {} |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
151 Err(_io_error) => { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
152 // 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
|
153 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
154 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
155 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
156 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
157 |
49070
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
158 fn format_cli_args<'a>( |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
159 mut args: impl Iterator<Item = &'a OsString>, |
137a93125902
rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48574
diff
changeset
|
160 ) -> Vec<u8> { |
46601
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
161 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
|
162 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
|
163 let mut formatted = Vec::new(); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
164 if let Some(arg) = args.next() { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
165 formatted.extend(arg) |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
166 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
167 for arg in args { |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
168 formatted.push(b' '); |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
169 formatted.extend(arg) |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
170 } |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
171 formatted |
755c31a1caf9
rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
172 } |