Skip to content

Commit c2d9f96

Browse files
committed
Print a deterministic length of commit hash in --version
1 parent a1361bd commit c2d9f96

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

build.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
// (git not installed or if this is not a git repository) just return an empty string.
2626
fn commit_info() -> String {
2727
match (channel(), commit_hash(), commit_date()) {
28-
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_end(), date),
28+
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash, date),
2929
_ => String::new(),
3030
}
3131
}
@@ -39,11 +39,13 @@ fn channel() -> String {
3939
}
4040

4141
fn commit_hash() -> Option<String> {
42-
Command::new("git")
43-
.args(["rev-parse", "--short", "HEAD"])
42+
let output = Command::new("git")
43+
.args(["rev-parse", "HEAD"])
4444
.output()
45-
.ok()
46-
.and_then(|r| String::from_utf8(r.stdout).ok())
45+
.ok()?;
46+
let mut stdout = String::from_utf8(output.stdout).ok()?;
47+
stdout.truncate(10);
48+
Some(stdout)
4749
}
4850

4951
fn commit_date() -> Option<String> {

0 commit comments

Comments
 (0)