1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-23 22:10:54 +01:00

Use HGPLAIN when executing mercurial commands

Summary: See comments. Skip [defaults] in .hgrc when executing commands.

Test Plan: Ran "arc diff" in a mercurial working copy.

Reviewers: Makinde, btrahan

Reviewed By: Makinde

CC: aran, epriestley

Maniphest Tasks: T922

Differential Revision: https://secure.phabricator.com/D1707
This commit is contained in:
epriestley 2012-02-28 16:56:57 -08:00
parent bd3ce3631a
commit bb4616cd7c

View file

@ -27,14 +27,42 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
private $base; private $base;
private $relativeCommit; private $relativeCommit;
public function execxLocal($pattern /*, ... */) {
$args = func_get_args();
return $this->buildLocalFuture($args)->resolvex();
}
public function execManualLocal($pattern /*, ... */) {
$args = func_get_args();
return $this->buildLocalFuture($args)->resolve();
}
private function buildLocalFuture(array $argv) {
// Mercurial has a "defaults" feature which basically breaks automation by
// allowing the user to add random flags to any command. This feature is
// "deprecated" and "a bad idea" that you should "forget ... existed"
// according to project lead Matt Mackall:
//
// http://markmail.org/message/hl3d6eprubmkkqh5
//
// There is an HGPLAIN environmental variable which enables "plain mode"
// and hopefully disables this stuff.
$argv[0] = 'HGPLAIN=1 hg '.$argv[0];
$future = newv('ExecFuture', $argv);
$future->setCWD($this->getPath());
return $future;
}
public function getSourceControlSystemName() { public function getSourceControlSystemName() {
return 'hg'; return 'hg';
} }
public function getSourceControlBaseRevision() { public function getSourceControlBaseRevision() {
list($stdout) = execx( list($stdout) = $this->execxLocal(
'(cd %s && hg log -l 1 --template %s -r %s)', 'log -l 1 --template %s -r %s',
$this->getPath(),
'{node}\\n', '{node}\\n',
$this->getRelativeCommit()); $this->getRelativeCommit());
return rtrim($stdout, "\n"); return rtrim($stdout, "\n");
@ -46,18 +74,12 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
public function getBranchName() { public function getBranchName() {
// TODO: I have nearly no idea how hg branches work. // TODO: I have nearly no idea how hg branches work.
list($stdout) = execx( list($stdout) = $this->execxLocal('branch');
'(cd %s && hg branch)',
$this->getPath());
return trim($stdout); return trim($stdout);
} }
public function setRelativeCommit($commit) { public function setRelativeCommit($commit) {
list($err) = exec_manual( list($err) = $this->execManualLocal('id -ir %s', $commit);
'(cd %s && hg id -ir %s)',
$this->getPath(),
$commit);
if ($err) { if ($err) {
throw new ArcanistUsageException( throw new ArcanistUsageException(
"Commit '{$commit}' is not a valid Mercurial commit identifier."); "Commit '{$commit}' is not a valid Mercurial commit identifier.");
@ -69,9 +91,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
public function getRelativeCommit() { public function getRelativeCommit() {
if (empty($this->relativeCommit)) { if (empty($this->relativeCommit)) {
list($stdout) = execx( list($stdout) = $this->execxLocal(
'(cd %s && hg outgoing --branch `hg branch` --style default)', 'outgoing --branch `hg branch` --style default');
$this->getPath());
$logs = ArcanistMercurialParser::parseMercurialLog($stdout); $logs = ArcanistMercurialParser::parseMercurialLog($stdout);
if (!count($logs)) { if (!count($logs)) {
throw new ArcanistUsageException("You have no outgoing changes!"); throw new ArcanistUsageException("You have no outgoing changes!");
@ -89,9 +110,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
// explicit template consisting of just the parents token) so we need // explicit template consisting of just the parents token) so we need
// to separately execute "hg parents". // to separately execute "hg parents".
list($stdout) = execx( list($stdout) = $this->execxLocal(
'(cd %s && hg parents --style default --rev %s)', 'parents --style default --rev %s',
$this->getPath(),
$against); $against);
$parents_logs = ArcanistMercurialParser::parseMercurialLog($stdout); $parents_logs = ArcanistMercurialParser::parseMercurialLog($stdout);
@ -120,9 +140,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
} }
public function getLocalCommitInformation() { public function getLocalCommitInformation() {
list($info) = execx( list($info) = $this->execxLocal(
'(cd %s && hg log --style default --rev %s..%s --)', 'log --style default --rev %s..%s --',
$this->getPath(),
$this->getRelativeCommit(), $this->getRelativeCommit(),
$this->getWorkingCopyRevision()); $this->getWorkingCopyRevision());
$logs = ArcanistMercurialParser::parseMercurialLog($info); $logs = ArcanistMercurialParser::parseMercurialLog($info);
@ -140,9 +159,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
$cmd[] = csprintf('--rev %s', $rev); $cmd[] = csprintf('--rev %s', $rev);
} }
list($full) = execx( list($full) = $this->execxLocal(
'(cd %s && hg log --template %s %C --)', 'log --template %s %C --',
$this->getPath(),
'{node}\\n', '{node}\\n',
implode(' ', $cmd)); implode(' ', $cmd));
@ -156,9 +174,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
} }
public function getBlame($path) { public function getBlame($path) {
list($stdout) = execx( list($stdout) = $this->execxLocal(
'(cd %s && hg annotate -u -v -c --rev %s -- %s)', 'annotate -u -v -c --rev %s -- %s',
$this->getPath(),
$this->getRelativeCommit(), $this->getRelativeCommit(),
$path); $path);
@ -217,9 +234,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
$status_map[$change->getCurrentPath()] = $flags; $status_map[$change->getCurrentPath()] = $flags;
} }
list($stdout) = execx( list($stdout) = $this->execxLocal('status');
'(cd %s && hg status)',
$this->getPath());
$working_status = ArcanistMercurialParser::parseMercurialStatus($stdout); $working_status = ArcanistMercurialParser::parseMercurialStatus($stdout);
foreach ($working_status as $path => $status) { foreach ($working_status as $path => $status) {
@ -257,9 +272,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
public function getRawDiffText($path) { public function getRawDiffText($path) {
$options = $this->getDiffOptions(); $options = $this->getDiffOptions();
list($stdout) = execx( list($stdout) = $this->execxLocal(
'(cd %s && hg diff %C --rev %s --rev %s -- %s)', 'diff %C --rev %s --rev %s -- %s',
$this->getPath(),
$options, $options,
$this->getRelativeCommit(), $this->getRelativeCommit(),
$this->getWorkingCopyRevision(), $this->getWorkingCopyRevision(),
@ -271,9 +285,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
public function getFullMercurialDiff() { public function getFullMercurialDiff() {
$options = $this->getDiffOptions(); $options = $this->getDiffOptions();
list($stdout) = execx( list($stdout) = $this->execxLocal(
'(cd %s && hg diff %C --rev %s --rev %s --)', 'diff %C --rev %s --rev %s --',
$this->getPath(),
$options, $options,
$this->getRelativeCommit(), $this->getRelativeCommit(),
$this->getWorkingCopyRevision()); $this->getWorkingCopyRevision());
@ -292,9 +305,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
} }
private function getFileDataAtRevision($path, $revision) { private function getFileDataAtRevision($path, $revision) {
list($err, $stdout) = exec_manual( list($err, $stdout) = $this->execManualLocal(
'(cd %s && hg cat --rev %s -- %s)', 'cat --rev %s -- %s',
$this->getPath(),
$revision, $revision,
$path); $path);
if ($err) { if ($err) {
@ -313,9 +325,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
// Without arguments, "hg id" shows the current working directory's commit, // Without arguments, "hg id" shows the current working directory's commit,
// and "--debug" expands it to a 40-character hash. // and "--debug" expands it to a 40-character hash.
list($stdout) = execx( list($stdout) = $this->execxLocal('--debug id --id');
'(cd %s && hg --debug id --id)',
$this->getPath());
// Even with "--id", "hg id" will print a trailing "+" after the hash // Even with "--id", "hg id" will print a trailing "+" after the hash
// if the working copy is dirty (has uncommitted changes). We'll explicitly // if the working copy is dirty (has uncommitted changes). We'll explicitly
@ -353,13 +363,13 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
public function performLocalBranchMerge($branch, $message) { public function performLocalBranchMerge($branch, $message) {
if ($branch) { if ($branch) {
$err = phutil_passthru( $err = phutil_passthru(
'(cd %s && hg merge --rev %s && hg commit -m %s)', '(cd %s && HGPLAIN=1 hg merge --rev %s && hg commit -m %s)',
$this->getPath(), $this->getPath(),
$branch, $branch,
$message); $message);
} else { } else {
$err = phutil_passthru( $err = phutil_passthru(
'(cd %s && hg merge && hg commit -m %s)', '(cd %s && HGPLAIN=1 hg merge && hg commit -m %s)',
$this->getPath(), $this->getPath(),
$message); $message);
} }