Speed-up git info tasks
Publish PHP Package / docker (push) Successful in 8s
Details
Publish PHP Package / docker (push) Successful in 8s
Details
This commit is contained in:
parent
9bfc1fea7e
commit
9500897b1e
|
@ -604,49 +604,66 @@ function rrmdir(string $dir, bool $remove_top_dir = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_get_info() : array
|
define("GIT_INFO_REV_HASH" , 1 << 0);
|
||||||
|
define("GIT_INFO_BRANCH" , 1 << 1);
|
||||||
|
define("GIT_INFO_REV_NUMBER", 1 << 2);
|
||||||
|
define("GIT_INFO_ALL" , ~0);
|
||||||
|
|
||||||
|
function git_get_info($info = GIT_INFO_ALL) : array
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
|
$rev_hash = "";
|
||||||
|
$branch = "";
|
||||||
|
$revision_number = 0;
|
||||||
|
|
||||||
if(!is_dir("$GAME_ROOT/.git"))
|
if(!is_dir("$GAME_ROOT/.git"))
|
||||||
throw new Exception("Not a Git repository");
|
throw new Exception("Not a Git repository");
|
||||||
|
|
||||||
$out = array();
|
if($info & GIT_INFO_REV_HASH)
|
||||||
exec("git rev-parse HEAD", $out);
|
{
|
||||||
$rev_hash = trim($out[0]);
|
$out = array();
|
||||||
if(!$rev_hash)
|
exec("git rev-parse HEAD", $out);
|
||||||
throw new Exception("Error getting git revision hash");
|
$rev_hash = trim($out[0]);
|
||||||
|
if(!$rev_hash)
|
||||||
|
throw new Exception("Error getting git revision hash");
|
||||||
|
}
|
||||||
|
|
||||||
$out = array();
|
if($info & GIT_INFO_BRANCH)
|
||||||
exec("git rev-parse --abbrev-ref HEAD", $out);
|
{
|
||||||
$branch = trim($out[0]);
|
$out = array();
|
||||||
if(!$branch)
|
exec("git rev-parse --abbrev-ref HEAD", $out);
|
||||||
throw new Exception("Error getting git branch");
|
$branch = trim($out[0]);
|
||||||
|
if(!$branch)
|
||||||
|
throw new Exception("Error getting git branch");
|
||||||
|
}
|
||||||
|
|
||||||
$out = array();
|
if($info & GIT_INFO_REV_NUMBER)
|
||||||
exec("git rev-list HEAD --count", $out);
|
{
|
||||||
$revision_number = (int)$out[0];
|
$out = array();
|
||||||
if(!$revision_number)
|
exec("git rev-list HEAD --count", $out);
|
||||||
throw new Exception("Error getting git revision number");
|
$revision_number = (int)$out[0];
|
||||||
|
if(!$revision_number)
|
||||||
|
throw new Exception("Error getting git revision number");
|
||||||
|
}
|
||||||
|
|
||||||
return array($rev_hash, $branch, $revision_number);
|
return array($rev_hash, $branch, $revision_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_get_rev_hash() : string
|
function git_get_rev_hash() : string
|
||||||
{
|
{
|
||||||
list($rev_hash, $_, $__) = git_get_info();
|
list($rev_hash, $_, $__) = git_get_info(GIT_INFO_REV_HASH);
|
||||||
return $rev_hash;
|
return $rev_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_get_branch() : string
|
function git_get_branch() : string
|
||||||
{
|
{
|
||||||
list($_, $branch, $__) = git_get_info();
|
list($_, $branch, $__) = git_get_info(GIT_INFO_BRANCH);
|
||||||
return $branch;
|
return $branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_get_rev_number() : string
|
function git_get_rev_number() : string
|
||||||
{
|
{
|
||||||
list($_, $__, $rev_number) = git_get_info();
|
list($_, $__, $rev_number) = git_get_info(GIT_INFO_REV_NUMBER);
|
||||||
return $rev_number;
|
return $rev_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue