Print a deterministic length of commit hash in --version

This commit is contained in:
David Tolnay 2024-07-29 19:01:39 -07:00 committed by Yacin Tmimi
parent a1361bd0d5
commit 17c5869dff

View File

@ -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<String> {
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<String> {