diff --git a/src/applications/differential/storage/DifferentialHunk.php b/src/applications/differential/storage/DifferentialHunk.php --- a/src/applications/differential/storage/DifferentialHunk.php +++ b/src/applications/differential/storage/DifferentialHunk.php @@ -9,6 +9,10 @@ protected $newOffset; protected $newLen; + const FLAG_LINES_ADDED = 1; + const FLAG_LINES_REMOVED = 2; + const FLAG_LINES_STABLE = 4; + public function getAddedLines() { return $this->makeContent($include = '+'); } @@ -29,6 +33,26 @@ return implode('', $this->makeContent($include = '-+')); } + public function getContentWithMask($mask) { + $include = array(); + + if (($mask & self::FLAG_LINES_ADDED)) { + $include[] = '+'; + } + + if (($mask & self::FLAG_LINES_REMOVED)) { + $include[] = '-'; + } + + if (($mask & self::FLAG_LINES_STABLE)) { + $include[] = ' '; + } + + $include = implode('', $include); + + return implode('', $this->makeContent($include)); + } + final private function makeContent($include) { $results = array(); $lines = explode("\n", $this->changes); diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php @@ -204,56 +204,21 @@ } protected function loadContentDictionary() { - $changesets = $this->loadChangesets(); - - $hunks = array(); - if ($changesets) { - $hunks = id(new DifferentialHunk())->loadAllWhere( - 'changesetID in (%Ld)', - mpull($changesets, 'getID')); - } - - $dict = array(); - $hunks = mgroup($hunks, 'getChangesetID'); - $changesets = mpull($changesets, null, 'getID'); - foreach ($changesets as $id => $changeset) { - $path = $this->getAbsoluteRepositoryPathForChangeset($changeset); - $content = array(); - foreach (idx($hunks, $id, array()) as $hunk) { - $content[] = $hunk->makeChanges(); - } - $dict[$path] = implode("\n", $content); - } - - return $dict; + $add_lines = DifferentialHunk::FLAG_LINES_ADDED; + $rem_lines = DifferentialHunk::FLAG_LINES_REMOVED; + $mask = ($add_lines | $rem_lines); + return $this->loadContentWithMask($mask); } protected function loadAddedContentDictionary() { - $changesets = $this->loadChangesets(); - - $hunks = array(); - if ($changesets) { - $hunks = id(new DifferentialHunk())->loadAllWhere( - 'changesetID in (%Ld)', - mpull($changesets, 'getID')); - } - - $dict = array(); - $hunks = mgroup($hunks, 'getChangesetID'); - $changesets = mpull($changesets, null, 'getID'); - foreach ($changesets as $id => $changeset) { - $path = $this->getAbsoluteRepositoryPathForChangeset($changeset); - $content = array(); - foreach (idx($hunks, $id, array()) as $hunk) { - $content[] = implode('', $hunk->getAddedLines()); - } - $dict[$path] = implode("\n", $content); - } - - return $dict; + return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_ADDED); } protected function loadRemovedContentDictionary() { + return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_REMOVED); + } + + private function loadContentWithMask($mask) { $changesets = $this->loadChangesets(); $hunks = array(); @@ -270,7 +235,7 @@ $path = $this->getAbsoluteRepositoryPathForChangeset($changeset); $content = array(); foreach (idx($hunks, $id, array()) as $hunk) { - $content[] = implode('', $hunk->getRemovedLines()); + $content[] = $hunk->getContentWithMask($mask); } $dict[$path] = implode("\n", $content); }