From 0e42c6b9b19c9504910adec1e565e1467f9f1e0b Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 3 Apr 2020 13:15:34 +0200 Subject: [PATCH] version-helper: git: return the commit date as well --- gst-plugin-version-helper/src/git.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/gst-plugin-version-helper/src/git.rs b/gst-plugin-version-helper/src/git.rs index 7e013113..2bd188dc 100644 --- a/gst-plugin-version-helper/src/git.rs +++ b/gst-plugin-version-helper/src/git.rs @@ -1,25 +1,30 @@ use std::path::Path; use std::process::Command; -pub fn repo_hash>(path: P) -> Option { +pub fn repo_hash>(path: P) -> Option<(String, String)> { let git_path = path.as_ref().to_str(); let mut args = match git_path { Some(path) => vec!["-C", path], None => vec![], }; - args.extend(&["rev-parse", "--short", "HEAD"]); + args.extend(&["log", "-1", "--format=%h_%cd", "--date=short"]); let output = Command::new("git").args(&args).output().ok()?; if !output.status.success() { return None; } - let hash = String::from_utf8(output.stdout).ok()?; - let hash = hash.trim_end_matches('\n'); + let output = String::from_utf8(output.stdout).ok()?; + let output = output.trim_end_matches('\n'); + let mut s = output.split('_'); + let hash = s.next()?; + let date = s.next()?; - if dirty(path) { - Some(format!("{}+", hash)) + let hash = if dirty(path) { + format!("{}+", hash) } else { - Some(hash.into()) - } + hash.into() + }; + + Some((hash, date.into())) } fn dirty>(path: P) -> bool {