Skip to content

Commit

Permalink
Print a deterministic length of commit hash in --version
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 30, 2024
1 parent cf352a7 commit 8d6bb40
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand All @@ -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> {
Expand Down

0 comments on commit 8d6bb40

Please sign in to comment.