mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-24 12:48:55 +00:00
settings: propagate configuration error of commit and operation parameters
Note that infallible version of whoami::username() would return "Unknown" on error. I just made it error out, but it's also an option to fall back to an empty string.
This commit is contained in:
parent
4a69d0178c
commit
5bd669e892
2 changed files with 24 additions and 6 deletions
|
@ -18,8 +18,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|||
* The following configuration variables are now parsed strictly:
|
||||
`colors.<labels>`, `git.abandon-unreachable-commits`,
|
||||
`git.auto-local-bookmark`, `git.push-bookmark-prefix`, `revsets.log`,
|
||||
`revsets.short-prefixes` `signing.backend`, `ui.allow-init-native`,
|
||||
`ui.color`, `ui.default-description`, `ui.progress-indicator`, `ui.quiet`
|
||||
`revsets.short-prefixes` `signing.backend`, `operation.hostname`,
|
||||
`operation.username`, `ui.allow-init-native`, `ui.color`,
|
||||
`ui.default-description`, `ui.progress-indicator`, `ui.quiet`, `user.email`,
|
||||
`user.name`
|
||||
|
||||
* `jj config list` now prints inline tables `{ key = value, .. }` literally.
|
||||
Inner items of inline tables are no longer merged across configuration files.
|
||||
|
|
|
@ -146,20 +146,36 @@ fn to_timestamp(value: ConfigValue) -> Result<Timestamp, Box<dyn std::error::Err
|
|||
|
||||
impl UserSettings {
|
||||
pub fn from_config(config: StackedConfig) -> Result<Self, ConfigGetError> {
|
||||
let user_name = config.get("user.name").unwrap_or_default();
|
||||
let user_email = config.get("user.email").unwrap_or_default();
|
||||
let user_name = config.get("user.name").optional()?.unwrap_or_default();
|
||||
let user_email = config.get("user.email").optional()?.unwrap_or_default();
|
||||
let commit_timestamp = config
|
||||
.get_value_with("debug.commit-timestamp", to_timestamp)
|
||||
.optional()?;
|
||||
let operation_timestamp = config
|
||||
.get_value_with("debug.operation-timestamp", to_timestamp)
|
||||
.optional()?;
|
||||
// whoami::fallible::*() failure isn't a ConfigGetError, but user would
|
||||
// have to set the corresponding config keys if these parameter can't be
|
||||
// obtained from the system. Instead of handling environment data here,
|
||||
// it might be better to load them by CLI and insert as a config layer.
|
||||
let operation_hostname = config
|
||||
.get("operation.hostname")
|
||||
.unwrap_or_else(|_| whoami::fallible::hostname().expect("valid hostname"));
|
||||
.optional()?
|
||||
.map_or_else(whoami::fallible::hostname, Ok)
|
||||
.map_err(|err| ConfigGetError::Type {
|
||||
name: "operation.hostname".to_owned(),
|
||||
error: err.into(),
|
||||
source_path: None,
|
||||
})?;
|
||||
let operation_username = config
|
||||
.get("operation.username")
|
||||
.unwrap_or_else(|_| whoami::username());
|
||||
.optional()?
|
||||
.map_or_else(whoami::fallible::username, Ok)
|
||||
.map_err(|err| ConfigGetError::Type {
|
||||
name: "operation.username".to_owned(),
|
||||
error: err.into(),
|
||||
source_path: None,
|
||||
})?;
|
||||
let rng_seed = config.get::<u64>("debug.randomness-seed").optional()?;
|
||||
Ok(UserSettings {
|
||||
config,
|
||||
|
|
Loading…
Reference in a new issue