From 931abe1f13253367944826ae06ca78779388f7c8 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sun, 15 Sep 2024 18:19:38 +0900 Subject: [PATCH] Normalize version given via GIT_CINNABAR_VERSION --- src/version.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/version.rs b/src/version.rs index 6f60421c..44ff28a0 100644 --- a/src/version.rs +++ b/src/version.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::borrow::{Borrow, Cow}; +use std::borrow::Cow; use std::str::FromStr; use derive_more::Display; @@ -158,7 +158,7 @@ mod static_ { pub const FULL_VERSION: &str = full_version!(SHORT_VERSION, BUILD_COMMIT, MODIFIED, cat); } -fn value<'a, T: 'a + ConfigType + ?Sized, F: FnOnce(&T) -> bool>( +fn value<'a, T: 'a + ConfigType + ?Sized, F: FnOnce(T::Owned) -> Option>( config: &str, static_value: &'a T, filter: F, @@ -166,7 +166,7 @@ fn value<'a, T: 'a + ConfigType + ?Sized, F: FnOnce(&T) -> bool>( if let Some(value) = experiment(Experiments::TEST) .then(|| get_typed_config::(config)) .flatten() - .filter(|x| filter(x.borrow())) + .and_then(filter) { Cow::Owned(value) } else { @@ -176,7 +176,7 @@ fn value<'a, T: 'a + ConfigType + ?Sized, F: FnOnce(&T) -> bool>( macro_rules! value { ($config:expr, $static_value:expr) => { - value!($config, $static_value, |_| true) + value!($config, $static_value, |x| Some(x)) }; ($config:expr, $static_value:expr, $filter:expr) => { Lazy::new(|| value($config, $static_value, $filter)) @@ -190,10 +190,12 @@ fn is_overridden(value: &Value) -> bool { } pub static SHORT_VERSION: Value = - value!("version", static_::SHORT_VERSION, |v| Version::parse(v) - .is_ok()); -pub static BUILD_COMMIT: Value = value!("commit", static_::BUILD_COMMIT, |c| c.is_empty() - || CommitId::from_str(c).is_ok()); + value!("version", static_::SHORT_VERSION, |v| Version::parse(&v) + .ok() + .map(|v| v.to_string())); +pub static BUILD_COMMIT: Value = value!("commit", static_::BUILD_COMMIT, |c| (c.is_empty() + || CommitId::from_str(&c).is_ok()) +.then_some(c)); static MODIFIED: Value = value!("modified", &static_::MODIFIED); #[cfg(any(feature = "version-check", feature = "self-update"))] pub static BUILD_BRANCH: Lazy = Lazy::new(|| {