From ec536afaa0cda11a081e2c8dd6e83457c0ab53b0 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Thu, 13 Feb 2020 17:07:37 +0800 Subject: [PATCH] * finish task #6859. --- module/repo/control.php | 45 ++++++++++++++ module/repo/view/blame.html.php | 102 ++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 module/repo/view/blame.html.php diff --git a/module/repo/control.php b/module/repo/control.php index 6cef422f4a..f37e9659a8 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -390,6 +390,51 @@ class repo extends control $this->display(); } + /** + * Blame repo file. + * + * @param int $repoID + * @param string $entry + * @param string $revision + * @param string $encoding + * @access public + * @return void + */ + public function blame($repoID, $entry, $revision = 'HEAD', $encoding = '') + { + if($this->get->entry) $entry = $this->get->entry; + $this->repo->setMenu($this->repos, $repoID); + if($repoID == 0) $repoID = $this->session->repoID; + $repo = $this->repo->getRepoByID($repoID); + $file = $entry; + $entry = $this->repo->decodePath($entry); + + $this->scm->setEngine($repo); + $encoding = empty($encoding) ? $repo->encoding : $encoding; + $encoding = strtolower(str_replace('_', '-', $encoding)); + $blames = $this->scm->blame($entry, $revision); + $revisions = array(); + foreach($blames as $i => $blame) + { + if(isset($blame['revision'])) $revisions[$blame['revision']] = $blame['revision']; + if($encoding != 'utf-8') $blames[$i]['content'] = helper::convertEncoding($blame['content'], $encoding); + } + + $log = $repo->SCM == 'Git' ? $this->dao->select('revision,commit')->from(TABLE_REPOHISTORY)->where('revision')->eq($revision)->andWhere('repo')->eq($repo->id)->fetch() : ''; + + $this->view->title = $this->lang->repo->common; + $this->view->repoID = $repoID; + $this->view->repo = $repo; + $this->view->revision = $revision; + $this->view->entry = $entry; + $this->view->file = $file; + $this->view->encoding = str_replace('-', '_', $encoding); + $this->view->historys = $repo->SCM == 'Git' ? $this->dao->select('revision,commit')->from(TABLE_REPOHISTORY)->where('revision')->in($revisions)->andWhere('repo')->eq($repo->id)->fetchPairs() : ''; + $this->view->revisionName = ($log and $repo->SCM == 'Git') ? $this->repo->getGitRevisionName($log->revision, $log->commit) : $revision; + $this->view->blames = $blames; + $this->display(); + } + /** * Show diff. * diff --git a/module/repo/view/blame.html.php b/module/repo/view/blame.html.php new file mode 100644 index 0000000000..9f3b5413b5 --- /dev/null +++ b/module/repo/view/blame.html.php @@ -0,0 +1,102 @@ + + + + + + +
+
+
+ repo->encodePath($entry);?> +
+
+ repo->encodingList, $encoding, $lang->repo->encoding) . "", "id='encoding' data-toggle='dropdown'", 'btn dropdown-toggle')?> + +
+
+
+
+ + + + + SCM == 'Git'):?> + + + + + + + + + + > + '; + echo $repo->SCM == 'Git' ? substr($blame['revision'], 0, 10) : $blame['revision']; + echo ''; + if($repo->SCM == 'Git') echo ''; + echo ''; + } + ?> + + + + + +
repo->revision?>repo->commit?>repo->committer?>repo->line?>repo->code?>
' . zget($historys, $blame['revision'], '') . '' . $blame['committer'] . '
+
+
+