diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 54701ee5..930431b7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -23,6 +23,8 @@ phutil_register_library_map(array( 'ArcanistChooseNoRevisionsException' => 'exception', 'ArcanistCloseRevisionWorkflow' => 'workflow/close-revision', 'ArcanistCloseWorkflow' => 'workflow/close', + 'ArcanistCommentRemover' => 'parser/commentremover', + 'ArcanistCommentRemoverTestCase' => 'parser/commentremover/__tests__', 'ArcanistCommitWorkflow' => 'workflow/commit', 'ArcanistConduitLinter' => 'lint/linter/conduit', 'ArcanistConfiguration' => 'configuration', @@ -129,6 +131,7 @@ phutil_register_library_map(array( 'ArcanistCallConduitWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistCloseRevisionWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistCloseWorkflow' => 'ArcanistBaseWorkflow', + 'ArcanistCommentRemoverTestCase' => 'ArcanistPhutilTestCase', 'ArcanistCommitWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistConduitLinter' => 'ArcanistLinter', 'ArcanistCoverWorkflow' => 'ArcanistBaseWorkflow', diff --git a/src/parser/commentremover/ArcanistCommentRemover.php b/src/parser/commentremover/ArcanistCommentRemover.php new file mode 100644 index 00000000..ee06db52 --- /dev/null +++ b/src/parser/commentremover/ArcanistCommentRemover.php @@ -0,0 +1,44 @@ + $line) { + if (!strlen($line)) { + unset($lines[$key]); + continue; + } + if ($line[0] == '#') { + unset($lines[$key]); + continue; + } + break; + } + $lines = array_reverse($lines); + return implode("\n", $lines)."\n"; + } + +} diff --git a/src/parser/commentremover/__init__.php b/src/parser/commentremover/__init__.php new file mode 100644 index 00000000..36cdd7b4 --- /dev/null +++ b/src/parser/commentremover/__init__.php @@ -0,0 +1,10 @@ +assertEqual($expect, ArcanistCommentRemover::removeComments($test)); + } + +} diff --git a/src/parser/commentremover/__tests__/__init__.php b/src/parser/commentremover/__tests__/__init__.php new file mode 100644 index 00000000..05d0a50b --- /dev/null +++ b/src/parser/commentremover/__tests__/__init__.php @@ -0,0 +1,13 @@ +writeScratchFile('create-message', $template); $where = $this->getReadableScratchFilePath('create-message'); @@ -1516,10 +1512,8 @@ EOTEXT ->setName('differential-update-comments') ->editInteractively(); - $comments = preg_replace('/^\s*#.*$/m', '', $comments); - $comments = rtrim($comments); - - if (!strlen($comments)) { + $comments = ArcanistCommentRemover::removeComments($comments); + if (!strlen(trim($comments))) { throw new ArcanistUserAbortException(); } diff --git a/src/workflow/diff/__init__.php b/src/workflow/diff/__init__.php index 9956cab5..db89e37a 100644 --- a/src/workflow/diff/__init__.php +++ b/src/workflow/diff/__init__.php @@ -10,6 +10,7 @@ phutil_require_module('arcanist', 'difference'); phutil_require_module('arcanist', 'differential/commitmessage'); phutil_require_module('arcanist', 'exception/usage'); phutil_require_module('arcanist', 'exception/usage/userabort'); +phutil_require_module('arcanist', 'parser/commentremover'); phutil_require_module('arcanist', 'parser/diff'); phutil_require_module('arcanist', 'parser/diff/changetype'); phutil_require_module('arcanist', 'repository/api/base'); diff --git a/src/workflow/patch/ArcanistPatchWorkflow.php b/src/workflow/patch/ArcanistPatchWorkflow.php index 49d87512..d585b1aa 100644 --- a/src/workflow/patch/ArcanistPatchWorkflow.php +++ b/src/workflow/patch/ArcanistPatchWorkflow.php @@ -662,11 +662,8 @@ EOTEXT ->setName('arcanist-patch-commit-message') ->editInteractively(); - $commit_message = preg_replace('/^\s*#.*$/m', - '', - $commit_message); - $commit_message = rtrim($commit_message); - if (!strlen($commit_message)) { + $commit_message = ArcanistCommentRemover::removeComments($commit_message); + if (!strlen(trim($commit_message))) { throw new ArcanistUserAbortException(); } } diff --git a/src/workflow/patch/__init__.php b/src/workflow/patch/__init__.php index 7e2852ad..dd479a0f 100644 --- a/src/workflow/patch/__init__.php +++ b/src/workflow/patch/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('arcanist', 'differential/constants/revisionstatus'); phutil_require_module('arcanist', 'exception/usage'); phutil_require_module('arcanist', 'exception/usage/userabort'); phutil_require_module('arcanist', 'parser/bundle'); +phutil_require_module('arcanist', 'parser/commentremover'); phutil_require_module('arcanist', 'parser/diff/changetype'); phutil_require_module('arcanist', 'workflow/base');