Revert "Use phutil_split_lines() in Differential"
This reverts commit f6cb51562e
.
This has some bugs in normal diffs that I haven't immediately been able to figure out. I'll reapply it once I sort them out.
Auditors: vrana
This commit is contained in:
parent
f6cb51562e
commit
468aeaef0d
|
@ -60,7 +60,7 @@ final class DifferentialChangesetParser {
|
||||||
private $markupEngine;
|
private $markupEngine;
|
||||||
private $highlightErrors;
|
private $highlightErrors;
|
||||||
|
|
||||||
const CACHE_VERSION = 7;
|
const CACHE_VERSION = 6;
|
||||||
const CACHE_MAX_SIZE = 8e6;
|
const CACHE_MAX_SIZE = 8e6;
|
||||||
|
|
||||||
const ATTR_GENERATED = 'attr:generated';
|
const ATTR_GENERATED = 'attr:generated';
|
||||||
|
@ -132,8 +132,8 @@ final class DifferentialChangesetParser {
|
||||||
foreach ($changeset->getHunks() as $hunk) {
|
foreach ($changeset->getHunks() as $hunk) {
|
||||||
$n_old = $hunk->getOldOffset();
|
$n_old = $hunk->getOldOffset();
|
||||||
$n_new = $hunk->getNewOffset();
|
$n_new = $hunk->getNewOffset();
|
||||||
$changes = phutil_split_lines($hunk->getChanges());
|
$changes = rtrim($hunk->getChanges(), "\n");
|
||||||
foreach ($changes as $line) {
|
foreach (explode("\n", $changes) as $line) {
|
||||||
$diff_type = $line[0]; // Change type in diff of diffs.
|
$diff_type = $line[0]; // Change type in diff of diffs.
|
||||||
$orig_type = $line[1]; // Change type in the original diff.
|
$orig_type = $line[1]; // Change type in the original diff.
|
||||||
if ($diff_type == ' ') {
|
if ($diff_type == ' ') {
|
||||||
|
@ -267,7 +267,12 @@ final class DifferentialChangesetParser {
|
||||||
|
|
||||||
public function parseHunk(DifferentialHunk $hunk) {
|
public function parseHunk(DifferentialHunk $hunk) {
|
||||||
$lines = $hunk->getChanges();
|
$lines = $hunk->getChanges();
|
||||||
$lines = phutil_split_lines($lines);
|
|
||||||
|
$lines = str_replace(
|
||||||
|
array("\t", "\r\n", "\r"),
|
||||||
|
array(' ', "\n", "\n"),
|
||||||
|
$lines);
|
||||||
|
$lines = explode("\n", $lines);
|
||||||
|
|
||||||
$types = array();
|
$types = array();
|
||||||
foreach ($lines as $line_index => $line) {
|
foreach ($lines as $line_index => $line) {
|
||||||
|
@ -568,7 +573,7 @@ final class DifferentialChangesetParser {
|
||||||
$old_corpus[] = $o['text'];
|
$old_corpus[] = $o['text'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$old_corpus_block = implode('', $old_corpus);
|
$old_corpus_block = implode("\n", $old_corpus);
|
||||||
|
|
||||||
$new_corpus = array();
|
$new_corpus = array();
|
||||||
foreach ($this->new as $n) {
|
foreach ($this->new as $n) {
|
||||||
|
@ -576,7 +581,7 @@ final class DifferentialChangesetParser {
|
||||||
$new_corpus[] = $n['text'];
|
$new_corpus[] = $n['text'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$new_corpus_block = implode('', $new_corpus);
|
$new_corpus_block = implode("\n", $new_corpus);
|
||||||
|
|
||||||
$this->markGenerated($new_corpus_block);
|
$this->markGenerated($new_corpus_block);
|
||||||
|
|
||||||
|
@ -595,7 +600,6 @@ final class DifferentialChangesetParser {
|
||||||
'old' => $old_corpus_block,
|
'old' => $old_corpus_block,
|
||||||
'new' => $new_corpus_block,
|
'new' => $new_corpus_block,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->highlightErrors = false;
|
$this->highlightErrors = false;
|
||||||
foreach (Futures($futures) as $key => $future) {
|
foreach (Futures($futures) as $key => $future) {
|
||||||
try {
|
try {
|
||||||
|
@ -816,14 +820,6 @@ final class DifferentialChangesetParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHighlightFuture($corpus) {
|
protected function getHighlightFuture($corpus) {
|
||||||
if (preg_match('/\r(?!\n)/', $corpus)) {
|
|
||||||
// TODO: Pygments converts "\r" newlines into "\n" newlines, so we can't
|
|
||||||
// use it on files with "\r" newlines. If we have "\r" not followed by
|
|
||||||
// "\n" in the file, skip highlighting.
|
|
||||||
$result = phutil_escape_html($corpus);
|
|
||||||
return new ImmediateFuture($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->highlightEngine->getHighlightFuture(
|
return $this->highlightEngine->getHighlightFuture(
|
||||||
$this->highlightEngine->getLanguageFromFilename($this->filename),
|
$this->highlightEngine->getLanguageFromFilename($this->filename),
|
||||||
$corpus);
|
$corpus);
|
||||||
|
@ -831,7 +827,7 @@ final class DifferentialChangesetParser {
|
||||||
|
|
||||||
protected function processHighlightedSource($data, $result) {
|
protected function processHighlightedSource($data, $result) {
|
||||||
|
|
||||||
$result_lines = phutil_split_lines($result);
|
$result_lines = explode("\n", $result);
|
||||||
foreach ($data as $key => $info) {
|
foreach ($data as $key => $info) {
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
unset($result_lines[$key]);
|
unset($result_lines[$key]);
|
||||||
|
@ -1778,20 +1774,13 @@ final class DifferentialChangesetParser {
|
||||||
$notice = $this->renderChangeTypeHeader($this->changeset, false);
|
$notice = $this->renderChangeTypeHeader($this->changeset, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = implode(
|
return implode(
|
||||||
"\n",
|
"\n",
|
||||||
array(
|
array(
|
||||||
$notice,
|
$notice,
|
||||||
$props,
|
$props,
|
||||||
$table,
|
$table,
|
||||||
));
|
));
|
||||||
|
|
||||||
// TODO: Let the user customize their tab width / display style.
|
|
||||||
$result = str_replace("\t", ' ', $result);
|
|
||||||
|
|
||||||
// TODO: We should possibly post-process "\r" as well.
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderChangeTypeHeader($changeset, $force) {
|
protected function renderChangeTypeHeader($changeset, $force) {
|
||||||
|
|
Loading…
Reference in a new issue