diff --git a/mountpoint-s3/src/build_info.rs b/mountpoint-s3/src/build_info.rs index 0dfefd01d..26eb2bfa1 100644 --- a/mountpoint-s3/src/build_info.rs +++ b/mountpoint-s3/src/build_info.rs @@ -12,21 +12,7 @@ pub const FULL_VERSION: &str = { if is_official_aws_release() { built::PKG_VERSION } else { - // A little hacky so we can pull out the hash as a const - const COMMIT_HASH_STR: &str = match built::GIT_COMMIT_HASH_SHORT { - Some(hash) => hash, - None => "", - }; - const COMMIT_DIRTY_STR: &str = match built::GIT_DIRTY { - Some(true) => "-dirty", - _ => "", - }; - const UNOFFICIAL_SUFFIX: &str = if COMMIT_HASH_STR.is_empty() { - "-unofficial" - } else { - const_format::concatcp!("-unofficial+", COMMIT_HASH_STR, COMMIT_DIRTY_STR) - }; - const_format::concatcp!(built::PKG_VERSION, UNOFFICIAL_SUFFIX) + const_format::concatcp!(built::PKG_VERSION, "-unofficial", git_commit_suffix()) } }; @@ -34,3 +20,22 @@ pub const FULL_VERSION: &str = { const fn is_official_aws_release() -> bool { option_env!("MOUNTPOINT_S3_AWS_RELEASE").is_some() } + +/// Formats the current git commit hash and dirty state as a version suffix. +/// Returns the empty string if building outside a git repository. +const fn git_commit_suffix() -> &'static str { + if built::GIT_COMMIT_HASH_SHORT.is_none() { + return ""; + } + // A little hacky so we can pull out the hash as a const + const COMMIT_HASH_STR: &str = match built::GIT_COMMIT_HASH_SHORT { + Some(hash) => hash, + // Evaluated at compile time, but never used + None => "unreachable", + }; + const COMMIT_DIRTY_STR: &str = match built::GIT_DIRTY { + Some(true) => "-dirty", + _ => "", + }; + const_format::concatcp!("+", COMMIT_HASH_STR, COMMIT_DIRTY_STR) +}