Skip to content

Commit

Permalink
Clean up Git info a bit
Browse files Browse the repository at this point in the history
Remove an extraneous newline, and pass `--git-dir` to `git` to ensure that
out-of-repo builds don't accidentally pick up a parent repo's info.
  • Loading branch information
ISSOtm committed Dec 17, 2023
1 parent 67720c2 commit b094467
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions preproc/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ pub struct Commit {
impl Commit {
pub fn rev_parse(what: &str) -> Result<Self, Error> {
let output = Command::new("git")
.args(["show", "-s", "--format=%H%x00%h%x00%ci", what])
.args([
"--git-dir=.git",
"show",
"-s",
"--format=%H%x00%h%x00%ci",
what,
])
.stderr(Stdio::inherit())
.stdin(Stdio::null())
.output()
Expand All @@ -31,15 +37,18 @@ impl Commit {
output.status
)));
}
let info = String::from_utf8(output.stdout).expect("Commit info is not valid UTF-8??");
let mut info = String::from_utf8(output.stdout).expect("Commit info is not valid UTF-8??");
let trimmed_len = info.trim_end().len();
info.truncate(trimmed_len);

let first_split = info
.find('\0')
.expect("Failed to split hash and short hash");
let second_split = info[first_split + 1..]
.find('\0')
.expect("Failed to split short hash and timestamp")
+ first_split;
+ first_split
+ 1;

Ok(Self {
info,
Expand Down

0 comments on commit b094467

Please sign in to comment.