* Fix bug#16945

This commit is contained in:
zenggang
2021-12-02 00:54:51 +00:00
parent fd0fb325fa
commit bcb6dbbe0a
3 changed files with 43 additions and 1 deletions
+9 -1
View File
@@ -536,10 +536,18 @@ class gitlab
if($version and $version != 'HEAD')
{
/* Get since param. */
if(substr($version, 0, 5) == 'since')
{
$since = true;
$version = substr($version, 5);
}
$committedDate = $this->getCommittedDate($version);
if(!$committedDate) return array('commits' => array(), 'files' => array());
$params['until'] = $committedDate;
if($since) $params['since'] = $committedDate;
else $params['until'] = $committedDate;
}
$list = $this->fetch($api, $params);
+2
View File
@@ -401,6 +401,8 @@ class repo extends control
/* Cache infos. */
if($refresh or !$cacheFile or !file_exists($cacheFile) or (time() - filemtime($cacheFile)) / 60 > $this->config->repo->cacheTime)
{
$this->repo->syncCommit($repoID, $branchID);
/* Get cache infos. */
$infos = $this->scm->ls($path, $revision);
+32
View File
@@ -1843,4 +1843,36 @@ class repoModel extends model
->andWhere('path')->in($projectIDs)
->fetchPairs('path', 'product');
}
/**
* Sync the latest commit.
*
* @param int $repoID
* @param string $branchID
* @access public
* @return void
*/
public function syncCommit($repoID, $branchID)
{
$repo = $this->getRepoByID($repoID);
$this->scm->setEngine($repo);
$latestInDB = $this->dao->select('DISTINCT t1.*')->from(TABLE_REPOHISTORY)->alias('t1')
->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision')
->where('t1.repo')->eq($repoID)
->beginIF($repo->SCM == 'Git' and $branchID)->andWhere('t2.branch')->eq($branchID)->fi()
->beginIF($repo->SCM == 'Gitlab' and $branchID)->andWhere('t2.branch')->eq($branchID)->fi()
->orderBy('t1.time desc')
->limit(1)
->fetch();
$version = empty($latestInDB) ? 1 : $latestInDB->commit + 1;
$logs = array();
$revision = $version == 1 ? 'HEAD' : ($repo->SCM == 'Git' ? $latestInDB->commit : $latestInDB->revision);
$logs = $this->scm->getCommits('since' . $revision, $this->config->repo->batchNum, $branchID);
$commitCount = $this->saveCommit($repoID, $logs, $version, $branchID);
$this->dao->update(TABLE_REPO)->set('commits=commits + ' . $commitCount)->where('id')->eq($repoID)->exec();
$this->fixCommit($repoID);
}
}