@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Work around `hg` echoing warnings to stdout under --debug

Summary:
Ref T615. Ref T4237. With `--debug`, Mercurial will echo an "ignoring untrusted configuration option" warning **to stdout** if `.hgrc` has the wrong owner.

However, we need `--debug` to make `{parents}` usable, at least until the patches I got into the upstream are widely deployed. So after getting `--debug` output, strip off any leading warnings.

These warnings should always be in English, at least, since we set `LANG` explicitly.

Test Plan: Unit tests. @asherkin, maybe you can confirm this? I can't actually get the warning, but I think my `hg` in PATH is just a bit out of date.

Reviewers: asherkin, btrahan

Reviewed By: asherkin

CC: asherkin, aran

Maniphest Tasks: T615, T4237

Differential Revision: https://secure.phabricator.com/D7784

+73
+1
src/applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php
··· 128 128 hgsprintf('reverse(%s::%s)', '0', $commit_hash), 129 129 $path_arg); 130 130 131 + $stdout = PhabricatorRepository::filterMercurialDebugOutput($stdout); 131 132 $lines = explode("\n", trim($stdout)); 132 133 $lines = array_slice($lines, $offset); 133 134
+1
src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php
··· 12 12 // NOTE: `--debug` gives us 40-character hashes. 13 13 list($stdout) = $repository->execxLocalCommand( 14 14 '--debug branches'); 15 + $stdout = PhabricatorRepository::filterMercurialDebugOutput($stdout); 15 16 16 17 $branches = array(); 17 18
+1
src/applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php
··· 10 10 list($stdout) = $repository->execxLocalCommand( 11 11 'log --debug --limit 1 --template={parents} --rev %s', 12 12 $drequest->getStableCommitName()); 13 + $stdout = PhabricatorRepository::filterMercurialDebugOutput($stdout); 13 14 14 15 $hashes = preg_split('/\s+/', trim($stdout)); 15 16 foreach ($hashes as $key => $value) {
+23
src/applications/repository/storage/PhabricatorRepository.php
··· 440 440 return $args; 441 441 } 442 442 443 + /** 444 + * Sanitize output of an `hg` command invoked with the `--debug` flag to make 445 + * it usable. 446 + * 447 + * @param string Output from `hg --debug ...` 448 + * @return string Usable output. 449 + */ 450 + public static function filterMercurialDebugOutput($stdout) { 451 + // When hg commands are run with `--debug` and some config file isn't 452 + // trusted, Mercurial prints out a warning to stdout, twice, after Feb 2011. 453 + // 454 + // http://selenic.com/pipermail/mercurial-devel/2011-February/028541.html 455 + 456 + $lines = preg_split('/(?<=\n)/', $stdout); 457 + $regex = '/ignoring untrusted configuration option .*\n$/'; 458 + 459 + foreach ($lines as $key => $line) { 460 + $lines[$key] = preg_replace($regex, '', $line); 461 + } 462 + 463 + return implode('', $lines); 464 + } 465 + 443 466 public function getURI() { 444 467 return '/diffusion/'.$this->getCallsign().'/'; 445 468 }
+47
src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php
··· 107 107 108 108 } 109 109 110 + public function testFilterMercurialDebugOutput() { 111 + $map = array( 112 + "" => "", 113 + 114 + "quack\n" => "quack\n", 115 + 116 + "ignoring untrusted configuration option x.y = z\nquack\n" => 117 + "quack\n", 118 + 119 + "ignoring untrusted configuration option x.y = z\n". 120 + "ignoring untrusted configuration option x.y = z\n". 121 + "quack\n" => 122 + "quack\n", 123 + 124 + "ignoring untrusted configuration option x.y = z\n". 125 + "ignoring untrusted configuration option x.y = z\n". 126 + "ignoring untrusted configuration option x.y = z\n". 127 + "quack\n" => 128 + "quack\n", 129 + 130 + "quack\n". 131 + "ignoring untrusted configuration option x.y = z\n". 132 + "ignoring untrusted configuration option x.y = z\n". 133 + "ignoring untrusted configuration option x.y = z\n" => 134 + "quack\n", 135 + 136 + "ignoring untrusted configuration option x.y = z\n". 137 + "ignoring untrusted configuration option x.y = z\n". 138 + "duck\n". 139 + "ignoring untrusted configuration option x.y = z\n". 140 + "ignoring untrusted configuration option x.y = z\n". 141 + "bread\n". 142 + "ignoring untrusted configuration option x.y = z\n". 143 + "quack\n" => 144 + "duck\nbread\nquack\n", 145 + 146 + "ignoring untrusted configuration option x.y = z\n". 147 + "duckignoring untrusted configuration option x.y = z\n". 148 + "quack" => 149 + "duckquack", 150 + ); 151 + 152 + foreach ($map as $input => $expect) { 153 + $actual = PhabricatorRepository::filterMercurialDebugOutput($input); 154 + $this->assertEqual($expect, $actual, $input); 155 + } 156 + } 110 157 111 158 }