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

Make the Arcanist comment remover less aggressive about stripping instructional comments

Summary:
Ref T13098. See PHI858. If you write this at the end of a message in `arc diff`:

```
  Subscribers:
  #projectname

  # NEW DIFFERENTIAL REVISION
  # Describe the changes in this new revision.
  # ...
```

...we'll currently eat the `#projectname` as an instructional comment, even if it is followed by an empty line.

Instead, stop eating stuff once we hit the first empty line. (We escape empty lines in comments already.)

After T13098 I'll maybe adjust this to use a more explicit instruction escape, like `##`, since there's no reason we're bound to `#`.

Test Plan: Added a unit test and made it pass.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13098

Differential Revision: https://secure.phabricator.com/D19639
This commit is contained in:
epriestley 2018-09-05 08:33:13 -07:00
parent 30b7835c37
commit 2650e8627a
2 changed files with 26 additions and 7 deletions

View file

@ -8,21 +8,25 @@ final class ArcanistCommentRemover extends Phobject {
* considered a comment.
*/
public static function removeComments($body) {
$lines = explode("\n", $body);
$body = rtrim($body);
$lines = phutil_split_lines($body);
$lines = array_reverse($lines);
foreach ($lines as $key => $line) {
if (!strlen($line)) {
unset($lines[$key]);
continue;
}
if ($line[0] == '#') {
if (preg_match('/^#/', $line)) {
unset($lines[$key]);
continue;
}
break;
}
$lines = array_reverse($lines);
return implode("\n", $lines)."\n";
$lines = implode('', $lines);
$lines = rtrim($lines)."\n";
return $lines;
}
}

View file

@ -24,6 +24,21 @@ Here is a list:
The end.
EOTEXT;
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));
$test = <<<EOTEXT
Subscribers:
#projectname
# Instructional comments.
EOTEXT;
$expect = <<<EOTEXT
Subscribers:
#projectname
EOTEXT;
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));