Page MenuHomePhabricator

D9922.id23816.diff
No OneTemporary

D9922.id23816.diff

diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php
--- a/src/repository/api/ArcanistGitAPI.php
+++ b/src/repository/api/ArcanistGitAPI.php
@@ -21,36 +21,21 @@
return new ArcanistGitAPI($root);
}
- protected function buildLocalFuture(array $argv) {
- $argv[0] = 'git '.$argv[0];
-
- $future = newv('ExecFuture', $argv);
- $future->setCWD($this->getPath());
- return $future;
- }
-
- public function execPassthru($pattern /* , ... */) {
- $args = func_get_args();
-
- static $git = null;
- if ($git === null) {
- if (phutil_is_windows()) {
- // NOTE: On Windows, phutil_passthru() uses 'bypass_shell' because
- // everything goes to hell if we don't. We must provide an absolute
- // path to Git for this to work properly.
+ protected function getBinaryName() {
+ if (phutil_is_windows()) {
+ // NOTE: On Windows, passthru uses 'bypass_shell' because everything
+ // goes to hell if we don't. We must provide an absolute path to Git for
+ // this to work properly.
+ static $git;
+ if ($git === null) {
$git = Filesystem::resolveBinary('git');
- $git = csprintf('%s', $git);
- } else {
- $git = 'git';
}
+ return $git;
+ } else {
+ return 'git';
}
-
- $args[0] = $git.' '.$args[0];
-
- return call_user_func_array('phutil_passthru', $args);
}
-
public function getSourceControlSystemName() {
return 'git';
}
diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php
--- a/src/repository/api/ArcanistMercurialAPI.php
+++ b/src/repository/api/ArcanistMercurialAPI.php
@@ -12,7 +12,11 @@
private $supportsRebase;
private $supportsPhases;
- protected function buildLocalFuture(array $argv) {
+ protected function getBinaryName() {
+ return 'hg';
+ }
+
+ protected function getExecutionEnvironment() {
// 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"
@@ -23,26 +27,9 @@
// There is an HGPLAIN environmental variable which enables "plain mode"
// and hopefully disables this stuff.
- if (phutil_is_windows()) {
- $argv[0] = 'set HGPLAIN=1 & hg '.$argv[0];
- } else {
- $argv[0] = 'HGPLAIN=1 hg '.$argv[0];
- }
-
- $future = newv('ExecFuture', $argv);
- $future->setCWD($this->getPath());
- return $future;
- }
-
- public function execPassthru($pattern /* , ... */) {
- $args = func_get_args();
- if (phutil_is_windows()) {
- $args[0] = 'hg '.$args[0];
- } else {
- $args[0] = 'HGPLAIN=1 hg '.$args[0];
- }
-
- return call_user_func_array('phutil_passthru', $args);
+ return array(
+ 'HGPLAIN' => 1,
+ );
}
public function getSourceControlSystemName() {
diff --git a/src/repository/api/ArcanistRepositoryAPI.php b/src/repository/api/ArcanistRepositoryAPI.php
--- a/src/repository/api/ArcanistRepositoryAPI.php
+++ b/src/repository/api/ArcanistRepositoryAPI.php
@@ -404,7 +404,58 @@
return $this->buildLocalFuture($args);
}
- abstract protected function buildLocalFuture(array $argv);
+ /**
+ * Provide the name of the VCS binary, like `'git'`, `'hg'` or `'svn'`.
+ *
+ * @return string Name of the VCS binary.
+ */
+ abstract protected function getBinaryName();
+
+ /**
+ * Provide environmental variables specific to this VCS.
+ *
+ * These variables will be passed to VCS subprocesses. For example, Mercurial
+ * needs to execute with HGPLAIN.
+ *
+ * @return map<string, string> Map of environmental variables to pass to
+ * VCS subprocesses.
+ */
+ protected function getExecutionEnvironment() {
+ return array();
+ }
+
+ final protected function getCommonExecutionEnvironment() {
+ return array(
+ 'LC_ALL' => 'en_US.UTF-8',
+ );
+ }
+
+ protected function buildLocalFuture(array $argv) {
+ list($command, $env) = $this->formatVCSCommand($argv);
+
+ return id(new ExecFuture('%C', $command))
+ ->setEnv($env)
+ ->setCWD($this->getPath());
+ }
+
+ public function execPassthru($pattern /* , ... */) {
+ $argv = func_get_args();
+ list($command, $env) = $this->formatVCSCommand($argv);
+
+ return id(new PhutilExecPassthru('%C', $command))
+ ->setEnv($env)
+ ->setCWD($this->getPath());
+ }
+
+ private function formatVCSCommand(array $argv) {
+ $argv = call_user_func_array('csprintf', $argv);
+ $command = csprintf('%s %C', $this->getBinaryName(), $argv);
+
+ $env = $this->getExecutionEnvironment() +
+ $this->getCommonExecutionEnvironment();
+
+ return array($command, $env);
+ }
public function canStashChanges() {
return false;
diff --git a/src/repository/api/ArcanistSubversionAPI.php b/src/repository/api/ArcanistSubversionAPI.php
--- a/src/repository/api/ArcanistSubversionAPI.php
+++ b/src/repository/api/ArcanistSubversionAPI.php
@@ -36,13 +36,8 @@
return $svn_dir;
}
- protected function buildLocalFuture(array $argv) {
-
- $argv[0] = 'svn '.$argv[0];
-
- $future = newv('ExecFuture', $argv);
- $future->setCWD($this->getPath());
- return $future;
+ protected function getBinaryName() {
+ return 'svn';
}
protected function buildCommitRangeStatus() {

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 18, 12:00 AM (3 w, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6724033
Default Alt Text
D9922.id23816.diff (5 KB)

Event Timeline