mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-13 12:54:53 +01:00
Summary: Ref T4292. Ref T10366. Depends on D15751. Today, generating repository commands is purely a function of the repository, so they use protocols and credentials based on the repository configuration. For example, a repository with an SSH "remote URI" always generate SSH "remote commands". This needs to change in the future: - After T10366, repositories won't necessarily just have one type of remote URI. They can only have one at a time still, but the repository itself won't change based on which one is currently active. - For T4292, I need to generate intracluster commands, regardless of repository configuration. These will have different protocols and credentials. Prepare for these cases by separating out command construction, so they'll be able to generate commands in a more flexible way. Test Plan: - Added unit tests. - Browsed diffusion. - Ran `bin/phd debug pull` to pull a bunch of repos. - Ran daemons. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4292, T10366 Differential Revision: https://secure.phabricator.com/D15752
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class DiffusionMercurialCommandEngine
|
|
extends DiffusionCommandEngine {
|
|
|
|
protected function canBuildForRepository(
|
|
PhabricatorRepository $repository) {
|
|
return $repository->isHg();
|
|
}
|
|
|
|
protected function newFormattedCommand($pattern, array $argv) {
|
|
$args = array();
|
|
|
|
if ($this->isAnySSHProtocol()) {
|
|
$pattern = "hg --config ui.ssh=%s {$pattern}";
|
|
$args[] = $this->getSSHWrapper();
|
|
} else {
|
|
$pattern = "hg {$pattern}";
|
|
}
|
|
|
|
return array($pattern, array_merge($args, $argv));
|
|
}
|
|
|
|
protected function newCustomEnvironment() {
|
|
$env = array();
|
|
|
|
// NOTE: This overrides certain configuration, extensions, and settings
|
|
// which make Mercurial commands do random unusual things.
|
|
$env['HGPLAIN'] = 1;
|
|
|
|
return $env;
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
//
|
|
// After Jan 2015, it may also fail to write to a revision branch cache.
|
|
|
|
$ignore = array(
|
|
'ignoring untrusted configuration option',
|
|
"couldn't write revision branch cache:",
|
|
);
|
|
|
|
foreach ($ignore as $key => $pattern) {
|
|
$ignore[$key] = preg_quote($pattern, '/');
|
|
}
|
|
|
|
$ignore = '('.implode('|', $ignore).')';
|
|
|
|
$lines = preg_split('/(?<=\n)/', $stdout);
|
|
$regex = '/'.$ignore.'.*\n$/';
|
|
|
|
foreach ($lines as $key => $line) {
|
|
$lines[$key] = preg_replace($regex, '', $line);
|
|
}
|
|
|
|
return implode('', $lines);
|
|
}
|
|
|
|
}
|