Fix git status parsing

This commit is contained in:
John Doty 2024-08-08 07:18:13 -07:00
parent b8fe678ff0
commit a3fa032500

View file

@ -52,8 +52,9 @@ fn emit_git_commit() {
eprintln!("`git rev-parse --short HEAD` failed, stderr: {stderr}"); eprintln!("`git rev-parse --short HEAD` failed, stderr: {stderr}");
panic!("`git rev-parse --short HEAD` failed"); panic!("`git rev-parse --short HEAD` failed");
} }
let rev = let rev = std::str::from_utf8(&output.stdout)
std::str::from_utf8(&output.stdout).expect("git did not output utf8"); .expect("git did not output utf8")
.trim();
println!("cargo::rustc-env=REPO_REV={rev}"); println!("cargo::rustc-env=REPO_REV={rev}");
} }
@ -86,13 +87,20 @@ fn emit_git_dirty() {
// If there *was* any output, parse it and tell cargo to re-run if any of // If there *was* any output, parse it and tell cargo to re-run if any of
// these files changed. (Maybe they get reverted! Then the repo status // these files changed. (Maybe they get reverted! Then the repo status
// will change.) // will change.)
for line in output.lines() { let mut split = output.split('\x00');
let fields: Vec<_> = line.split('\x00').collect(); while let Some(field) = split.next() {
let parts: Vec<_> = fields[0].split(' ').collect(); if field.is_empty() {
let path = parts[1]; continue;
println!("cargo::rerun-if-changed={path}"); }
let prefix = &field[0..3];
println!("cargo::rerun-if-changed={}", &field[3..]);
let b = prefix.as_bytes();
if b[0] == b'R' || b[1] == b'R' || b[0] == b'C' || b[1] == b'C' {
if let Some(additional) = split.next() {
println!("cargo::rerun-if-changed={additional}");
}
}
} }
// Emit the repository status. // Emit the repository status.
let dirty = if output.trim().is_empty() { let dirty = if output.trim().is_empty() {
"" ""