1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-09 00:12:40 +01:00

(experimental) Merge branch 'master' into experimental

This commit is contained in:
epriestley 2017-10-24 14:06:44 -07:00
commit 856f79bba5
12 changed files with 118 additions and 16 deletions

View file

@ -25,8 +25,15 @@ final class ArcanistLintMessage extends Phobject {
$message = new ArcanistLintMessage(); $message = new ArcanistLintMessage();
$message->setPath($dict['path']); $message->setPath($dict['path']);
$message->setLine($dict['line']);
$message->setChar($dict['char']); if (isset($dict['line'])) {
$message->setLine($dict['line']);
}
if (isset($dict['char'])) {
$message->setChar($dict['char']);
}
$message->setCode($dict['code']); $message->setCode($dict['code']);
$message->setSeverity($dict['severity']); $message->setSeverity($dict['severity']);
$message->setName($dict['name']); $message->setName($dict['name']);

View file

@ -235,8 +235,11 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer {
} }
for ($ii = $start; $ii < $start + $new_impact; $ii++) { for ($ii = $start; $ii < $start + $new_impact; $ii++) {
// If the patch was at the end of the file and ends with a newline, we
// won't have an actual entry in the array for the last line, even though
// we want to show it in the diff.
$out[] = array( $out[] = array(
'text' => $new_lines[$ii - 1], 'text' => idx($new_lines, $ii - 1, ''),
'type' => '+', 'type' => '+',
'chevron' => ($ii == $start), 'chevron' => ($ii == $start),
); );
@ -265,9 +268,17 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer {
} }
} }
// If the line doesn't actually end in a newline, add one so the layout
// doesn't mess up. This can happen when the last line of the old file
// didn't have a newline at the end.
$text = $spec['text'];
if (!preg_match('/\n\z/', $spec['text'])) {
$text .= "\n";
}
$result[] = $this->renderLine( $result[] = $this->renderLine(
idx($spec, 'number'), idx($spec, 'number'),
$spec['text'], $text,
$chevron, $chevron,
idx($spec, 'type')); idx($spec, 'type'));
@ -310,6 +321,15 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer {
$offset += strlen($line); $offset += strlen($line);
} }
// If the last line ends in a newline, add a virtual offset for the final
// line with no characters on it. This allows lint messages to target the
// last line of the file at character 1.
if ($lines) {
if (preg_match('/\n\z/', $line)) {
$line_map[$number] = $offset;
}
}
return $line_map; return $line_map;
} }

View file

@ -120,6 +120,28 @@ EOTEXT;
'original' => "\n", 'original' => "\n",
'replacement' => '', 'replacement' => '',
), ),
'eofnewline' => array(
'line' => 1,
'char' => 7,
'original' => '',
'replacement' => "\n",
),
'eofmultilinechar' => array(
'line' => 5,
'char' => 3,
'original' => '',
'replacement' => "\nX\nY\n",
),
'eofmultilineline' => array(
'line' => 6,
'char' => 1,
'original' => '',
'replacement' => "\nX\nY\n",
),
); );
$defaults = array( $defaults = array(
@ -132,8 +154,6 @@ EOTEXT;
foreach ($map as $key => $test_case) { foreach ($map as $key => $test_case) {
$data = $this->readTestData("{$key}.txt"); $data = $this->readTestData("{$key}.txt");
$data = preg_replace('/~+\s*$/m', '', $data);
$expect = $this->readTestData("{$key}.expect"); $expect = $this->readTestData("{$key}.expect");
$test_case = $test_case + $defaults; $test_case = $test_case + $defaults;
@ -184,11 +204,6 @@ EOTEXT;
throw $ex; throw $ex;
} }
// Trim "~" off the ends of lines. This allows the "expect" file to test
// for trailing whitespace without actually containing trailing
// whitespace.
$expect = preg_replace('/~+$/m', '', $expect);
$this->assertEqual( $this->assertEqual(
$expect, $expect,
$actual, $actual,
@ -200,7 +215,19 @@ EOTEXT;
private function readTestData($filename) { private function readTestData($filename) {
$path = dirname(__FILE__).'/data/'.$filename; $path = dirname(__FILE__).'/data/'.$filename;
return Filesystem::readFile($path); $data = Filesystem::readFile($path);
// If we find "~~~" at the end of the file, get rid of it and any whitespace
// afterwards. This allows specifying data files with trailing empty
// lines.
$data = preg_replace('/~~~\s*\z/', '', $data);
// Trim "~" off the ends of lines. This allows the "expect" file to test
// for trailing whitespace without actually containing trailing
// whitespace.
$data = preg_replace('/~$/m', '', $data);
return $data;
} }
} }

View file

@ -0,0 +1,12 @@
>>> Lint for path/to/example.c:
Warning (WARN123) Lint Warning
Consider this.
3 3
4 4
5 5
>>> + ~
+ X
+ Y

View file

@ -0,0 +1,5 @@
1
2
3
4
5

View file

@ -0,0 +1,12 @@
>>> Lint for path/to/example.c:
Warning (WARN123) Lint Warning
Consider this.
3 3
4 4
5 5
>>> + ~
+ X
+ Y

View file

@ -0,0 +1,5 @@
1
2
3
4
5

View file

@ -0,0 +1,9 @@
>>> Lint for path/to/example.c:
Warning (WARN123) Lint Warning
Consider this.
>>> - 1 abcdef
+ abcdef
+ ~

View file

@ -0,0 +1 @@
abcdef~~~

View file

@ -1,3 +1,3 @@
Adrift upon the sea. Adrift upon the sea.
~ ~~~

View file

@ -497,6 +497,10 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
return null; return null;
} }
if (!strlen($branch)) {
return null;
}
return $branch; return $branch;
} }
@ -509,7 +513,7 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
// Verify this, and strip it. // Verify this, and strip it.
$ref = rtrim($stdout); $ref = rtrim($stdout);
$branch = $this->getBranchNameFromRef($ref); $branch = $this->getBranchNameFromRef($ref);
if (!$branch) { if ($branch === null) {
throw new Exception( throw new Exception(
pht('Failed to parse %s output!', 'git symbolic-ref')); pht('Failed to parse %s output!', 'git symbolic-ref'));
} }
@ -1015,7 +1019,7 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
list($ref, $hash, $epoch, $tree, $desc, $text) = $fields; list($ref, $hash, $epoch, $tree, $desc, $text) = $fields;
$branch = $this->getBranchNameFromRef($ref); $branch = $this->getBranchNameFromRef($ref);
if ($branch) { if ($branch !== null) {
$result[] = array( $result[] = array(
'current' => ($branch === $current), 'current' => ($branch === $current),
'name' => $branch, 'name' => $branch,

View file

@ -444,7 +444,7 @@ EOTEXT
$branch = $this->getArgument('branch'); $branch = $this->getArgument('branch');
if (empty($branch)) { if (empty($branch)) {
$branch = $this->getBranchOrBookmark(); $branch = $this->getBranchOrBookmark();
if ($branch) { if ($branch !== null) {
$this->branchType = $this->getBranchType($branch); $this->branchType = $this->getBranchType($branch);
// TODO: This message is misleading when landing a detached head or // TODO: This message is misleading when landing a detached head or