1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-02 02:40:58 +01:00

Support blame on blame for svn

Summary:
add the column for the blame on blame for svn. We will support
git once we have the 'parent' info of the commits saved in the database
for git.

Test Plan:
in svn it should work. In git is doesn't break things.

Reviewed By: epriestley
Reviewers: epriestley
CC: epriestley
Differential Revision: 95
This commit is contained in:
jungejason 2011-04-01 15:34:45 -07:00
parent 82fffe466a
commit 313da1d5eb
3 changed files with 89 additions and 13 deletions

View file

@ -26,6 +26,7 @@ class DiffusionBrowseFileController extends DiffusionController {
'jpeg'=> 'image/jpeg' 'jpeg'=> 'image/jpeg'
); );
public function processRequest() { public function processRequest() {
// Build the view selection form. // Build the view selection form.
@ -90,6 +91,20 @@ class DiffusionBrowseFileController extends DiffusionController {
} }
/*
* Returns a content-type corrsponding to an image file extension
*
* @param string $path File path
* @return mixed A content-type string or NULL if path doesn't end with a
* recognized image extension
*/
public function getImageType($path) {
$ext = pathinfo($path);
$ext = $ext['extension'];
return idx($this->imageTypes, $ext);
}
private function buildCorpus($selected) { private function buildCorpus($selected) {
$needs_blame = ($selected == 'blame' || $selected == 'plainblame'); $needs_blame = ($selected == 'blame' || $selected == 'plainblame');
@ -166,7 +181,7 @@ class DiffusionBrowseFileController extends DiffusionController {
implode("\n", $text_list))); implode("\n", $text_list)));
$rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict,
$needs_blame, $drequest); $needs_blame, $drequest, $file_query, $selected);
$corpus_table = phutil_render_tag( $corpus_table = phutil_render_tag(
'table', 'table',
@ -189,7 +204,7 @@ class DiffusionBrowseFileController extends DiffusionController {
private static function buildDisplayRows($text_list, $rev_list, $blame_dict, private static function buildDisplayRows($text_list, $rev_list, $blame_dict,
$needs_blame, DiffusionRequest $drequest) { $needs_blame, DiffusionRequest $drequest, $file_query, $selected) {
$last_rev = null; $last_rev = null;
$color = null; $color = null;
$rows = array(); $rows = array();
@ -208,6 +223,8 @@ class DiffusionBrowseFileController extends DiffusionController {
$rev = $rev_list[$k]; $rev = $rev_list[$k];
if ($last_rev == $rev) { if ($last_rev == $rev) {
$blame_info = $blame_info =
($file_query->getSupportsBlameOnBlame() ?
'<th style="background: '.$color.'; width: 2em;"></th>' : '').
'<th style="background: '.$color.'; width: 9em;"></th>'. '<th style="background: '.$color.'; width: 9em;"></th>'.
'<th style="background: '.$color.'"></th>'; '<th style="background: '.$color.'"></th>';
} else { } else {
@ -220,8 +237,25 @@ class DiffusionBrowseFileController extends DiffusionController {
$drequest, $drequest,
substr($rev, 0, 7)); substr($rev, 0, 7));
if (!$file_query->getSupportsBlameOnBlame()) {
$prev_link = '';
} else {
$prev_rev = $file_query->getPrevRev($rev);
$path = $drequest->getPath();
$prev_link = self::renderBrowse(
$drequest,
$path,
"\xC2\xAB",
$prev_rev,
$n,
$selected);
$prev_link = '<th style="background: ' . $color .
'; width: 2em;">' . $prev_link . '</th>';
}
$author_link = $blame_dict[$rev]['author']; $author_link = $blame_dict[$rev]['author'];
$blame_info = $blame_info =
$prev_link .
'<th style="background: '.$color. '<th style="background: '.$color.
'; width: 9em;">'.$revision_link.'</th>'. '; width: 9em;">'.$revision_link.'</th>'.
'<th style="background: '.$color. '<th style="background: '.$color.
@ -278,17 +312,41 @@ class DiffusionBrowseFileController extends DiffusionController {
} }
/** private static function renderBrowse(
* Returns a content-type corrsponding to an image file extension DiffusionRequest $drequest,
* $path,
* @param string $path File path $name = null,
* @return mixed A content-type string or NULL if path doesn't end with a $rev = null,
* recognized image extension $line = null,
*/ $view = null) {
public function getImageType($path) {
$ext = pathinfo($path); $callsign = $drequest->getCallsign();
$ext = $ext['extension'];
return idx($this->imageTypes, $ext); if ($name === null) {
$name = $path;
}
$at = null;
if ($rev) {
$at = ';'.$rev;
}
if ($view) {
$view = '?view='.$view;
}
if ($line) {
$line = '$'.$line;
}
return phutil_render_tag(
'a',
array(
'href' => "/diffusion/{$callsign}/browse/{$path}{$at}{$line}{$view}",
),
$name
);
} }
} }

View file

@ -50,6 +50,16 @@ abstract class DiffusionFileContentQuery {
return $query; return $query;
} }
public function getSupportsBlameOnBlame() {
return false;
}
public function getPrevRev($rev) {
// TODO: support git once the 'parent' info of a commit is saved
// to the database.
throw new Exception("Unsupported VCS!");
}
final protected function getRequest() { final protected function getRequest() {
return $this->request; return $this->request;
} }

View file

@ -18,6 +18,14 @@
final class DiffusionSvnFileContentQuery extends DiffusionFileContentQuery { final class DiffusionSvnFileContentQuery extends DiffusionFileContentQuery {
public function getSupportsBlameOnBlame() {
return true;
}
public function getPrevRev($rev) {
return max($rev - 1, 0);
}
protected function executeQuery() { protected function executeQuery() {
$drequest = $this->getRequest(); $drequest = $this->getRequest();