From ed02823eaff018ae31e2a6550f8ecda9b5305b5f Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Tue, 16 Apr 2013 11:02:04 -0700 Subject: [PATCH] Condense renames in Differential ToC Summary: It's currently quite confusing. Test Plan: lang=diff diff --git a/bin/config b/bin/x similarity index 100% rename from bin/config rename to bin/x diff --git a/bin/aphlict b/bin/y/aphlict similarity index 100% rename from bin/aphlict rename to bin/y/aphlict diff --git a/bin/diviner b/scripts/z similarity index 100% rename from bin/diviner rename to scripts/z Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Differential Revision: https://secure.phabricator.com/D5708 --- .../DifferentialDiffTableOfContentsView.php | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/applications/differential/view/DifferentialDiffTableOfContentsView.php b/src/applications/differential/view/DifferentialDiffTableOfContentsView.php index 63de1f17fd..5a06782a94 100644 --- a/src/applications/differential/view/DifferentialDiffTableOfContentsView.php +++ b/src/applications/differential/view/DifferentialDiffTableOfContentsView.php @@ -82,8 +82,9 @@ final class DifferentialDiffTableOfContentsView extends AphrontView { $type = $changeset->getChangeType(); $ftype = $changeset->getFileType(); $ref = idx($this->references, $id); - $link = $this->renderChangesetLink($changeset, $ref); + $display_file = $changeset->getDisplayFilename(); + $meta = null; if (DifferentialChangeType::isOldLocationChangeType($type)) { $away = $changeset->getAwayPaths(); if (count($away) > 1) { @@ -99,19 +100,26 @@ final class DifferentialDiffTableOfContentsView extends AphrontView { $meta = phutil_implode_html(phutil_tag('br'), $meta); } else { if ($type == DifferentialChangeType::TYPE_MOVE_AWAY) { - $meta = pht('Moved to %s', reset($away)); + $display_file = $this->renderRename( + $display_file, + reset($away), + "\xE2\x86\x92"); } else { $meta = pht('Copied to %s', reset($away)); } } } else if ($type == DifferentialChangeType::TYPE_MOVE_HERE) { - $meta = pht('Moved from %s', $changeset->getOldFile()); + $old_file = $changeset->getOldFile(); + $display_file = $this->renderRename( + $display_file, + $old_file, + "\xE2\x86\x90"); } else if ($type == DifferentialChangeType::TYPE_COPY_HERE) { $meta = pht('Copied from %s', $changeset->getOldFile()); - } else { - $meta = null; } + $link = $this->renderChangesetLink($changeset, $ref, $display_file); + $line_count = $changeset->getAffectedLineCount(); if ($line_count == 0) { $lines = null; @@ -233,6 +241,38 @@ final class DifferentialDiffTableOfContentsView extends AphrontView { $buttons); } + private function renderRename($display_file, $other_file, $arrow) { + $old = explode('/', $display_file); + $new = explode('/', $other_file); + + $start = count($old); + foreach ($old as $index => $part) { + if (!isset($new[$index]) || $part != $new[$index]) { + $start = $index; + break; + } + } + + $end = count($old); + foreach (array_reverse($old) as $from_end => $part) { + $index = count($new) - $from_end - 1; + if (!isset($new[$index]) || $part != $new[$index]) { + $end = $from_end; + break; + } + } + + $rename = + '{'. + implode('/', array_slice($old, $start, count($old) - $end - $start)). + ' '.$arrow.' '. + implode('/', array_slice($new, $start, count($new) - $end - $start)). + '}'; + + array_splice($new, $start, count($new) - $end - $start, $rename); + return implode('/', $new); + } + private function renderCoverage(array $coverage, $file) { $info = idx($coverage, $file); if (!$info) { @@ -250,8 +290,10 @@ final class DifferentialDiffTableOfContentsView extends AphrontView { } - private function renderChangesetLink(DifferentialChangeset $changeset, $ref) { - $display_file = $changeset->getDisplayFilename(); + private function renderChangesetLink( + DifferentialChangeset $changeset, + $ref, + $display_file) { return javelin_tag( 'a',