Add cmpTraitInit and fix git-func

This commit is contained in:
cmp167
2023-09-10 09:49:34 +12:00
parent 6ee83b4b82
commit 1a837f46dd

View File

@@ -634,59 +634,127 @@
function getGitStatus() {
$ret = $this->fgExec("git status");
function getGitStatus($dir = ".") {
$a = array(
"git", "status", "--porcelain"
);
// $this->d(join("\n", $ret));
$gitStatus = $this->cmpSysExec($a, ["workDir" => $dir]);
$out = trim($ret["output"], "\n \t\r");
if(!$out) {
$this->d($ret["stderr"][0]);
return false;
if($gitStatus["retval"]) {
$this->d("GIT have errors");
$this->d($gitStatus["stderr"]);
return ;
}
$lin = explode("\n", $out);
$cnt = count($lin);
if($lin[$cnt-1] == "nothing to commit, working tree clean") {
$this->gitStatus = "treeClean";
$this->d("Git tree clean");
} else {
$this->gitStatus = "treeModified";
$this->d("Last string: " . $lin[$cnt-1]);
if(!$gitStatus["stdout"]) {
return null;
}
return;
$this->w("GIT have changes");
$arr = explode("\n", $gitStatus["stdout"]);
$ret = array();
for($i = 0; $i < count($arr); $i++) {
$arr[$i] = trim($arr[$i], "\n \r\t");
if(!$arr[$i])
continue;
$ff = explode(" ", $arr[$i], 2);
$this->d("flag=" . $ff[0] . " file=" . $ff[1]);
$ret[] = $ff;
}
// $this->d($ret);
return $ret;
}
function getGitLog1() {
$ret = $this->fgExec("git log -1");
function getGitLog1($dir = ".") {
// https://git-scm.com/docs/pretty-formats
$frmReq = array(
array("commitHash", "H" ),
array("commitDate", "ci"),
array("commitTStm", "ct"),
array("authorMail", "ae")
);
// $this->d(join("\n", $ret));
$frmArr = array();
$out = trim($ret["output"], "\n \t\r");
for($i = 0; $i < count($frmReq); $i++)
$frmArr[] = "%" . $frmReq[$i][1];
if(!$out) {
$this->d($ret["stderr"][0]);
return false;
$frmStr = join("%n", $frmArr);
$a = array(
"git", "log", "--pretty=format:$frmStr", "-1"
);
$gitCommit = $this->cmpSysExec($a, ["workDir" => $dir]);
if($gitCommit["retval"]) {
$this->d("GIT have errors");
$this->d($gitCommit["stderr"]);
return null;
}
$lin = explode("\n", $out);
$cnt = count($lin);
$b = explode("\n", $gitCommit["stdout"]);
$wrd = explode(" ", $lin[0]);
$this->gitCommit = $wrd[1];
$frmRet = array();
$this->gitComment = $lin[$cnt-1];
for($i = 0; $i < count($frmReq); $i++)
$frmRet[ $frmReq[$i][0] ] = $b[$i];
$wrd = explode(" ", $lin[2]);
array_shift($wrd);
$this->gitTimeStamp = strtotime(join(" ", $wrd));
return;
return $frmRet;
}
function cmpTraitInit($obj, $lvl = 0) {
$listTrait = class_uses($obj);
foreach($listTrait as $trait) {
$this->d("Used trait $trait");
do {
$traitRoot = OUT_PROJ_DIR . "/" . $trait;
$traitGit = $traitRoot . "/.git";
if(!is_dir($traitGit))
break;
$ret = $this->getGitStatus($traitRoot);
$ret = $this->getGitLog1($traitRoot);
$this->d($ret);
} while(0);
$this->cmpTraitInit($trait, $lvl+1);
$initMeth = $trait . "Init";
if(!method_exists($this, $initMeth)) {
// $this->d("No method $initMeth");
continue;
}
$parm = null;
if(isset($this->parm[$trait])) {
// $this->d("Found parm");
$parm = $this->parm[$trait];
}
$this->swoSelfCall(array("func" => $initMeth, "parm" => $parm));
}
return true;
}
function isMD5($str) {
if(preg_match("/^[0-9a-f]{32}$/", $str))
return true;