1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Adapt to style changes; fix performance bug when loading hunks for changesets.

This commit is contained in:
Manuel Klimek 2012-08-13 19:32:19 +00:00 committed by Manuel Klimek
parent 0ce886121c
commit 10773c5cb6
2 changed files with 21 additions and 14 deletions

View file

@ -152,6 +152,13 @@ final class DifferentialCommentMail extends DifferentialMail {
if ($inlines) { if ($inlines) {
$body[] = 'INLINE COMMENTS'; $body[] = 'INLINE COMMENTS';
$changesets = $this->getChangesets(); $changesets = $this->getChangesets();
if (PhabricatorEnv::getEnvConfig(
'metamta.differential.unified-comment-context', false)) {
foreach ($changesets as $changeset) {
$changeset->attachHunks($changeset->loadHunks());
}
}
foreach ($inlines as $inline) { foreach ($inlines as $inline) {
$changeset = $changesets[$inline->getChangesetID()]; $changeset = $changesets[$inline->getChangesetID()];
if (!$changeset) { if (!$changeset) {
@ -172,8 +179,6 @@ final class DifferentialCommentMail extends DifferentialMail {
} else { } else {
$body[] = "================"; $body[] = "================";
$body[] = "Comment at: " . $file . ":" . $range; $body[] = "Comment at: " . $file . ":" . $range;
$changeset->attachHunks($changeset->loadHunks());
$body[] = $changeset->makeContextDiff($inline, 1); $body[] = $changeset->makeContextDiff($inline, 1);
$body[] = "----------------"; $body[] = "----------------";

View file

@ -217,7 +217,7 @@ final class DifferentialChangeset extends DifferentialDAO {
public function makeContextDiff($inline, $add_context) { public function makeContextDiff($inline, $add_context) {
$context = array(); $context = array();
$debug = False; $debug = false;
if ($debug) { if ($debug) {
$context[] = 'Inline: '.$inline->getIsNewFile().' '. $context[] = 'Inline: '.$inline->getIsNewFile().' '.
$inline->getLineNumber().' '.$inline->getLineLength(); $inline->getLineNumber().' '.$inline->getLineLength();
@ -254,31 +254,33 @@ final class DifferentialChangeset extends DifferentialDAO {
$hunk_offset = array( "-" => NULL, "+" => NULL ); $hunk_offset = array( "-" => NULL, "+" => NULL );
$hunk_last = array( "-" => NULL, "+" => NULL ); $hunk_last = array( "-" => NULL, "+" => NULL );
foreach (explode("\n", $hunk->getChanges()) as $line) { foreach (explode("\n", $hunk->getChanges()) as $line) {
$inCommon = strncmp($line, " ", 1) === 0; $in_common = strncmp($line, " ", 1) === 0;
$inOld = strncmp($line, "-", 1) === 0 || $inCommon; $in_old = strncmp($line, "-", 1) === 0 || $in_common;
$inNew = strncmp($line, "+", 1) === 0 || $inCommon; $in_new = strncmp($line, "+", 1) === 0 || $in_common;
$inSelected = strncmp($line, $prefix, 1) === 0; $in_selected = strncmp($line, $prefix, 1) === 0;
$skip = !$inSelected && !$inCommon; $skip = !$in_selected && !$in_common;
if ($hunk_pos[$prefix] <= $end) { if ($hunk_pos[$prefix] <= $end) {
if ($start <= $hunk_pos[$prefix]) { if ($start <= $hunk_pos[$prefix]) {
if (!$skip || ($hunk_pos[$prefix] != $start && if (!$skip || ($hunk_pos[$prefix] != $start &&
$hunk_pos[$prefix] != $end)) { $hunk_pos[$prefix] != $end)) {
if ($inOld) { if ($in_old) {
if ($hunk_offset["-"] === NULL) if ($hunk_offset["-"] === NULL) {
$hunk_offset["-"] = $hunk_pos["-"]; $hunk_offset["-"] = $hunk_pos["-"];
}
$hunk_last["-"] = $hunk_pos["-"]; $hunk_last["-"] = $hunk_pos["-"];
} }
if ($inNew) { if ($in_new) {
if ($hunk_offset["+"] === NULL) if ($hunk_offset["+"] === NULL) {
$hunk_offset["+"] = $hunk_pos["+"]; $hunk_offset["+"] = $hunk_pos["+"];
}
$hunk_last["+"] = $hunk_pos["+"]; $hunk_last["+"] = $hunk_pos["+"];
} }
$hunk_content[] = $line; $hunk_content[] = $line;
} }
} }
if ($inOld) ++$hunk_pos["-"]; if ($in_old) { ++$hunk_pos["-"]; }
if ($inNew) ++$hunk_pos["+"]; if ($in_new) { ++$hunk_pos["+"]; }
} }
} }
if ($hunk_offset["-"] !== NULL || $hunk_offset["+"] !== NULL) { if ($hunk_offset["-"] !== NULL || $hunk_offset["+"] !== NULL) {