Differential D21278 Diff 50672 src/applications/differential/query/DifferentialDiffInlineCommentQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialDiffInlineCommentQuery.php
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | $rows = queryfx_all( | ||||
mpull($comments, 'getID')); | mpull($comments, 'getID')); | ||||
$id_map = ipull($rows, 'commentID'); | $id_map = ipull($rows, 'commentID'); | ||||
$id_map = array_fuse($id_map); | $id_map = array_fuse($id_map); | ||||
return $id_map; | return $id_map; | ||||
} | } | ||||
protected function newInlineContextMap(array $inlines) { | |||||
$viewer = $this->getViewer(); | |||||
$map = array(); | |||||
foreach ($inlines as $key => $inline) { | |||||
$changeset = id(new DifferentialChangesetQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($inline->getChangesetID())) | |||||
->needHunks(true) | |||||
->executeOne(); | |||||
if (!$changeset) { | |||||
continue; | |||||
} | |||||
$hunks = $changeset->getHunks(); | |||||
$is_simple = | |||||
(count($hunks) === 1) && | |||||
((int)head($hunks)->getOldOffset() <= 1) && | |||||
((int)head($hunks)->getNewOffset() <= 1); | |||||
if (!$is_simple) { | |||||
continue; | |||||
} | |||||
if ($inline->getIsNewFile()) { | |||||
$vector = $changeset->getNewStatePathVector(); | |||||
$filename = last($vector); | |||||
$corpus = $changeset->makeNewFile(); | |||||
} else { | |||||
$vector = $changeset->getOldStatePathVector(); | |||||
$filename = last($vector); | |||||
$corpus = $changeset->makeOldFile(); | |||||
} | |||||
$corpus = phutil_split_lines($corpus); | |||||
// Adjust the line number into a 0-based offset. | |||||
$offset = $inline->getLineNumber(); | |||||
$offset = $offset - 1; | |||||
// Adjust the inclusive range length into a row count. | |||||
$length = $inline->getLineLength(); | |||||
$length = $length + 1; | |||||
$head_min = max(0, $offset - 3); | |||||
$head_max = $offset; | |||||
$head_len = $head_max - $head_min; | |||||
if ($head_len) { | |||||
$head = array_slice($corpus, $head_min, $head_len, true); | |||||
$head = $this->simplifyContext($head, true); | |||||
} else { | |||||
$head = array(); | |||||
} | |||||
$body = array_slice($corpus, $offset, $length, true); | |||||
$tail = array_slice($corpus, $offset + $length, 3, true); | |||||
$tail = $this->simplifyContext($tail, false); | |||||
$context = id(new PhabricatorDiffInlineCommentContext()) | |||||
->setFilename($filename) | |||||
->setHeadLines($head) | |||||
->setBodyLines($body) | |||||
->setTailLines($tail); | |||||
$map[$key] = $context; | |||||
} | |||||
return $map; | |||||
} | |||||
} | } |