From f7f5ed64bd66127ca4d5bf19348a7fe73bf3bbdc Mon Sep 17 00:00:00 2001 From: zenggang Date: Mon, 11 Mar 2024 02:22:25 +0000 Subject: [PATCH] * Fix feedback#5175,5271 --- lib/scm/subversion.class.php | 7 +++++-- module/repo/control.php | 20 ++++++++++++++++---- module/repo/model.php | 14 +++++++++++++- module/repo/tao.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index a7a693a742..c1e0371729 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -602,12 +602,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); @@ -638,6 +638,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 44463fa428..dedef7eab6 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1293,6 +1293,8 @@ class repo extends control public function ajaxSyncCommit($repoID = 0, $type = 'batch') { set_time_limit(0); + ini_set('memory_limit', '1024M'); + $repo = $this->repo->getByID($repoID); if(empty($repo)) return; if($repo->synced) return print($this->config->repo->repoSyncLog->finish); @@ -1374,17 +1376,27 @@ class repo extends control $version = 1; if($repo->SCM != 'Gitlab') { - $latestInDB = $this->dao->select('t1.*')->from(TABLE_REPOHISTORY)->alias('t1') + $orderBy = $repo->SCM == 'Subversion' ? 'svnRevision desc' : 't1.time'; + $latestInDB = $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 == 'Git' and $this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() ->beginIF($repo->SCM == 'Gitlab' and $this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() - ->orderBy('t1.time') + ->beginIF($repo->SCM == 'Subversion')->andWhere('t1.time')->ne('1970-01-01 08:00:00')->fi() + ->orderBy($orderBy) ->limit(1) ->fetch(); - $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; + } + if($type == 'batch') { $logs = $this->scm->getCommits($revision, $this->config->repo->batchNum, $branchID); diff --git a/module/repo/model.php b/module/repo/model.php index 22a0b8d9a5..01ea36e964 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -422,7 +422,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 || $data->SCM == 'Subversion') && $repo->path != $data->path) { $this->repoTao->deleteInfoByID($repo->id); return false; @@ -1153,6 +1153,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; @@ -1166,6 +1171,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; @@ -1215,6 +1222,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; @@ -1236,6 +1246,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 be2f0ef475..ea4c1eaaa6 100644 --- a/module/repo/tao.php +++ b/module/repo/tao.php @@ -79,5 +79,34 @@ class repoTao extends repoModel $pattern = "/^[a-zA-Z0-9_\-\.]+$/"; return preg_match($pattern, $repo->name); } + + /** + * Copy svn dir. + * + * @param int $repoID + * @param string $copyfromPath + * @param string $copyfromRev + * @param string $dirPath + * @access protected + * @return viod + */ + protected function copySvnDir(int $repoID, string $copyfromPath, string $copyfromRev, string $dirPath) + { + $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(); + } + } }