@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Don't skip even lines in copied code detector

Summary: PHP 3 basics: `each()` advances internal pointer so calling `next()` is wrong.

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4011

vrana 4d7b4418 254678d4

+71 -1
+2
src/__phutil_library_map__.php
··· 245 245 'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php', 246 246 'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php', 247 247 'DifferentialDiffTableOfContentsView' => 'applications/differential/view/DifferentialDiffTableOfContentsView.php', 248 + 'DifferentialDiffTestCase' => 'applications/differential/storage/__tests__/DifferentialDiffTestCase.php', 248 249 'DifferentialDiffViewController' => 'applications/differential/controller/DifferentialDiffViewController.php', 249 250 'DifferentialException' => 'applications/differential/exception/DifferentialException.php', 250 251 'DifferentialExceptionMail' => 'applications/differential/mail/DifferentialExceptionMail.php', ··· 1502 1503 'DifferentialDiffCreateController' => 'DifferentialController', 1503 1504 'DifferentialDiffProperty' => 'DifferentialDAO', 1504 1505 'DifferentialDiffTableOfContentsView' => 'AphrontView', 1506 + 'DifferentialDiffTestCase' => 'ArcanistPhutilTestCase', 1505 1507 'DifferentialDiffViewController' => 'DifferentialController', 1506 1508 'DifferentialException' => 'Exception', 1507 1509 'DifferentialExceptionMail' => 'DifferentialMail',
+1 -1
src/applications/differential/storage/DifferentialDiff.php
··· 204 204 $copies = array(); 205 205 foreach ($changeset->getHunks() as $hunk) { 206 206 $added = array_map('trim', $hunk->getAddedLines()); 207 - for (reset($added); list($line, $code) = each($added); next($added)) { 207 + for (reset($added); list($line, $code) = each($added); ) { 208 208 if (isset($map[$code])) { // We found a long matching line. 209 209 $best_length = 0; 210 210 foreach ($map[$code] as $val) { // Explore all candidates.
+18
src/applications/differential/storage/__tests__/DifferentialDiffTestCase.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffTestCase extends ArcanistPhutilTestCase { 4 + 5 + public function testDetectCopiedCode() { 6 + $root = dirname(__FILE__).'/diff/'; 7 + $parser = new ArcanistDiffParser(); 8 + 9 + $diff = DifferentialDiff::newFromRawChanges( 10 + $parser->parseDiff(Filesystem::readFile($root.'lint_engine.diff'))); 11 + $copies = idx(head($diff->getChangesets())->getMetadata(), 'copy:lines'); 12 + 13 + $this->assertEqual( 14 + array_combine(range(237, 252), range(167, 182)), 15 + ipull($copies, 1)); 16 + } 17 + 18 + }
+50
src/applications/differential/storage/__tests__/diff/lint_engine.diff
··· 1 + diff --git a/ArcanistLintEngine.php b/ArcanistLintEngine.php 2 + index 41e1153..255b049 100644 3 + --- a/ArcanistLintEngine.php 4 + +++ b/ArcanistLintEngine.php 5 + @@ -165,22 +165,6 @@ abstract class ArcanistLintEngine { 6 + $stopped = array(); 7 + $linters = $this->buildLinters(); 8 + 9 + - if (!$linters) { 10 + - throw new ArcanistNoEffectException("No linters to run."); 11 + - } 12 + - 13 + - $have_paths = false; 14 + - foreach ($linters as $linter) { 15 + - if ($linter->getPaths()) { 16 + - $have_paths = true; 17 + - break; 18 + - } 19 + - } 20 + - 21 + - if (!$have_paths) { 22 + - throw new ArcanistNoEffectException("No paths are lintable."); 23 + - } 24 + - 25 + $exceptions = array(); 26 + foreach ($linters as $linter_name => $linter) { 27 + try { 28 + @@ -251,6 +235,22 @@ abstract class ArcanistLintEngine { 29 + } 30 + } 31 + 32 + + if (!$linters) { 33 + + throw new ArcanistNoEffectException("No linters to run."); 34 + + } 35 + + 36 + + $have_paths = false; 37 + + foreach ($linters as $linter) { 38 + + if ($linter->getPaths()) { 39 + + $have_paths = true; 40 + + break; 41 + + } 42 + + } 43 + + 44 + + if (!$have_paths) { 45 + + throw new ArcanistNoEffectException("No paths are lintable."); 46 + + } 47 + + 48 + if ($exceptions) { 49 + throw new PhutilAggregateException('Some linters failed:', $exceptions); 50 + }