Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHG0cb1b02228a6: rust: use HgError in ConfigError
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
hg-reviewers |
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | rust/hg-core/src/config/config.rs (8 lines) | |||
M | rust/hg-core/src/config/layer.rs (48 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
e22c11fa12be | 9e464c9e4c95 | Simon Sapin | Feb 1 2021, 6:55 AM |
Status | Author | Revision | |
---|---|---|---|
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin |
// config.rs | // config.rs | ||||
// | // | ||||
// Copyright 2020 | // Copyright 2020 | ||||
// Valentin Gatien-Baron, | // Valentin Gatien-Baron, | ||||
// Raphaël Gomès <rgomes@octobus.net> | // Raphaël Gomès <rgomes@octobus.net> | ||||
// | // | ||||
// This software may be used and distributed according to the terms of the | // This software may be used and distributed according to the terms of the | ||||
// GNU General Public License version 2 or any later version. | // GNU General Public License version 2 or any later version. | ||||
use super::layer; | use super::layer; | ||||
use crate::config::layer::{ConfigError, ConfigLayer, ConfigValue}; | use crate::config::layer::{ | ||||
ConfigError, ConfigLayer, ConfigParseError, ConfigValue, | |||||
}; | |||||
use std::path::PathBuf; | use std::path::PathBuf; | ||||
use crate::repo::Repo; | use crate::repo::Repo; | ||||
use crate::utils::files::read_whole_file; | use crate::utils::files::read_whole_file; | ||||
/// Holds the config values for the current repository | /// Holds the config values for the current repository | ||||
/// TODO update this docstring once we support more sources | /// TODO update this docstring once we support more sources | ||||
pub struct Config { | pub struct Config { | ||||
/// Returns an `Err` if the first value found is not a valid boolean. | /// Returns an `Err` if the first value found is not a valid boolean. | ||||
/// Otherwise, returns an `Ok(option)`, where `option` is the boolean if | /// Otherwise, returns an `Ok(option)`, where `option` is the boolean if | ||||
/// found, or `None`. | /// found, or `None`. | ||||
pub fn get_option( | pub fn get_option( | ||||
&self, | &self, | ||||
section: &[u8], | section: &[u8], | ||||
item: &[u8], | item: &[u8], | ||||
) -> Result<Option<bool>, ConfigError> { | ) -> Result<Option<bool>, ConfigParseError> { | ||||
match self.get_inner(§ion, &item) { | match self.get_inner(§ion, &item) { | ||||
Some((layer, v)) => match parse_bool(&v.bytes) { | Some((layer, v)) => match parse_bool(&v.bytes) { | ||||
Some(b) => Ok(Some(b)), | Some(b) => Ok(Some(b)), | ||||
None => Err(ConfigError::Parse { | None => Err(ConfigParseError { | ||||
origin: layer.origin.to_owned(), | origin: layer.origin.to_owned(), | ||||
line: v.line, | line: v.line, | ||||
bytes: v.bytes.to_owned(), | bytes: v.bytes.to_owned(), | ||||
}), | }), | ||||
}, | }, | ||||
None => Ok(None), | None => Ok(None), | ||||
} | } | ||||
} | } |
Should read_include be instead using the VFS?