From c2d9f96d8305a61a3b57e1fc4c203d29323ecbff Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 29 Jul 2024 19:01:39 -0700 Subject: [PATCH] Print a deterministic length of commit hash in --version --- build.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/build.rs b/build.rs index 9a8bb77a8ed..8e1ed287159 100644 --- a/build.rs +++ b/build.rs @@ -25,7 +25,7 @@ fn main() { // (git not installed or if this is not a git repository) just return an empty string. fn commit_info() -> String { match (channel(), commit_hash(), commit_date()) { - (channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_end(), date), + (channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash, date), _ => String::new(), } } @@ -39,11 +39,13 @@ fn channel() -> String { } fn commit_hash() -> Option { - Command::new("git") - .args(["rev-parse", "--short", "HEAD"]) + let output = Command::new("git") + .args(["rev-parse", "HEAD"]) .output() - .ok() - .and_then(|r| String::from_utf8(r.stdout).ok()) + .ok()?; + let mut stdout = String::from_utf8(output.stdout).ok()?; + stdout.truncate(10); + Some(stdout) } fn commit_date() -> Option {