mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +01:00
Simplify Herald logic for loading Differential changes
Summary: Ref T4045. These three methods are fairly copy-pastey. Provide a more formal DifferentialHunk API for querying various types of line ranges. Test Plan: Used test console to verify that "added content", "removed content", and "changed content" rules still produce the same data. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4045 Differential Revision: https://secure.phabricator.com/D8764
This commit is contained in:
parent
2509c6b0f5
commit
aaf1320b02
2 changed files with 34 additions and 45 deletions
|
@ -9,6 +9,10 @@ final class DifferentialHunk extends DifferentialDAO {
|
|||
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 @@ final class DifferentialHunk extends DifferentialDAO {
|
|||
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);
|
||||
|
|
|
@ -204,56 +204,21 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
|
|||
}
|
||||
|
||||
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 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
|
|||
$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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue