Jump to correct line in Blame previous revision
Test Plan: Jumped on correct line in SVN, Git and HG repos. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3084
This commit is contained in:
@@ -783,13 +783,17 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|||||||
$path = $old_filename;
|
$path = $old_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$line = null;
|
||||||
|
// If there's a follow error, drop the line so the user sees the message.
|
||||||
|
if (!$follow) {
|
||||||
|
$line = $this->getBeforeLineNumber($target_commit);
|
||||||
|
}
|
||||||
|
|
||||||
$before_uri = $drequest->generateURI(
|
$before_uri = $drequest->generateURI(
|
||||||
array(
|
array(
|
||||||
'action' => 'browse',
|
'action' => 'browse',
|
||||||
'commit' => $target_commit,
|
'commit' => $target_commit,
|
||||||
// If there's a follow error, drop the line so the user sees the
|
'line' => $line,
|
||||||
// message.
|
|
||||||
'line' => $follow ? null : $drequest->getLine(),
|
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -801,6 +805,41 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|||||||
return id(new AphrontRedirectResponse())->setURI($before_uri);
|
return id(new AphrontRedirectResponse())->setURI($before_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getBeforeLineNumber($target_commit) {
|
||||||
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
|
||||||
|
$line = $drequest->getLine();
|
||||||
|
if (!$line) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$diff_query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest);
|
||||||
|
$diff_query->setAgainstCommit($target_commit);
|
||||||
|
try {
|
||||||
|
$raw_diff = $diff_query->loadRawDiff();
|
||||||
|
$old_line = 0;
|
||||||
|
$new_line = 0;
|
||||||
|
|
||||||
|
foreach (explode("\n", $raw_diff) as $text) {
|
||||||
|
if ($text[0] == '-' || $text[0] == ' ') {
|
||||||
|
$old_line++;
|
||||||
|
}
|
||||||
|
if ($text[0] == '+' || $text[0] == ' ') {
|
||||||
|
$new_line++;
|
||||||
|
}
|
||||||
|
if ($new_line == $line) {
|
||||||
|
return $old_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We didn't find the target line.
|
||||||
|
return $line;
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
return $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function loadParentRevisionOf($commit) {
|
private function loadParentRevisionOf($commit) {
|
||||||
$drequest = $this->getDiffusionRequest();
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user