performance-metrics: Produce some error messages if git commands fail

It is reasonable for these to fail as it the tool could be run outside
of a git repository but by not giving any error message we cannot see
issues when we expect the report to have the git details.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-06-10 15:39:04 +01:00
parent ada85f68f6
commit cac42301f8

View File

@ -53,18 +53,30 @@ impl Default for MetricsReport {
let mut git_human_readable = "".to_string();
if let Ok(git_out) = Command::new("git").args(&["describe", "--dirty"]).output() {
if git_out.status.success() {
if let Ok(git_out_str) = String::from_utf8(git_out.stdout) {
git_human_readable = git_out_str.trim().to_string();
}
git_human_readable = String::from_utf8(git_out.stdout)
.unwrap()
.trim()
.to_string();
} else {
eprintln!(
"Error generating human readable git reference: {}",
String::from_utf8(git_out.stderr).unwrap()
);
}
}
let mut git_revision = "".to_string();
if let Ok(git_out) = Command::new("git").args(&["rev-parse", "HEAD"]).output() {
if git_out.status.success() {
if let Ok(git_out_str) = String::from_utf8(git_out.stdout) {
git_revision = git_out_str.trim().to_string();
}
git_revision = String::from_utf8(git_out.stdout)
.unwrap()
.trim()
.to_string();
} else {
eprintln!(
"Error generating git reference: {}",
String::from_utf8(git_out.stderr).unwrap()
);
}
}
@ -74,9 +86,15 @@ impl Default for MetricsReport {
.output()
{
if git_out.status.success() {
if let Ok(git_out_str) = String::from_utf8(git_out.stdout) {
git_commit_date = git_out_str.trim().to_string();
}
git_commit_date = String::from_utf8(git_out.stdout)
.unwrap()
.trim()
.to_string();
} else {
eprintln!(
"Error generating git commit date: {}",
String::from_utf8(git_out.stderr).unwrap()
);
}
}