From 3cad824e38722b4434e57fe0fe12d1dd8d86ba72 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 10 Jun 2020 08:24:35 -0700 Subject: [PATCH] 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= arc-ls-remote --output -- 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 --- src/land/engine/ArcanistLandEngine.php | 12 ++++++++++- .../engine/ArcanistMercurialLandEngine.php | 12 ++++++----- src/toolset/command/ArcanistCommand.php | 20 ++++++++++++++++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/land/engine/ArcanistLandEngine.php b/src/land/engine/ArcanistLandEngine.php index 741de7b7..31e51976 100644 --- a/src/land/engine/ArcanistLandEngine.php +++ b/src/land/engine/ArcanistLandEngine.php @@ -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(); } diff --git a/src/land/engine/ArcanistMercurialLandEngine.php b/src/land/engine/ArcanistMercurialLandEngine.php index 68dd20f7..fec60cdd 100644 --- a/src/land/engine/ArcanistMercurialLandEngine.php +++ b/src/land/engine/ArcanistMercurialLandEngine.php @@ -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( diff --git a/src/toolset/command/ArcanistCommand.php b/src/toolset/command/ArcanistCommand.php index 1c5390ef..3a7c5338 100644 --- a/src/toolset/command/ArcanistCommand.php +++ b/src/toolset/command/ArcanistCommand.php @@ -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(); - $command = $future->getCommand(); + + $display_command = $this->getDisplayCommand(); + if ($display_command !== null) { + $command = $display_command; + } else { + $command = $future->getCommand(); + } $log->writeNewline();