From f362e5785f4c37f7475f180e717484565ec477f8 Mon Sep 17 00:00:00 2001 From: vrana Date: Mon, 30 Apr 2012 11:05:30 -0700 Subject: [PATCH] Ignore non-existing diffs in copied code detector script Auditors: epriestley --- scripts/differential/detect_copied_code.php | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/differential/detect_copied_code.php b/scripts/differential/detect_copied_code.php index 2c62d061a5..d3dfce46cf 100755 --- a/scripts/differential/detect_copied_code.php +++ b/scripts/differential/detect_copied_code.php @@ -29,17 +29,19 @@ list(, $from, $to) = $argv; for ($diff_id = $from; $diff_id <= $to; $diff_id++) { echo "Processing $diff_id"; $diff = id(new DifferentialDiff())->load($diff_id); - $diff->attachChangesets($diff->loadChangesets()); - $orig_copy = array(); - foreach ($diff->getChangesets() as $i => $changeset) { - $orig_copy[$i] = idx((array)$changeset->getMetadata(), 'copy:lines'); - $changeset->attachHunks($changeset->loadHunks()); - } - $diff->detectCopiedCode(); - foreach ($diff->getChangesets() as $i => $changeset) { - if (idx($changeset->getMetadata(), 'copy:lines') || $orig_copy[$i]) { - echo "."; - $changeset->save(); + if ($diff) { + $diff->attachChangesets($diff->loadChangesets()); + $orig_copy = array(); + foreach ($diff->getChangesets() as $i => $changeset) { + $orig_copy[$i] = idx((array)$changeset->getMetadata(), 'copy:lines'); + $changeset->attachHunks($changeset->loadHunks()); + } + $diff->detectCopiedCode(); + foreach ($diff->getChangesets() as $i => $changeset) { + if (idx($changeset->getMetadata(), 'copy:lines') || $orig_copy[$i]) { + echo "."; + $changeset->save(); + } } } echo "\n";