1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 00:10:57 +01:00

Trim lines before detecting copied/moved code

Test Plan:
https://secure.phabricator.com/differential/diff/4043/
{F10761}

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2352
This commit is contained in:
vrana 2012-04-30 16:40:57 -07:00
parent 4cc61687aa
commit 2f047dce43

View file

@ -156,7 +156,7 @@ final class DifferentialDiff extends DifferentialDAO {
return $diff; return $diff;
} }
public function detectCopiedCode($min_width = 40, $min_lines = 3) { public function detectCopiedCode($min_width = 30, $min_lines = 3) {
$map = array(); $map = array();
$files = array(); $files = array();
$types = array(); $types = array();
@ -167,7 +167,7 @@ final class DifferentialDiff extends DifferentialDAO {
foreach (explode("\n", $hunk->getChanges()) as $code) { foreach (explode("\n", $hunk->getChanges()) as $code) {
$type = (isset($code[0]) ? $code[0] : ''); $type = (isset($code[0]) ? $code[0] : '');
if ($type == '-' || $type == ' ') { if ($type == '-' || $type == ' ') {
$code = (string)substr($code, 1); $code = trim(substr($code, 1));
$files[$file][$line] = $code; $files[$file][$line] = $code;
$types[$file][$line] = $type; $types[$file][$line] = $type;
if (strlen($code) >= $min_width) { if (strlen($code) >= $min_width) {
@ -182,7 +182,7 @@ final class DifferentialDiff extends DifferentialDAO {
foreach ($this->changesets as $changeset) { foreach ($this->changesets as $changeset) {
$copies = array(); $copies = array();
foreach ($changeset->getHunks() as $hunk) { foreach ($changeset->getHunks() as $hunk) {
$added = $hunk->getAddedLines(); $added = array_map('trim', $hunk->getAddedLines());
for (reset($added); list($line, $code) = each($added); next($added)) { for (reset($added); list($line, $code) = each($added); next($added)) {
if (isset($map[$code])) { // We found a long matching line. if (isset($map[$code])) { // We found a long matching line.
$best_length = 0; $best_length = 0;