diff --git a/src/applications/differential/storage/DifferentialDiff.php b/src/applications/differential/storage/DifferentialDiff.php index 3f66656da6..2459dac2f8 100644 --- a/src/applications/differential/storage/DifferentialDiff.php +++ b/src/applications/differential/storage/DifferentialDiff.php @@ -136,6 +136,7 @@ final class DifferentialDiff extends DifferentialDAO { $changeset = new DifferentialChangeset(); $add_lines = 0; $del_lines = 0; + $first_line = PHP_INT_MAX; $hunks = $change->getHunks(); if ($hunks) { foreach ($hunks as $hunk) { @@ -148,6 +149,10 @@ final class DifferentialDiff extends DifferentialDAO { $changeset->addUnsavedHunk($dhunk); $add_lines += $hunk->getAddLines(); $del_lines += $hunk->getDelLines(); + $added_lines = $hunk->getChangedLines('new'); + if ($added_lines) { + $first_line = min($first_line, head_key($added_lines)); + } } $lines += $add_lines + $del_lines; } else { @@ -155,12 +160,17 @@ final class DifferentialDiff extends DifferentialDAO { $changeset->attachHunks(array()); } + $metadata = $change->getAllMetadata(); + if ($first_line != PHP_INT_MAX) { + $metadata['line:first'] = $first_line; + } + $changeset->setOldFile($change->getOldPath()); $changeset->setFilename($change->getCurrentPath()); $changeset->setChangeType($change->getType()); $changeset->setFileType($change->getFileType()); - $changeset->setMetadata($change->getAllMetadata()); + $changeset->setMetadata($metadata); $changeset->setOldProperties($change->getOldProperties()); $changeset->setNewProperties($change->getNewProperties()); $changeset->setAwayPaths($change->getAwayPaths()); diff --git a/src/applications/differential/view/DifferentialChangesetListView.php b/src/applications/differential/view/DifferentialChangesetListView.php index c85990b448..3f9cfe8e13 100644 --- a/src/applications/differential/view/DifferentialChangesetListView.php +++ b/src/applications/differential/view/DifferentialChangesetListView.php @@ -256,7 +256,8 @@ final class DifferentialChangesetListView extends AphrontView { $repository = $this->repository; if ($repository) { $meta['diffusionURI'] = (string)$repository->getDiffusionBrowseURIForPath( - $changeset->getAbsoluteRepositoryPath($repository, $this->diff)); + $changeset->getAbsoluteRepositoryPath($repository, $this->diff), + idx($changeset->getMetadata(), 'line:first')); } $change = $changeset->getChangeType(); @@ -283,7 +284,7 @@ final class DifferentialChangesetListView extends AphrontView { $path = ltrim( $changeset->getAbsoluteRepositoryPath($repository, $this->diff), '/'); - $line = 1; // TODO: get first changed line + $line = idx($changeset->getMetadata(), 'line:first', 1); $callsign = $repository->getCallsign(); $editor_link = $user->loadEditorLink($path, $line, $callsign); if ($editor_link) { diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index b5be702783..f3387c5b36 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -60,7 +60,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO { return $this; } - public function getDiffusionBrowseURIForPath($path) { + public function getDiffusionBrowseURIForPath($path, $line = null) { $drequest = DiffusionRequest::newFromDictionary( array( 'repository' => $this, @@ -70,6 +70,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO { return $drequest->generateURI( array( 'action' => 'browse', + 'line' => $line, )); }