File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 1919
2020use std:: process:: Command ;
2121
22+ const UNKNOWN : & str = "unknown" ;
23+
2224fn main ( ) {
23- let git_commit_hash = Command :: new ( "git" )
24- . args ( & [ "rev-parse" , "HEAD" ] )
25- . output ( )
26- . map_or ( "unknown" . to_string ( ) , |output| {
27- let hash = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
28- String :: from ( & hash[ ..7 ] )
29- } ) ;
30- println ! ( "cargo:rustc-env=GIT_COMMIT_HASH={}" , git_commit_hash) ;
25+ println ! ( "cargo:rustc-env=GIT_COMMIT_HASH={}" , git_rev_parse_head( ) ) ;
26+ }
27+
28+ fn git_rev_parse_head ( ) -> String {
29+ let mut stdout = match Command :: new ( "git" ) . args ( & [ "rev-parse" , "HEAD" ] ) . output ( ) {
30+ Ok ( output) if output. status . success ( ) => output. stdout ,
31+ _ => return UNKNOWN . to_string ( ) ,
32+ } ;
33+ stdout. truncate ( 7 ) ;
34+ String :: from_utf8 ( stdout) . unwrap_or_else ( |_| UNKNOWN . to_string ( ) )
3135}
You can’t perform that action at this time.
0 commit comments