diff --git a/src/applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php b/src/applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php index d6c6aab39e..3d552d0725 100644 --- a/src/applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php +++ b/src/applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php @@ -128,6 +128,7 @@ extends ConduitAPI_diffusion_abstractquery_Method { hgsprintf('reverse(%s::%s)', '0', $commit_hash), $path_arg); + $stdout = PhabricatorRepository::filterMercurialDebugOutput($stdout); $lines = explode("\n", trim($stdout)); $lines = array_slice($lines, $offset); diff --git a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php index cd1cbcd720..602b2b6123 100644 --- a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php +++ b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php @@ -12,6 +12,7 @@ final class DiffusionLowLevelMercurialBranchesQuery // NOTE: `--debug` gives us 40-character hashes. list($stdout) = $repository->execxLocalCommand( '--debug branches'); + $stdout = PhabricatorRepository::filterMercurialDebugOutput($stdout); $branches = array(); diff --git a/src/applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php b/src/applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php index ec19f9cbce..dc9f900ce8 100644 --- a/src/applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php +++ b/src/applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php @@ -10,6 +10,7 @@ final class DiffusionMercurialCommitParentsQuery list($stdout) = $repository->execxLocalCommand( 'log --debug --limit 1 --template={parents} --rev %s', $drequest->getStableCommitName()); + $stdout = PhabricatorRepository::filterMercurialDebugOutput($stdout); $hashes = preg_split('/\s+/', trim($stdout)); foreach ($hashes as $key => $value) { diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 2ce03840a0..64ce761e72 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -440,6 +440,29 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO return $args; } + /** + * Sanitize output of an `hg` command invoked with the `--debug` flag to make + * it usable. + * + * @param string Output from `hg --debug ...` + * @return string Usable output. + */ + public static function filterMercurialDebugOutput($stdout) { + // When hg commands are run with `--debug` and some config file isn't + // trusted, Mercurial prints out a warning to stdout, twice, after Feb 2011. + // + // http://selenic.com/pipermail/mercurial-devel/2011-February/028541.html + + $lines = preg_split('/(?<=\n)/', $stdout); + $regex = '/ignoring untrusted configuration option .*\n$/'; + + foreach ($lines as $key => $line) { + $lines[$key] = preg_replace($regex, '', $line); + } + + return implode('', $lines); + } + public function getURI() { return '/diffusion/'.$this->getCallsign().'/'; } diff --git a/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php b/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php index 69f18f454a..5b60b2968e 100644 --- a/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php +++ b/src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php @@ -107,5 +107,52 @@ final class PhabricatorRepositoryTestCase } + public function testFilterMercurialDebugOutput() { + $map = array( + "" => "", + + "quack\n" => "quack\n", + + "ignoring untrusted configuration option x.y = z\nquack\n" => + "quack\n", + + "ignoring untrusted configuration option x.y = z\n". + "ignoring untrusted configuration option x.y = z\n". + "quack\n" => + "quack\n", + + "ignoring untrusted configuration option x.y = z\n". + "ignoring untrusted configuration option x.y = z\n". + "ignoring untrusted configuration option x.y = z\n". + "quack\n" => + "quack\n", + + "quack\n". + "ignoring untrusted configuration option x.y = z\n". + "ignoring untrusted configuration option x.y = z\n". + "ignoring untrusted configuration option x.y = z\n" => + "quack\n", + + "ignoring untrusted configuration option x.y = z\n". + "ignoring untrusted configuration option x.y = z\n". + "duck\n". + "ignoring untrusted configuration option x.y = z\n". + "ignoring untrusted configuration option x.y = z\n". + "bread\n". + "ignoring untrusted configuration option x.y = z\n". + "quack\n" => + "duck\nbread\nquack\n", + + "ignoring untrusted configuration option x.y = z\n". + "duckignoring untrusted configuration option x.y = z\n". + "quack" => + "duckquack", + ); + + foreach ($map as $input => $expect) { + $actual = PhabricatorRepository::filterMercurialDebugOutput($input); + $this->assertEqual($expect, $actual, $input); + } + } }