cargo: upgrade the config crate from 0.11.0 to 0.12.0

This required a bit of work.
This commit is contained in:
Martin von Zweigbergk 2022-03-09 18:04:19 -08:00 committed by Martin von Zweigbergk
parent 36a575ccbf
commit 3f24411bbf
10 changed files with 164 additions and 115 deletions

197
Cargo.lock generated
View File

@ -2,6 +2,12 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "ahash"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
name = "aho-corasick"
version = "0.7.18"
@ -11,12 +17,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "assert_cmd"
version = "2.0.4"
@ -37,6 +37,17 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
[[package]]
name = "async-trait"
version = "0.1.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -65,6 +76,12 @@ dependencies = [
"rand",
]
[[package]]
name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bitflags"
version = "1.2.1"
@ -119,7 +136,7 @@ dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde 1.0.126",
"serde",
]
[[package]]
@ -178,7 +195,7 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits 0.2.14",
"num-traits",
"time",
"winapi",
]
@ -231,15 +248,18 @@ dependencies = [
[[package]]
name = "config"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369"
checksum = "54ad70579325f1a38ea4c13412b82241c5900700a69785d73e2736bd65a33f86"
dependencies = [
"async-trait",
"json5",
"lazy_static",
"nom",
"pathdiff",
"ron",
"rust-ini",
"serde 1.0.126",
"serde-hjson",
"serde",
"serde_json",
"toml",
"yaml-rust",
@ -271,12 +291,12 @@ dependencies = [
"csv",
"itertools",
"lazy_static",
"num-traits 0.2.14",
"num-traits",
"oorandom",
"plotters",
"rayon",
"regex",
"serde 1.0.126",
"serde",
"serde_cbor",
"serde_derive",
"serde_json",
@ -367,7 +387,7 @@ dependencies = [
"csv-core",
"itoa 0.4.7",
"ryu",
"serde 1.0.126",
"serde",
]
[[package]]
@ -425,6 +445,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "dlv-list"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b"
dependencies = [
"rand",
]
[[package]]
name = "doc-comment"
version = "0.3.3"
@ -464,7 +493,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
dependencies = [
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -528,6 +557,15 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3"
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [
"ahash",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
@ -567,7 +605,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown",
"hashbrown 0.11.2",
]
[[package]]
@ -587,7 +625,7 @@ checksum = "30a7e1911532a662f6b08b68f884080850f2fd9544963c3ab23a5af42bda1eac"
dependencies = [
"console",
"once_cell",
"serde 1.0.126",
"serde",
"serde_json",
"serde_yaml",
"similar",
@ -641,6 +679,17 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "json5"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1"
dependencies = [
"pest",
"pest_derive",
"serde",
]
[[package]]
name = "jujutsu"
version = "0.3.3"
@ -711,19 +760,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]]
name = "libc"
version = "0.2.97"
@ -813,14 +849,19 @@ dependencies = [
]
[[package]]
name = "nom"
version = "5.1.2"
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
version = "7.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
dependencies = [
"lexical-core",
"memchr",
"version_check",
"minimal-lexical",
]
[[package]]
@ -836,16 +877,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits 0.2.14",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
dependencies = [
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -914,6 +946,16 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "ordered-multimap"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485"
dependencies = [
"dlv-list",
"hashbrown 0.9.1",
]
[[package]]
name = "os_str_bytes"
version = "6.0.0"
@ -923,6 +965,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "percent-encoding"
version = "2.1.0"
@ -984,7 +1032,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a"
dependencies = [
"num-traits 0.2.14",
"num-traits",
"plotters-backend",
"plotters-svg",
"wasm-bindgen",
@ -1225,10 +1273,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rust-ini"
version = "0.13.0"
name = "ron"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
checksum = "1b861ecaade43ac97886a512b360d01d66be9f41f3c61088b42cedf92e03d678"
dependencies = [
"base64",
"bitflags",
"serde",
]
[[package]]
name = "rust-ini"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22"
dependencies = [
"cfg-if",
"ordered-multimap",
]
[[package]]
name = "rustc_version"
@ -1278,12 +1341,6 @@ dependencies = [
"pest",
]
[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]]
name = "serde"
version = "1.0.126"
@ -1293,18 +1350,6 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-hjson"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
dependencies = [
"lazy_static",
"num-traits 0.1.43",
"regex",
"serde 0.8.23",
]
[[package]]
name = "serde_cbor"
version = "0.11.1"
@ -1312,7 +1357,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622"
dependencies = [
"half",
"serde 1.0.126",
"serde",
]
[[package]]
@ -1334,7 +1379,7 @@ checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [
"itoa 1.0.1",
"ryu",
"serde 1.0.126",
"serde",
]
[[package]]
@ -1345,7 +1390,7 @@ checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0"
dependencies = [
"indexmap",
"ryu",
"serde 1.0.126",
"serde",
"yaml-rust",
]
@ -1373,12 +1418,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
version = "0.10.0"
@ -1511,7 +1550,7 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc"
dependencies = [
"serde 1.0.126",
"serde",
"serde_json",
]
@ -1536,7 +1575,7 @@ version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde 1.0.126",
"serde",
]
[[package]]

View File

@ -30,7 +30,7 @@ chrono = "0.4.19"
clap = { version = "3.1.6", features = ["cargo"] }
clap_complete = "3.1.1"
clap_mangen = "0.1"
config = "0.11.0"
config = "0.12.0"
criterion = "0.3.5"
git2 = "0.14.2"
hex = "0.4.3"

View File

@ -22,7 +22,7 @@ blake2 = "0.10.4"
bytes = "1.1.0"
byteorder = "1.4.3"
chrono = "0.4.19"
config = "0.11.0"
config = "0.12.0"
dirs = "4.0.0"
git2 = "0.14.2"
hex = "0.4.3"

View File

@ -35,7 +35,7 @@ const TOO_MUCH_CONFIG_ERROR: &str =
impl UserSettings {
pub fn from_config(config: config::Config) -> Self {
let timestamp = match config.get_str("user.timestamp") {
let timestamp = match config.get_string("user.timestamp") {
Ok(timestamp_str) => match DateTime::parse_from_rfc3339(&timestamp_str) {
Ok(datetime) => Some(Timestamp::from_datetime(datetime)),
Err(_) => None,
@ -46,18 +46,18 @@ impl UserSettings {
}
pub fn for_user() -> Result<Self, config::ConfigError> {
let mut config = config::Config::new();
let mut config_builder = config::Config::builder();
let loaded_from_config_dir = match dirs::config_dir() {
None => false,
Some(config_dir) => {
let p = config_dir.join("jj/config.toml");
let exists = p.exists();
config.merge(
config_builder = config_builder.add_source(
config::File::from(p)
.required(false)
.format(config::FileFormat::Toml),
)?;
);
exists
}
};
@ -71,48 +71,52 @@ impl UserSettings {
TOO_MUCH_CONFIG_ERROR.to_string(),
));
}
config.merge(
config_builder = config_builder.add_source(
config::File::from(p)
.required(false)
.format(config::FileFormat::Toml),
)?;
);
}
let mut env_config = config::Config::new();
// TODO: Make the config from environment a separate source instead? Seems
// cleaner to separate it like that, especially if the config::Config instance
// can keep track of where the config comes from then (it doesn't seem like it
// can, however - we don't give a name or anything to the Config object).
if let Ok(value) = env::var("JJ_USER") {
env_config.set("user.name", value)?;
config_builder = config_builder.set_override("user.name", value)?;
}
if let Ok(value) = env::var("JJ_EMAIL") {
env_config.set("user.email", value)?;
config_builder = config_builder.set_override("user.email", value)?;
}
if let Ok(value) = env::var("JJ_TIMESTAMP") {
env_config.set("user.timestamp", value)?;
config_builder = config_builder.set_override("user.timestamp", value)?;
}
config.merge(env_config)?;
let config = config_builder.build()?;
Ok(Self::from_config(config))
}
pub fn with_repo(&self, repo_path: &Path) -> Result<RepoSettings, config::ConfigError> {
let mut config = self.config.clone();
config.merge(
config::File::from(repo_path.join("config"))
.required(false)
.format(config::FileFormat::Toml),
)?;
let config = config::Config::builder()
.add_source(self.config.clone())
.add_source(
config::File::from(repo_path.join("config"))
.required(false)
.format(config::FileFormat::Toml),
)
.build()?;
Ok(RepoSettings { _config: config })
}
pub fn user_name(&self) -> String {
self.config
.get_str("user.name")
.get_string("user.name")
.unwrap_or_else(|_| "(no name configured)".to_string())
}
pub fn user_email(&self) -> String {
self.config
.get_str("user.email")
.get_string("user.email")
.unwrap_or_else(|_| "(no email configured)".to_string())
}

View File

@ -42,9 +42,13 @@ pub fn new_user_home() -> TempDir {
}
pub fn user_settings() -> UserSettings {
let mut config = config::Config::new();
config.set("user.name", "Test User").unwrap();
config.set("user.email", "test.user@example.com").unwrap();
let config = config::Config::builder()
.set_override("user.name", "Test User")
.unwrap()
.set_override("user.email", "test.user@example.com")
.unwrap()
.build()
.unwrap();
UserSettings::from_config(config)
}

View File

@ -99,10 +99,12 @@ fn test_rewrite(use_git: bool) {
],
);
let mut config = config::Config::new();
config.set("user.name", "Rewrite User").unwrap();
config
.set("user.email", "rewrite.user@example.com")
let config = config::Config::builder()
.set_override("user.name", "Rewrite User")
.unwrap()
.set_override("user.email", "rewrite.user@example.com")
.unwrap()
.build()
.unwrap();
let rewrite_settings = UserSettings::from_config(config);
let mut tx = repo.start_transaction("test");

View File

@ -71,7 +71,7 @@ fn test_init_external_git() {
#[test_case(true ; "git backend")]
fn test_init_no_config_set(use_git: bool) {
// Test that we can create a repo without setting any config
let settings = UserSettings::from_config(config::Config::new());
let settings = UserSettings::from_config(config::Config::default());
let test_workspace = testutils::init_workspace(&settings, use_git);
let repo = &test_workspace.repo;
let checkout_id = repo.view().get_checkout(&WorkspaceId::default()).unwrap();

View File

@ -2129,7 +2129,7 @@ fn show_diff(
} else if args.is_present("color-words") {
Format::ColorWords
} else {
match ui.settings().config().get_str("diff.format") {
match ui.settings().config().get_string("diff.format") {
Ok(value) if &value == "summary" => Format::Summary,
Ok(value) if &value == "git" => Format::Git,
Ok(value) if &value == "color-words" => Format::ColorWords,
@ -2709,7 +2709,7 @@ fn log_template(settings: &UserSettings) -> String {
)"#;
settings
.config()
.get_str("template.log.graph")
.get_string("template.log.graph")
.unwrap_or_else(|_| String::from(default_template))
}
@ -4545,7 +4545,7 @@ fn resolve_alias(ui: &mut Ui, args: Vec<String>) -> Vec<String> {
{
let mut resolved_args = vec![args[0].clone()];
for arg in alias_definition {
match arg.into_str() {
match arg.into_string() {
Ok(string_arg) => resolved_args.push(string_arg),
Err(err) => {
ui.write_error(&format!(

View File

@ -133,7 +133,7 @@ pub fn edit_diff(
// best one here.
let editor_binary = settings
.config()
.get_str("ui.diff-editor")
.get_string("ui.diff-editor")
.unwrap_or_else(|_| "meld".to_string());
// Start a diff editor on the two directories.
let exit_status = Command::new(&editor_binary)

View File

@ -67,7 +67,7 @@ impl<'stdout> Ui<'stdout> {
let stdout: Box<dyn Write + 'static> = Box::new(io::stdout());
let color_setting = settings
.config()
.get_str("ui.color")
.get_string("ui.color")
.unwrap_or_else(|_| "auto".to_string());
let color = match color_setting.as_str() {
"always" => true,
@ -122,7 +122,7 @@ impl<'stdout> Ui<'stdout> {
let template_string = self
.settings
.config()
.get_str("template.commit_summary")
.get_string("template.commit_summary")
.unwrap_or_else(|_| {
String::from(
r#"label(if(open, "open"), commit_id.short() " " description.first_line())"#,