From ef0f0559efe10cd636aa43f72ad1c3cadff07fd6 Mon Sep 17 00:00:00 2001 From: zenggang Date: Tue, 12 Mar 2024 02:45:01 +0000 Subject: [PATCH] * Fix feedback#5175,5271 --- lib/scm/subversion.class.php | 7 +++++-- module/repo/control.php | 9 ++++++++- module/repo/model.php | 21 ++++++++++++++++++--- module/repo/tao.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index 0a27a00e40..6b9e17f85e 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -603,12 +603,12 @@ class Subversion $path = '"' . $this->root . '"'; if(stripos($this->root, 'https') === 0 or stripos($this->root, 'svn') === 0) { - $comments = str_replace("\\", "/", "$this->client log $count -v -r $version:0 --non-interactive --trust-server-cert-failures=cn-mismatch --trust-server-cert --no-auth-cache --xml $path"); + $comments = str_replace("\\", "/", "$this->client log $count -v -r $version:HEAD --non-interactive --trust-server-cert-failures=cn-mismatch --trust-server-cert --no-auth-cache --xml $path"); if($this->svnVersion and version_compare($this->svnVersion, '1.9', '<')) $comments = str_replace("\\", "/", "$this->client log $count -v -r $version:0 --non-interactive --trust-server-cert --no-auth-cache --xml $path"); } else { - $comments = str_replace("\\", "/", "$this->client log $count -v -r $version:0 --no-auth-cache --xml $path"); + $comments = str_replace("\\", "/", "$this->client log $count -v -r $version:HEAD --no-auth-cache --xml $path"); } $comments = $this->replaceAuth(escapeCmd($comments)); $comments = execCmd($comments, 'string', $result); @@ -639,6 +639,9 @@ class Subversion $parsedFile->path = (string)$file; $parsedFile->type = (string)$file['kind']; $parsedFile->action = (string)$file['action']; + if(isset($file['copyfrom-path'])) $parsedFile->copyfromPath = (string)$file['copyfrom-path']; + if(isset($file['copyfrom-rev'])) $parsedFile->copyfromRev = (string)$file['copyfrom-rev']; + $logs['files'][$parsedLog->revision][] = $parsedFile; } } diff --git a/module/repo/control.php b/module/repo/control.php index 4d9c2ad978..c75d303532 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1156,7 +1156,14 @@ class repo extends control $latestInDB = $this->repo->getLatestCommit($repoID, false); $version = empty($latestInDB) ? 1 : $latestInDB->commit + 1; - $revision = $version == 1 ? 'HEAD' : (in_array($repo->SCM, array('Git', 'Gitea', 'Gogs')) ? $latestInDB->commit : $latestInDB->revision); + if(in_array($repo->SCM, array('Git', 'Gitea', 'Gogs'))) + { + $revision = $version == 1 ? 'HEAD' : $latestInDB->commit; + } + else + { + $revision = $version == 1 ? '0' : $latestInDB->revision; + } $batchNum = $type == 'batch' ? $this->config->repo->batchNum : 0; $logs = $this->scm->getCommits($revision, $batchNum, $branchID); } diff --git a/module/repo/model.php b/module/repo/model.php index 0203331a58..e0a8a49227 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -398,7 +398,7 @@ class repoModel extends model $this->updateCommitDate($repo->id); } - if(($repo->serviceHost != $data->serviceHost || $repo->serviceProject != $data->serviceProject) && $repo->path != $data->path) + if(($repo->serviceHost != $data->serviceHost || $repo->serviceProject != $data->serviceProject || $repo->scm == 'Subversion') && $repo->path != $data->path) { $this->repoTao->deleteInfoByID($repo->id); return false; @@ -894,12 +894,15 @@ class repoModel extends model public function getLatestCommit(int $repoID, bool $checkCount = true): object|false { $repo = $this->fetchByID($repoID); + + $orderBy = $repo->SCM == 'Subversion' ? 'svnRevision desc' : 't1.time desc'; $branchID = (string)$this->cookie->repoBranch; - $lastComment = $this->dao->select('t1.*')->from(TABLE_REPOHISTORY)->alias('t1') + $lastComment = $this->dao->select('t1.*,t1.revision*1 as svnRevision')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) ->beginIF($repo->SCM != 'Subversion' && $branchID)->andWhere('t2.branch')->eq($branchID)->fi() - ->orderBy('t1.time desc') + ->beginIF($repo->SCM == 'Subversion')->andWhere('t1.time')->ne('1970-01-01 08:00:00')->fi() + ->orderBy($orderBy) ->fetch(); if(empty($lastComment)) return false; if(!$checkCount) return $lastComment; @@ -1061,6 +1064,11 @@ class repoModel extends model { $parentPath = dirname($file->path); + $copyfromPath = !empty($file->copyfromPath) ? $file->copyfromPath : ''; + $copyfromRev = !empty($file->copyfromRev) ? $file->copyfromRev : ''; + unset($file->copyfromPath); + unset($file->copyfromRev); + $file->parent = $parentPath == '\\' ? '/' : $parentPath; $file->revision = $commitID; $file->repo = $repoID; @@ -1074,6 +1082,8 @@ class repoModel extends model $file->action = 'D'; $this->dao->insert(TABLE_REPOFILES)->data($file)->exec(); } + + if(!empty($copyfromPath) && !empty($copyfromRev)) $this->repoTao->copySvnDir($repoID, $copyfromPath, $copyfromRev, $file->path); } } $revisionPairs[$commit->revision] = $commit->revision; @@ -1122,6 +1132,9 @@ class repoModel extends model { $parentPath = dirname($file); + $copyfromPath = !empty($info['copyfrom-path']) ? $info['copyfrom-path'] : ''; + $copyfromRev = !empty($info['copyfrom-rev']) ? $info['copyfrom-rev']: ''; + $repoFile = new stdclass(); $repoFile->repo = $repoID; $repoFile->revision = $commitID; @@ -1143,6 +1156,8 @@ class repoModel extends model $repoFile->oldPath = ''; $this->dao->insert(TABLE_REPOFILES)->data($repoFile)->exec(); } + + if(!empty($copyfromPath) && !empty($copyfromRev)) $this->repoTao->copySvnDir($repoID, $copyfromPath, $copyfromRev, $repoFile->path); } $version ++; diff --git a/module/repo/tao.php b/module/repo/tao.php index f054cf9bfc..9db2217ee5 100644 --- a/module/repo/tao.php +++ b/module/repo/tao.php @@ -307,4 +307,33 @@ class repoTao extends repoModel return $matches; } + + /** + * Copy svn dir. + * + * @param int $repoID + * @param string $copyfromPath + * @param string $copyfromRev + * @param string $dirPath + * @access protected + * @return void + */ + protected function copySvnDir(int $repoID, string $copyfromPath, string $copyfromRev, string $dirPath): void + { + $copyFiles = $this->dao->select('t1.*')->from(TABLE_REPOFILES)->alias('t1') + ->leftJoin(TABLE_REPOHISTORY)->alias('t2')->on('t1.revision = t2.id') + ->where('t1.repo')->eq($repoID) + ->andWhere('t2.revision+0')->le($copyfromRev) + ->andWhere('t1.path')->like("{$copyfromPath}%") + ->fetchAll(); + foreach($copyFiles as $copyFile) + { + unset($copyFile->id); + $copyFile->path = substr_replace($copyFile->path, $dirPath, 0, strlen($copyfromPath)); + $copyFile->parent = substr_replace($copyFile->parent, $dirPath, 0, strlen($copyfromPath)); + + if($copyFile->path == $dirPath) continue; + $this->dao->insert(TABLE_REPOFILES)->data($copyFile)->exec(); + } + } }