Add color to diffusion blame and improve plain view

Summary:
query the database to get the epoch info for the commits, then
calculate the color depending on the epoch (the newer the commit, the
dark its color). Also improved the plain blame view for git, as the
git-blame doesn't produce a good display by default. Now we format the
output it from the data we fetches from the database.

Test Plan:
verify both git and svn browsing page work for 'plain',
'plainblame', 'highlighted' and 'highlightedblame' view.

Reviewed By: epriestley
Reviewers: epriestley
CC: epriestley, jungejason
Differential Revision: 93
This commit is contained in:
jungejason
2011-03-31 18:28:24 -07:00
parent 3369147cab
commit 64cd4f969d
6 changed files with 142 additions and 116 deletions

View File

@@ -20,6 +20,7 @@ abstract class DiffusionFileContentQuery {
private $request;
private $needsBlame;
private $fileContent;
final private function __construct() {
// <private>
@@ -54,20 +55,53 @@ abstract class DiffusionFileContentQuery {
}
final public function loadFileContent() {
return $this->executeQuery();
$this->fileContent = $this->executeQuery();
}
abstract protected function executeQuery();
final public function getRawData() {
return $this->loadFileContent()->getCorpus();
return $this->fileContent->getCorpus();
}
final public function getTokenizedData() {
return $this->tokenizeData($this->getRawData());
final public function getBlameData() {
$raw_data = $this->getRawData();
$text_list = array();
$rev_list = array();
$blame_dict = array();
if (!$this->getNeedsBlame()) {
$text_list = explode("\n", rtrim($raw_data));
} else {
foreach (explode("\n", rtrim($raw_data)) as $k => $line) {
list($rev_id, $author, $text) = $this->tokenizeLine($line);
$text_list[$k] = $text;
$rev_list[$k] = $rev_id;
if (!isset($blame_dict[$rev_id]) &&
!isset($blame_dict[$rev_id]['author'] )) {
$blame_dict[$rev_id]['author'] = $author;
}
}
$repository = $this->getRequest()->getRepository();
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
'repositoryID = %d AND commitIdentifier IN (%Ls)', $repository->getID(),
array_unique($rev_list));
foreach ($commits as $commit) {
$commitIdentifier = $commit->getCommitIdentifier();
$epoch = $commit->getEpoch();
$blame_dict[$commitIdentifier]['epoch'] = $epoch;
}
}
return array($text_list, $rev_list, $blame_dict);
}
abstract protected function tokenizeData($data);
abstract protected function tokenizeLine($line);
public function setNeedsBlame($needs_blame)
{

View File

@@ -7,8 +7,10 @@
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
phutil_require_module('phabricator', 'applications/repository/storage/commit');
phutil_require_module('phutil', 'symbols');
phutil_require_module('phutil', 'utils');
phutil_require_source('DiffusionFileContentQuery.php');