Mercurial > public > mercurial-scm > hg-stable
diff rust/rhg/src/blackbox.rs @ 50804:7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
In order for the Rust code to gain access to default values of in-core
extensions that have a Rust implementation, we need to centralize them
alongside the core items declarations.
This is the first and so far only one of the extensions that have gained
Rust support, I don't think it's worth the churn to move the rest of the
extension's configitems yet.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 05 Jul 2023 23:59:22 +0200 |
parents | d39ac3468ad4 |
children | 58aa5ee9c846 |
line wrap: on
line diff
--- a/rust/rhg/src/blackbox.rs Mon Feb 13 18:11:48 2023 +0100 +++ b/rust/rhg/src/blackbox.rs Wed Jul 05 23:59:22 2023 +0200 @@ -7,12 +7,6 @@ use hg::utils::{files::get_bytes_from_os_str, shell_quote}; use std::ffi::OsString; -const ONE_MEBIBYTE: u64 = 1 << 20; - -// TODO: somehow keep defaults in sync with `configitem` in `hgext/blackbox.py` -const DEFAULT_MAX_SIZE: u64 = ONE_MEBIBYTE; -const DEFAULT_MAX_FILES: u32 = 7; - // Python does not support %.3f, only %f const DEFAULT_DATE_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.3f"; @@ -62,15 +56,28 @@ max_size: invocation .config .get_byte_size(b"blackbox", b"maxsize")? - .unwrap_or(DEFAULT_MAX_SIZE), + .expect( + "blackbox.maxsize should have a default value", + ), max_files: invocation .config .get_u32(b"blackbox", b"maxfiles")? - .unwrap_or(DEFAULT_MAX_FILES), + .expect( + "blackbox.maxfiles should have a default value", + ), date_format: invocation .config .get_str(b"blackbox", b"date-format")? - .unwrap_or(DEFAULT_DATE_FORMAT), + .map(|f| { + if f.is_empty() { + DEFAULT_DATE_FORMAT + } else { + f + } + }) + .expect( + "blackbox.date-format should have a default value", + ), }) } } else {