Merge branch 'liyuchun_65972' into 'zenops_44'

* Finish task #65982.

See merge request easycorp/zentaopms!5081
This commit is contained in:
孙广明
2022-08-24 06:32:02 +00:00
11 changed files with 266 additions and 69 deletions
+2
View File
@@ -258,3 +258,5 @@ UPDATE `zt_grouppriv` SET `module` = 'product' WHERE `module` = 'story' and `met
ALTER TABLE `zt_job` ADD `lastSyncDate` datetime DEFAULT NULL AFTER `lastTag`;
INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES ('*/5', '*', '*', '*', '*', 'moduleName=compile&methodName=syncCompile', '定时同步构建记录', 'zentao', 1, 'normal', '0000-00-00 00:00:00');
ALTER TABLE `zt_repofiles` ADD `oldPath` varchar(255) DEFAULT '' AFTER `path`;
+9 -4
View File
@@ -213,6 +213,8 @@ class Gitea
if(!scm::checkRevision($fromRevision)) return array();
if(!scm::checkRevision($toRevision)) return array();
execCmd(escapeCmd("$this->client pull"));
$path = ltrim($path, DIRECTORY_SEPARATOR);
$count = $count == 0 ? '' : "-n $count";
/* compatible with svn. */
@@ -611,6 +613,7 @@ class Gitea
$parsedFile = new stdclass();
$parsedFile->revision = $hash;
$parsedFile->path = '/' . trim($path);
$parsedFile->oldPath = isset($file[2]) ? '/' . trim($file[2]) : '';
$parsedFile->type = 'file';
$parsedFile->action = $action;
$logs['files'][$hash][] = $parsedFile;
@@ -683,12 +686,14 @@ class Gitea
}
elseif(strpos($line, "\t") !== false)
{
list($action, $entry) = explode("\t", $line);
$lineList = explode("\t", $line);
list($action, $entry) = $lineList;
$entry = '/' . trim($entry);
$pathInfo = array();
$pathInfo['action'] = $action;
$pathInfo['kind'] = 'file';
$changes[$entry] = $pathInfo;
$pathInfo['action'] = $action;
$pathInfo['kind'] = 'file';
$pathInfo['oldPath'] = isset($lineList[2]) ? '/' . trim($lineList[2]) : '';
$changes[$entry] = $pathInfo;
}
}
+7 -5
View File
@@ -342,7 +342,7 @@ class gitlab
if(!scm::checkRevision($revision)) return false;
if($revision == 'HEAD' and $this->branch) $revision = $this->branch;
$file = $this->files($entry, $revision);
return base64_decode($file->content);
return isset($file->content) ? base64_decode($file->content) : '';
}
/**
@@ -688,7 +688,7 @@ class gitlab
/**
* Get files by commit.
*
* @param string $commit
* @param string $commit
* @access public
* @return void
*/
@@ -717,8 +717,9 @@ class gitlab
$file->revision = $revision;
$file->path = '/' . $row->new_path;
$file->type = 'file';
$file->oldPath = '/' . $row->old_path;
$file->action = 'M';
$file->action = 'M';
if($row->new_file) $file->action = 'A';
if($row->renamed_file) $file->action = 'R';
if($row->deleted_file) $file->action = 'D';
@@ -827,8 +828,9 @@ class gitlab
foreach($commit->diffs as $diff)
{
$parsedLog->change[$diff->path] = array();
$parsedLog->change[$diff->path]['action'] = $diff->action;
$parsedLog->change[$diff->path]['kind'] = $diff->type;
$parsedLog->change[$diff->path]['action'] = $diff->action;
$parsedLog->change[$diff->path]['kind'] = $diff->type;
$parsedLog->change[$diff->path]['oldPath'] = $diff->oldPath;
}
$parsedLogs[] = $parsedLog;
}
+10 -5
View File
@@ -199,6 +199,8 @@ class GitRepo
if(!scm::checkRevision($fromRevision)) return array();
if(!scm::checkRevision($toRevision)) return array();
execCmd(escapeCmd("$this->client pull"));
$path = ltrim($path, DIRECTORY_SEPARATOR);
$count = $count == 0 ? '' : "-n $count";
/* compatible with svn. */
@@ -594,9 +596,10 @@ class GitRepo
$parsedFile = new stdclass();
$parsedFile->revision = $hash;
$parsedFile->path = '/' . trim($path);
$parsedFile->oldPath = isset($file[2]) ? '/' . trim($file[2]) : '';
$parsedFile->type = 'file';
$parsedFile->action = $action;
$logs['files'][$hash][] = $parsedFile;
$logs['files'][$hash][] = $parsedFile;
}
}
return $logs;
@@ -667,12 +670,14 @@ class GitRepo
}
elseif(strpos($line, "\t") !== false)
{
list($action, $entry) = explode("\t", $line);
$lineList = explode("\t", $line);
list($action, $entry) = $lineList;
$entry = '/' . trim($entry);
$pathInfo = array();
$pathInfo['action'] = $action;
$pathInfo['kind'] = 'file';
$changes[$entry] = $pathInfo;
$pathInfo['action'] = $action;
$pathInfo['kind'] = 'file';
$pathInfo['oldPath'] = isset($lineList[2]) ? '/' . trim($lineList[2]) : '';
$changes[$entry] = $pathInfo;
}
}
+9 -4
View File
@@ -213,6 +213,8 @@ class Gogs
if(!scm::checkRevision($fromRevision)) return array();
if(!scm::checkRevision($toRevision)) return array();
execCmd(escapeCmd("$this->client pull"));
$path = ltrim($path, DIRECTORY_SEPARATOR);
$count = $count == 0 ? '' : "-n $count";
/* compatible with svn. */
@@ -611,6 +613,7 @@ class Gogs
$parsedFile = new stdclass();
$parsedFile->revision = $hash;
$parsedFile->path = '/' . trim($path);
$parsedFile->oldPath = isset($file[2]) ? '/' . trim($file[2]) : '';
$parsedFile->type = 'file';
$parsedFile->action = $action;
$logs['files'][$hash][] = $parsedFile;
@@ -704,12 +707,14 @@ class Gogs
}
elseif(strpos($line, "\t") !== false)
{
list($action, $entry) = explode("\t", $line);
$lineList = explode("\t", $line);
list($action, $entry) = $lineList;
$entry = '/' . trim($entry);
$pathInfo = array();
$pathInfo['action'] = $action;
$pathInfo['kind'] = 'file';
$changes[$entry] = $pathInfo;
$pathInfo['action'] = $action;
$pathInfo['kind'] = 'file';
$pathInfo['oldPath'] = isset($lineList[2]) ? '/' . trim($lineList[2]) : '';
$changes[$entry] = $pathInfo;
}
}
+12
View File
@@ -284,6 +284,18 @@ class scm
{
return $this->engine->getAllFiles($path, $revision);
}
/**
* Get files by commit.
*
* @param string $commit
* @access public
* @return array
*/
public function getFilesByCommit($revision)
{
return $this->engine->getFilesByCommit($revision);
}
}
/**
+1
View File
@@ -26,6 +26,7 @@ $config->repo->syncTime = 10;
$config->repo->batchNum = 100;
$config->repo->images = '|png|gif|jpg|ico|jpeg|bmp|';
$config->repo->binary = '|pdf|';
$config->repo->synced = '';
$config->repo->editor = new stdclass();
$config->repo->editor->create = array('id' => 'desc', 'tools' => 'simpleTools');
+30 -48
View File
@@ -511,10 +511,8 @@ class repo extends control
$this->repo->setRepoBranch('');
}
/* Decrypt path and get cacheFile. */
$path = $this->repo->decodePath($path);
$cacheFile = $this->repo->getCacheFile($repoID, $path, $revision);
$this->scm->setEngine($repo);
/* Decrypt path. */
$path = $this->repo->decodePath($path);
/* Load pager. */
$this->app->loadClass('pager', $static = true);
@@ -528,58 +526,29 @@ class repo extends control
$this->locate($this->repo->createLink('diff', "repoID=$repoID&objectID=$objectID&entry=" . $this->repo->encodePath($path) . "&oldrevision=$oldRevision&newRevision=$newRevision"));
}
/* Cache infos. */
if($refresh or !$cacheFile or !file_exists($cacheFile) or (time() - filemtime($cacheFile)) / 60 > $this->config->repo->cacheTime)
/* Refresh repo. */
if($refresh)
{
/* Get cache infos. */
$infos = $this->scm->ls($path, $revision);
/* Update code commit history. */
$commentGroup = $this->loadModel('job')->getTriggerGroup('commit', array($repo->id));
if($infos)
if(in_array($repo->SCM, $this->config->repo->gitTypeList))
{
/* Update code commit history. */
$commentGroup = $this->loadModel('job')->getTriggerGroup('commit', array($repo->id));
if($refresh and in_array($repo->SCM, $this->config->repo->gitTypeList))
{
$branch = $this->cookie->repoBranch;
$this->loadModel('git')->updateCommit($repo, $commentGroup, false);
$_COOKIE['repoBranch'] = $branch;
}
if($refresh and $repo->SCM == 'Subversion') $this->loadModel('svn')->updateCommit($repo, $commentGroup, false);
$revisionList = array();
foreach($infos as $info) $revisionList[$info->revision] = $info->revision;
$comments = $this->repo->getHistory($repoID, $revisionList);
foreach($infos as $info)
{
if(isset($comments[$info->revision]))
{
$comment = $comments[$info->revision];
$info->comment = $comment->comment;
}
}
$branch = $this->cookie->repoBranch;
$this->loadModel('git')->updateCommit($repo, $commentGroup, false);
$_COOKIE['repoBranch'] = $branch;
}
if($cacheFile)
{
if(!file_exists($cacheFile . '.lock'))
{
touch($cacheFile . '.lock');
file_put_contents($cacheFile, serialize($infos));
unlink($cacheFile . '.lock');
}
}
}
else
{
$infos = unserialize(file_get_contents($cacheFile));
if($repo->SCM == 'Subversion') $this->loadModel('svn')->updateCommit($repo, $commentGroup, false);
}
/* Get files info. */
$infos = $this->repo->getFileCommits($repo, $branchID, $path);
if($this->cookie->repoRefresh) setcookie('repoRefresh', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true);
/* Set logType and revisions. */
$logType = 'dir';
$revisions = $this->repo->getCommits($repo, $path, $revision, $logType, $pager);
$logType = 'dir';
$revisions = $this->repo->getCommits($repo, $path, $revision, $logType, $pager);
$lastRevision = current($revisions);
/* Synchronous commit only in root path. */
if(in_array($repo->SCM, $this->config->repo->gitTypeList) and empty($path) and $infos and empty($revisions)) $this->locate($this->repo->createLink('showSyncCommit', "repoID=$repoID&objectID=$objectID&branch=" . helper::safe64Encode(base64_encode($this->cookie->repoBranch))));
@@ -601,8 +570,9 @@ class repo extends control
$this->view->path = urldecode($path);
$this->view->logType = $logType;
$this->view->cloneUrl = $this->repo->getCloneUrl($repo);
$this->view->cacheTime = date('m-d H:i', filemtime($cacheFile));
$this->view->cacheTime = date('m-d H:i', strtotime($lastRevision->time));
$this->view->branchOrTag = $branchOrTag;
$this->view->syncedRF = strpos(",{$this->config->repo->synced},", ",$repoID,") !== false; //Check has synced rename files.
$this->display();
}
@@ -1550,4 +1520,16 @@ class repo extends control
$files = $this->repo->getFileTree($repo, $branch);
return print($files);
}
/**
* Ajax sync rename record.
*
* @param int $repoID
* @access public
* @return void
*/
public function ajaxSyncRenameRecord($repoID)
{
$this->repo->insertDeleteRecord($repoID);
}
}
+7
View File
@@ -109,4 +109,11 @@ $(function()
var link = createLink('repo', 'downloadCode', 'repoID=' + repoID + '&branch=' + branch);
window.open(link);
})
/* Sync rename record. */
if(!syncedRF)
{
var link = createLink('repo', 'ajaxSyncRenameRecord', 'repoID=' + repoID);
$.get(link);
}
})
+178 -3
View File
@@ -877,6 +877,15 @@ class repoModel extends model
$file->revision = $commitID;
$file->repo = $repoID;
$this->dao->insert(TABLE_REPOFILES)->data($file)->exec();
if($file->oldPath)
{
$file->path = $file->oldPath;
$file->parent = dirname($file->path);
$file->oldPath = '';
$file->action = 'D';
$this->dao->insert(TABLE_REPOFILES)->data($file)->exec();
}
}
}
$revisionPairs[$commit->revision] = $commit->revision;
@@ -933,7 +942,20 @@ class repoModel extends model
$repoFile->parent = $parentPath == '\\' ? '/' : $parentPath;
$repoFile->type = $info['kind'];
$repoFile->action = $info['action'];
$repoFile->oldPath = $info['oldPath'];
$this->dao->insert(TABLE_REPOFILES)->data($repoFile)->exec();
if($repoFile->oldPath)
{
$parentPath = dirname($repoFile->oldPath);
$repoFile->path = $repoFile->oldPath;
$repoFile->parent = $parentPath == '\\' ? '/' : $parentPath;
$repoFile->type = $info['kind'];
$repoFile->action = 'D';
$repoFile->oldPath = '';
$this->dao->insert(TABLE_REPOFILES)->data($repoFile)->exec();
}
}
$version++;
}
@@ -2208,11 +2230,82 @@ class repoModel extends model
return $url;
}
/**
* Get file commits.
*
* @param object $repo
* @param string $branch
* @param string $parent
* @access public
* @return array
*/
public function getFileCommits($repo, $branch, $parent = '')
{
$parent = '/' . ltrim($parent, '/');
/* Get file commits by repo. */
if($repo->SCM != 'Subversion' and empty($branch)) $branch = $this->cookie->repoBranch;
$fileCommits = $this->dao->select('t1.path,t1.type,t1.action,t1.oldPath,t1.parent,t2.revision,t2.comment,t2.committer,t2.time')->from(TABLE_REPOFILES)->alias('t1')
->leftJoin(TABLE_REPOHISTORY)->alias('t2')->on('t1.revision=t2.id')
->leftJoin(TABLE_REPOBRANCH)->alias('t3')->on('t2.id=t3.revision')
->where('t1.repo')->eq($repo->id)
->andWhere('left(t2.comment, 12)')->ne('Merge branch')
->beginIF($repo->SCM != 'Subversion' and $branch)->andWhere('t3.branch')->eq($branch)->fi()
->andWhere('t1.parent')->like("$parent%")->fi()
->orderBy('t2.`time` asc')
->fetchAll('path');
$files = array();
$folders = array();
$dirList = array();
foreach($fileCommits as $fileCommit)
{
/* Filter by parent. */
if($fileCommit->action == 'D') continue;
if(strpos($fileCommit->path, $parent) !== 0) continue;
$pathList = explode('/', ltrim($fileCommit->path, '/'));
if($fileCommit->parent == $parent and $fileCommit->type == 'file')
{
$file = new stdclass();
$file->name = end($pathList);
$file->kind = 'file';
$file->revision = $fileCommit->revision;
$file->comment = $fileCommit->comment;
$file->account = $fileCommit->committer;
$file->date = $fileCommit->time;
$files[] = $file;
}
else
{
$childPath = ltrim(substr($fileCommit->path, strlen($parent)), '/');
$childPath = explode('/', $childPath);
$fileName = $fileCommit->type == 'dir' ? end($pathList) : $childPath[0];
if(in_array($fileName, $dirList)) continue;
$folder = new stdclass();
$folder->name = $fileName;
$folder->kind = 'dir';
$folder->revision = $fileCommit->revision;
$folder->comment = $fileCommit->comment;
$folder->account = $fileCommit->committer;
$folder->date = $fileCommit->time;
$dirList[] = $fileName;
$folders[] = $folder;
}
}
return array_merge($folders, $files);
}
/**
* Get html for file tree.
*
* @param object $repo
* @param string $branch
* @param string $parent
* @access public
* @return string
*/
@@ -2222,11 +2315,10 @@ class repoModel extends model
$files = $this->dao->select('t1.path,t1.action')->from(TABLE_REPOFILES)->alias('t1')
->leftJoin(TABLE_REPOHISTORY)->alias('t2')->on('t1.revision=t2.id')
->leftJoin(TABLE_REPOBRANCH)->alias('t3')->on('t2.id=t3.revision')
->where('1=1')
->andWhere('t1.repo')->eq($repo->id)
->where('t1.repo')->eq($repo->id)
->andWhere('left(t2.comment, 12)')->ne('Merge branch')
->beginIF($repo->SCM != 'Subversion' and $branch)->andWhere('t3.branch')->eq($branch)->fi()
->orderBy('t1.`type` asc, t2.`time` asc')
->orderBy('t2.`time` asc')
->fetchPairs();
$allFiles = array();
@@ -2411,4 +2503,87 @@ class repoModel extends model
$output->targetHtml = str_replace('selected-target', 'selected', $targetHtml);
return $output;
}
/**
* Insert delete record.
*
* @param int $repoID
* @access public
* @return void
*/
public function insertDeleteRecord($repoID)
{
set_time_limit(0);
$repo = $this->loadModel('repo')->getRepoByID($repoID);
if(empty($repo)) return false;
$scm = $this->app->loadClass('scm');
$scm->setEngine($repo);
$values = '';
if($repo->SCM == 'Gitlab')
{
$renameRevisions = $this->dao->select('t1.revision as revisionID,t2.revision')->from(TABLE_REPOFILES)->alias('t1')
->leftJoin(TABLE_REPOHISTORY)->alias('t2')->on('t1.revision=t2.id')
->where('t1.action')->eq('R')
->andWhere('t1.repo')->eq($repoID)
->andWhere('t1.oldPath')->eq('')
->orderBy('t2.time desc')
->fetchAll('revisionID');
foreach($renameRevisions as $revision)
{
$files = $scm->getFilesByCommit($revision->revision);
foreach($files as $file)
{
if($file->action != 'R') continue;
$parentPath = dirname($file->oldPath) == '\\' ? '/' : dirname($file->oldPath);
$values .= "($repoID,{$revision->revisionID},'{$file->oldPath}','','$parentPath','{$file->type}','D'),";
$this->dao->update(TABLE_REPOFILES)->set('oldPath')->eq($file->oldPath)->where('revision')->eq($revision->revisionID)->andWhere('path')->eq($file->path)->exec();
}
}
}
else
{
$branchGroups = $this->dao->select('t1.id as fileID,t1.revision as revisionID,t2.revision,t3.branch')->from(TABLE_REPOFILES)->alias('t1')
->leftJoin(TABLE_REPOHISTORY)->alias('t2')->on('t1.revision=t2.id')
->leftJoin(TABLE_REPOBRANCH)->alias('t3')->on('t3.revision=t2.id')
->where('t1.action')->eq('R')
->andWhere('t1.repo')->eq($repoID)
->andWhere('t1.oldPath')->eq('')
->orderBy('t2.time desc')
->fetchGroup('branch');
$revisionPairs = $this->dao->select('revision,id')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->fetchPairs();
foreach($branchGroups as $branch => $group)
{
$firstCommit = end($group);
$commits = $scm->getCommits($firstCommit->revision, 0, $branch);
foreach($commits['files'] as $revision => $commit)
{
if(!isset($revisionPairs[$revision])) continue;
$revisionID = $revisionPairs[$revision];
foreach($commit as $file)
{
if(!$file->oldPath) continue;
$parentPath = dirname($file->oldPath) == '\\' ? '/' : dirname($file->oldPath);
$values .= "($repoID,$revisionID,'{$file->oldPath}','','$parentPath','{$file->type}','D'),";
$this->dao->update(TABLE_REPOFILES)->set('oldPath')->eq($file->oldPath)->where('revision')->eq($revisionID)->andWhere('path')->eq($file->path)->exec();
}
}
}
}
if($values)
{
$sql = 'INSERT INTO ' . TABLE_REPOFILES . ' (`repo`,`revision`,`path`,`oldPath`,`parent`,`type`,`action`) VALUES ' . trim($values, ',');
$result = $this->dao->exec($sql);
}
$this->loadModel('setting')->setItem('system.repo.synced', $this->config->repo->synced . ',' . $repoID);
}
}
+1
View File
@@ -13,6 +13,7 @@
<?php js::set('branch', $branchID);?>
<?php js::set('lang', $lang->repo);?>
<?php js::set('cloneUrl', $cloneUrl);?>
<?php js::set('syncedRF', $syncedRF);?>
<div id='mainMenu' class='clearfix'>
<div class='btn-toolbar pull-left'>
<?php if(!empty($branchesAndTags)):?>