mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-24 11:00:29 +00:00
version-helper: copy git.rs from gtk-rs/gir
Bare copy from https://github.com/gtk-rs/gir/blob/master/src/git.rs
This commit is contained in:
parent
9ec6a02e13
commit
bbdf90d67c
1 changed files with 36 additions and 0 deletions
36
gst-plugin-version-helper/src/git.rs
Normal file
36
gst-plugin-version-helper/src/git.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn repo_hash<P: AsRef<Path>>(path: P) -> Option<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"]);
|
||||
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');
|
||||
|
||||
if dirty(path) {
|
||||
Some(format!("{}+", hash))
|
||||
} else {
|
||||
Some(hash.into())
|
||||
}
|
||||
}
|
||||
|
||||
fn dirty<P: AsRef<Path>>(path: P) -> bool {
|
||||
let path = path.as_ref().to_str();
|
||||
let mut args = match path {
|
||||
Some(path) => vec!["-C", path],
|
||||
None => vec![],
|
||||
};
|
||||
args.extend(&["ls-files", "-m"]);
|
||||
match Command::new("git").args(&args).output() {
|
||||
Ok(modified_files) => !modified_files.stdout.is_empty(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue