From abbea6a4a20ed1562d99ce5942154352bc545eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 21 Mar 2021 14:59:03 +0100 Subject: commit_hash returns option instead --- mumd/build.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'mumd') diff --git a/mumd/build.rs b/mumd/build.rs index 45cfd4e..f09b1c4 100644 --- a/mumd/build.rs +++ b/mumd/build.rs @@ -5,21 +5,17 @@ fn main() { "{} {}-{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), - commit_hash(), + commit_hash().unwrap_or_else(|| "???".to_string()), ); println!("cargo:rustc-env=VERSION={}", version); } -fn commit_hash() -> String { +fn commit_hash() -> Option { let output = Command::new("git") .arg("show") .arg("--pretty=format:%h") // abbrev hash .current_dir(env!("CARGO_MANIFEST_DIR")) .output(); - if let Ok(output) = output { - String::from_utf8_lossy(&output.stdout).to_string() - } else { - String::from("???") - } + output.ok().map(|o| String::from_utf8_lossy(&o.stdout).to_string()) } -- cgit v1.2.1