Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/parser/DifferentialChangesetParser.php
Show First 20 Lines • Show All 1,170 Lines • ▼ Show 20 Lines | public function detectCopiedCode( | ||||
} | } | ||||
foreach ($changesets as $changeset) { | foreach ($changesets as $changeset) { | ||||
$copies = array(); | $copies = array(); | ||||
foreach ($changeset->getHunks() as $hunk) { | foreach ($changeset->getHunks() as $hunk) { | ||||
$added = array_map('trim', $hunk->getAddedLines()); | $added = array_map('trim', $hunk->getAddedLines()); | ||||
for (reset($added); list($line, $code) = each($added); ) { | for (reset($added); list($line, $code) = each($added); ) { | ||||
if (isset($map[$code])) { // We found a long matching line. | if (isset($map[$code])) { // We found a long matching line. | ||||
if (count($map[$code]) > 16) { | |||||
// If there are a large number of identical lines in this diff, | |||||
// don't try to figure out where this block came from: the | |||||
// analysis is O(N^2), since we need to compare every line | |||||
// against every other line. Even if we arrive at a result, it | |||||
// is unlikely to be meaningful. See T5041. | |||||
continue 2; | |||||
} | |||||
$best_length = 0; | $best_length = 0; | ||||
foreach ($map[$code] as $val) { // Explore all candidates. | foreach ($map[$code] as $val) { // Explore all candidates. | ||||
list($file, $orig_line) = $val; | list($file, $orig_line) = $val; | ||||
$length = 1; | $length = 1; | ||||
// Search also backwards for short lines. | // Search also backwards for short lines. | ||||
foreach (array(-1, 1) as $direction) { | foreach (array(-1, 1) as $direction) { | ||||
$offset = $direction; | $offset = $direction; | ||||
while (!isset($copies[$line + $offset]) && | while (!isset($copies[$line + $offset]) && | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |