annotate rust/rhg/src/blackbox.rs @ 51689:39e2b2d062c1

pytype: work around wrong ImportError flagging As documented in https://github.com/google/pytype/issues/163, newer versions of Pytype do not understand caught `ImportError`, so we temporarily ignore them where applicable.
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 18 Jul 2024 12:03:29 +0200
parents 58aa5ee9c846
children
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};
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 // 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
11 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
12
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
13 type DateTime = chrono::DateTime<chrono::Local>;
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 pub struct ProcessStartTime {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
16 /// For measuring duration
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
17 monotonic_clock: std::time::Instant,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
18 /// For formatting with year, month, day, etc.
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
19 calendar_based: DateTime,
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
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
22 impl ProcessStartTime {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
23 pub fn now() -> Self {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
24 Self {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
25 monotonic_clock: std::time::Instant::now(),
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
26 calendar_based: chrono::Local::now(),
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 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
29 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
30
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
31 pub struct Blackbox<'a> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
32 process_start_time: &'a ProcessStartTime,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
33 /// Do nothing if this is `None`
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
34 configured: Option<ConfiguredBlackbox<'a>>,
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 struct ConfiguredBlackbox<'a> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
38 repo: &'a Repo,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
39 max_size: u64,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
40 max_files: u32,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
41 date_format: &'a str,
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
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
44 impl<'a> Blackbox<'a> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
45 pub fn new(
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
46 invocation: &'a CliInvocation<'a>,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
47 process_start_time: &'a ProcessStartTime,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
48 ) -> Result<Self, HgError> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
49 let configured = if let Ok(repo) = invocation.repo {
50766
58aa5ee9c846 rust-blackbox: use `is_extension_enabled` config helper
Raphaël Gomès <rgomes@octobus.net>
parents: 50765
diff changeset
50 if !invocation.config.is_extension_enabled(b"blackbox") {
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
51 None
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
52 } else {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
53 Some(ConfiguredBlackbox {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
54 repo,
46665
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
55 max_size: invocation
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
56 .config
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
57 .get_byte_size(b"blackbox", b"maxsize")?
50765
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
58 .expect(
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
59 "blackbox.maxsize should have a default value",
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
60 ),
46665
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
61 max_files: 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_u32(b"blackbox", b"maxfiles")?
50765
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
64 .expect(
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
65 "blackbox.maxfiles should have a default value",
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
66 ),
46665
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
67 date_format: invocation
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46601
diff changeset
68 .config
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
69 .get_str(b"blackbox", b"date-format")?
50765
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
70 .map(|f| {
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
71 if f.is_empty() {
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
72 DEFAULT_DATE_FORMAT
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
73 } else {
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
74 f
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
75 }
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
76 })
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
77 .expect(
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
78 "blackbox.date-format should have a default value",
7f8f6fe13fa9 configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents: 50683
diff changeset
79 ),
46601
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 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
82 } else {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
83 // 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
84 // write to.
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
85 None
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
86 };
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
87 Ok(Self {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
88 process_start_time,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
89 configured,
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
49070
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48574
diff changeset
93 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
94 &self,
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48574
diff changeset
95 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
96 ) {
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
97 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
98 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
99 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
100 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
101 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
102
49070
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48574
diff changeset
103 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
104 &self,
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48574
diff changeset
105 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
106 exit_code: i32,
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48574
diff changeset
107 ) {
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
108 if let Some(configured) = &self.configured {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
109 let now = chrono::Local::now();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
110 let duration = self
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
111 .process_start_time
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
112 .monotonic_clock
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
113 .elapsed()
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
114 .as_secs_f64();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
115 let message = format_bytes!(
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
116 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
117 format_cli_args(argv),
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
118 exit_code,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
119 format_bytes::Utf8(format_args!("{:.03}", duration))
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 configured.log(&now, &message);
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
122 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
123 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
124 }
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 impl ConfiguredBlackbox<'_> {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
127 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
128 let date = format_bytes::Utf8(date_time.format(self.date_format));
50683
d39ac3468ad4 rust-dependencies: switch from `users` to `whoami`
Raphaël Gomès <rgomes@octobus.net>
parents: 49070
diff changeset
129 let user = get_bytes_from_os_str(whoami::username_os());
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
130 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
131 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
132 format!("{:x}", parents.p1)
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 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
135 Err(_dirstate_corruption_error) => {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
136 // 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
137 "???".to_owned()
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
138 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
139 });
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
140 let pid = std::process::id();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
141 let line = format_bytes!(
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
142 b"{} {} @{} ({})> {}\n",
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
143 date,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
144 user,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
145 rev,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
146 pid,
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
147 message
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 let result =
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
150 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
151 .max_size(Some(self.max_size))
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
152 .max_files(self.max_files)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
153 .write(&line);
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
154 match result {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
155 Ok(()) => {}
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
156 Err(_io_error) => {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
157 // 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
158 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
159 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
160 }
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
49070
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48574
diff changeset
163 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
164 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
165 ) -> Vec<u8> {
46601
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
166 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
167 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
168 let mut formatted = Vec::new();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
169 if let Some(arg) = args.next() {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
170 formatted.extend(arg)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
171 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
172 for arg in args {
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
173 formatted.push(b' ');
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
174 formatted.extend(arg)
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
175 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
176 formatted
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
177 }