* adjust for gitlab branch.

This commit is contained in:
wangyidong
2021-05-27 14:16:44 +08:00
parent 49febd6e96
commit bf365b9188
2 changed files with 11 additions and 5 deletions
+6 -2
View File
@@ -40,6 +40,7 @@ class gitlab
$param->path = ltrim($path, '/');
$param->ref = $revision;
$param->recursive = 0;
if(!empty($this->branch)) $param->ref = $this->branch;
$list = $this->fetch($api, $param);
if(empty($list)) return array();
@@ -257,6 +258,7 @@ class gitlab
$api = "compare";
$params = array('from' => $fromRevision, 'to' => $toRevision, 'straight' => 1);
if($toRevision == 'HEAD' and $this->branch) $params['to'] = $this->branch;
$results = $this->fetch($api, $params);
foreach($results->diffs as $key => $diff)
{
@@ -288,6 +290,7 @@ class gitlab
public function cat($entry, $revision = 'HEAD')
{
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);
}
@@ -309,6 +312,7 @@ class gitlab
$info->path = $entry;
$info->revision = $revision;
$info->root = '';
if($revision == 'HEAD' and $this->branch) $info->revision = $this->branch;
if($entry)
{
@@ -494,13 +498,13 @@ class gitlab
if(!scm::checkRevision($version)) return array();
$api = "commits";
$count = 500;
$count = 500;
$params = array();
$params['ref_name'] = $branch;
$params['per_page'] = $count;
$params['all'] = 1;
if($version)
if($version and $version != 'HEAD')
{
$lastCommit = $this->getSingleCommit($version);
if(!isset($lastCommit->committed_date)) return array('commits' => array(), 'files' => array());
+5 -3
View File
@@ -338,6 +338,7 @@ class repo extends control
public function browse($repoID = 0, $branchID = '', $objectID = 0, $path = '', $revision = 'HEAD', $refresh = 0)
{
$repoID = $this->repo->saveState($repoID, $objectID);
if($branchID) $this->repo->setRepoBranch($branchID);
/* Get path and refresh. */
if($this->get->repoPath) $path = $this->get->repoPath;
@@ -427,7 +428,7 @@ class repo extends control
$revisions = $this->repo->getCommits($repo, $path, $revision, $logType, $pager);
/* Synchronous commit only in root path. */
if(strpos($repo->SCM, 'Git') != false and empty($path) and $infos and empty($revisions)) $this->locate($this->repo->createLink('showSyncCommit', "repoID=$repoID&objectID=$objectID&branch=" . base64_encode($this->cookie->repoBranch)));
if(strpos($repo->SCM, 'Git') !== false and empty($path) and $infos and empty($revisions)) $this->locate($this->repo->createLink('showSyncCommit', "repoID=$repoID&objectID=$objectID&branch=" . base64_encode($this->cookie->repoBranch)));
/* Set committers. */
$commiters = $this->loadModel('user')->getCommiters();
@@ -911,7 +912,7 @@ class repo extends control
$version = empty($latestInDB) ? 1 : $latestInDB->commit + 1;
$logs = array();
$revision = $version == 1 ? 'HEAD' : (strpos($repo->SCM, 'Git') !== false ? $latestInDB->commit : $latestInDB->revision);
$revision = $version == 1 ? 'HEAD' : ($repo->SCM == 'Git' ? $latestInDB->commit : $latestInDB->revision);
if($type == 'batch')
{
$logs = $this->scm->getCommits($revision, $this->config->repo->batchNum, $branchID);
@@ -961,7 +962,7 @@ class repo extends control
set_time_limit(0);
$repo = $this->repo->getRepoByID($repoID);
if(empty($repo)) die();
if(strpos($repo->SCM, 'Git') != false) die('finish');
if(strpos($repo->SCM, 'Git') !== false) die('finish');
if($branch) $branch = base64_decode($branch);
$this->scm->setEngine($repo);
@@ -980,6 +981,7 @@ class repo extends control
$version = empty($latestInDB) ? 1 : $latestInDB->commit + 1;
$logs = array();
$revision = $version == 1 ? 'HEAD' : $latestInDB->commit;
if($repo->SCM == 'Gitlab' and $version > 1) $revision = $latestInDB->revision;
$logs = $this->scm->getCommits($revision, $this->config->repo->batchNum, $branch);
$commitCount = $this->repo->saveCommit($repoID, $logs, $version, $branch);