1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

In "arc land" in Mercurial, show a tidier "ls-remote" command

Summary:
Ref T9948. Ref T13546. We must passthru "hg ls-remote" because it might prompt the user for credentials.

Since "ls-remote" is implemented as an exension and we can't rely on using stdout beacuse of passthru, the actual command we execute is:

```
$ hg --config extensions.arc-hg=<huge long path to extension> arc-ls-remote --output <huge long path to temporary file> -- remote
```

This is meaningless and distracting; show the intent of the command we're executing instead. Users can see the raw command in "--trace" if they're actually debugging behavior.

Test Plan: Ran "arc land" in a Mercurial repository, got a tidier command output.

Maniphest Tasks: T13546, T9948

Differential Revision: https://secure.phabricator.com/D21344
This commit is contained in:
epriestley 2020-06-10 08:24:35 -07:00
parent b1f807f7ca
commit 3cad824e38
3 changed files with 37 additions and 7 deletions

View file

@ -1547,7 +1547,7 @@ abstract class ArcanistLandEngine
return $sets;
}
final protected function newPassthru($pattern /* , ... */) {
final protected function newPassthruCommand($pattern /* , ... */) {
$workflow = $this->getWorkflow();
$argv = func_get_args();
@ -1560,6 +1560,16 @@ abstract class ArcanistLandEngine
$command = $workflow->newCommand($passthru)
->setResolveOnError(true);
return $command;
}
final protected function newPassthru($pattern /* , ... */) {
$argv = func_get_args();
$command = call_user_func_array(
array($this, 'newPassthruCommand'),
$argv);
return $command->execute();
}

View file

@ -455,18 +455,20 @@ final class ArcanistMercurialLandEngine
// NOTE: We're using passthru on this because it's a remote command and
// may prompt the user for credentials.
// TODO: This is fairly silly/confusing to show to users in the common
// case where it does not require credentials, particularly because the
// actual command line is full of nonsense.
$tmpfile = new TempFile();
Filesystem::remove($tmpfile);
$err = $this->newPassthru(
$command = $this->newPassthruCommand(
'%Ls arc-ls-remote --output %s -- %s',
$api->getMercurialExtensionArguments(),
phutil_string_cast($tmpfile),
$target->getRemote());
$command->setDisplayCommand(
'hg ls-remote -- %s',
$target->getRemote());
$err = $command->execute();
if ($err) {
throw new Exception(
pht(

View file

@ -6,6 +6,7 @@ final class ArcanistCommand
private $logEngine;
private $executableFuture;
private $resolveOnError = false;
private $displayCommand;
public function setExecutableFuture(PhutilExecutableFuture $future) {
$this->executableFuture = $future;
@ -34,10 +35,27 @@ final class ArcanistCommand
return $this->resolveOnError;
}
public function setDisplayCommand($pattern /* , ... */) {
$argv = func_get_args();
$command = call_user_func_array('csprintf', $argv);
$this->displayCommand = $command;
return $this;
}
public function getDisplayCommand() {
return $this->displayCommand;
}
public function execute() {
$log = $this->getLogEngine();
$future = $this->getExecutableFuture();
$display_command = $this->getDisplayCommand();
if ($display_command !== null) {
$command = $display_command;
} else {
$command = $future->getCommand();
}
$log->writeNewline();