mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-30 02:32:41 +01:00
Allow ArcanistDiffParser to parse diff.suppress-blank-empty
Git diffs
Summary: See D3963. Instead, parse these diffs so they'll work with `--raw`, etc. Test Plan: Generated a failing diff, added it as a test case. Fixed issue. Ran test suite. Ran `arc` against it: $ git -c diff.suppress-blank-empty=true diff HEAD | arc diff --raw --only --conduit-uri=http://local.aphront.com:8080/ Reading diff from stdin... Created a new Differential diff: Diff URI: http://local.aphront.com:8080/differential/diff/103/ Included changes: M things Reviewers: vrana, jiiix, btrahan Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D3969
This commit is contained in:
parent
515399c0f6
commit
2d3d7be09a
3 changed files with 29 additions and 14 deletions
|
@ -840,12 +840,17 @@ final class ArcanistDiffParser {
|
||||||
$add = 0;
|
$add = 0;
|
||||||
$del = 0;
|
$del = 0;
|
||||||
|
|
||||||
$advance = false;
|
$hit_next_hunk = false;
|
||||||
while ((($line = $this->nextLine()) !== null)) {
|
while ((($line = $this->nextLine()) !== null)) {
|
||||||
if (strlen($line)) {
|
if (strlen(rtrim($line, "\r\n"))) {
|
||||||
$char = $line[0];
|
$char = $line[0];
|
||||||
} else {
|
} else {
|
||||||
$char = '~';
|
// Normally, we do not encouter empty lines in diffs, because
|
||||||
|
// unchanged lines have an initial space. However, in Git, with
|
||||||
|
// the option `diff.suppress-blank-empty` set, unchanged blank lines
|
||||||
|
// emit as completely empty. If we encounter a completely empty line,
|
||||||
|
// treat it as a ' ' (i.e., unchanged empty line) line.
|
||||||
|
$char = ' ';
|
||||||
}
|
}
|
||||||
switch ($char) {
|
switch ($char) {
|
||||||
case '\\':
|
case '\\':
|
||||||
|
@ -861,20 +866,19 @@ final class ArcanistDiffParser {
|
||||||
$hunk->setIsMissingNewNewline(true);
|
$hunk->setIsMissingNewNewline(true);
|
||||||
}
|
}
|
||||||
if (!$new_len) {
|
if (!$new_len) {
|
||||||
$advance = true;
|
|
||||||
break 2;
|
break 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
if (!$new_len) {
|
|
||||||
break 2;
|
|
||||||
}
|
|
||||||
++$add;
|
++$add;
|
||||||
--$new_len;
|
--$new_len;
|
||||||
$real[] = $line;
|
$real[] = $line;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
if (!$old_len) {
|
if (!$old_len) {
|
||||||
|
// In this case, we've hit "---" from a new file. So don't
|
||||||
|
// advance the line cursor.
|
||||||
|
$hit_next_hunk = true;
|
||||||
break 2;
|
break 2;
|
||||||
}
|
}
|
||||||
++$del;
|
++$del;
|
||||||
|
@ -889,17 +893,14 @@ final class ArcanistDiffParser {
|
||||||
--$new_len;
|
--$new_len;
|
||||||
$real[] = $line;
|
$real[] = $line;
|
||||||
break;
|
break;
|
||||||
case "\r":
|
|
||||||
case "\n":
|
|
||||||
case '~':
|
|
||||||
$advance = true;
|
|
||||||
break 2;
|
|
||||||
default:
|
default:
|
||||||
|
// We hit something, likely another hunk.
|
||||||
|
$hit_next_hunk = true;
|
||||||
break 2;
|
break 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($old_len != 0 || $new_len != 0) {
|
if ($old_len || $new_len) {
|
||||||
$this->didFailParse("Found the wrong number of hunk lines.");
|
$this->didFailParse("Found the wrong number of hunk lines.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,7 +940,7 @@ final class ArcanistDiffParser {
|
||||||
$change->addHunk($hunk);
|
$change->addHunk($hunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($advance) {
|
if (!$hit_next_hunk) {
|
||||||
$line = $this->nextNonemptyLine();
|
$line = $this->nextNonemptyLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -536,6 +536,9 @@ EOTEXT
|
||||||
case 'more-newlines.svndiff':
|
case 'more-newlines.svndiff':
|
||||||
$this->assertEqual(1, count($changes));
|
$this->assertEqual(1, count($changes));
|
||||||
break;
|
break;
|
||||||
|
case 'suppress-blank-empty.gitdiff':
|
||||||
|
$this->assertEqual(1, count($changes));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("No test block for diff file {$diff_file}.");
|
throw new Exception("No test block for diff file {$diff_file}.");
|
||||||
break;
|
break;
|
||||||
|
|
11
src/parser/__tests__/diff/suppress-blank-empty.gitdiff
Normal file
11
src/parser/__tests__/diff/suppress-blank-empty.gitdiff
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
diff --git a/things b/things
|
||||||
|
index b6c8793..0c96a0f 100644
|
||||||
|
--- a/things
|
||||||
|
+++ b/things
|
||||||
|
@@ -1,5 +1,5 @@
|
||||||
|
apple
|
||||||
|
|
||||||
|
-banana
|
||||||
|
+bananas
|
||||||
|
|
||||||
|
cherry
|
Loading…
Reference in a new issue