From eda3fc2ab44f93673f23e19bb88ef7b69cbf861c Mon Sep 17 00:00:00 2001 From: durham Date: Tue, 19 Feb 2013 13:36:02 -0800 Subject: [PATCH] Improve mercurial 'arc land' perf by avoiding updates Summary: Mercurial 'arc land --hold' was taking 90+ seconds on our large repository. Since most of arc land doesn't require any particular working directory, I've changed the mercurial logic to avoid all updates except for two: the one prior to finding the revision (only applies if the user specified --branch), and the one at the end to leave the user in a good state. Also got rid of a 'hg outgoing' call when phases are supported. Also changed the hg-subversion detection to just look for .hg/svn instead of running 'hg svn info', which was taking 4 seconds. Now arc land takes about 50 seconds. Still much worse than git's 25 seconds. One big hot spot is in the two 'hg rebase' calls, which account for 25 seconds (versus 11 seconds of git). Test Plan: Tested arc land with mercurial and git. Tested with and without the --branch options. Reviewers: epriestley, bos, sid0, dschleimer Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5014 --- src/repository/api/ArcanistMercurialAPI.php | 28 +++++++++- src/workflow/ArcanistLandWorkflow.php | 57 +++++++++++++-------- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php index 93903506..c65d48f1 100644 --- a/src/repository/api/ArcanistMercurialAPI.php +++ b/src/repository/api/ArcanistMercurialAPI.php @@ -12,6 +12,9 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { private $includeDirectoryStateInDiffs; private $rawDiffCache = array(); + private $supportsRebase; + private $supportsPhases; + protected function buildLocalFuture(array $argv) { // Mercurial has a "defaults" feature which basically breaks automation by @@ -113,8 +116,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { // Mercurial 2.1 and up have phases which indicate if something is // published or not. To find which revs are outgoing, it's much // faster to check the phase instead of actually checking the server. - list($err) = $this->execManualLocal('help phase'); - if (!$err) { + if (!$this->supportsPhases()) { list($err, $stdout) = $this->execManualLocal( 'log --branch %s -r %s --style default', $this->getBranchName(), @@ -445,6 +447,24 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { } } + public function supportsRebase() { + if ($this->supportsRebase === null) { + list ($err) = $this->execManualLocal("help rebase"); + $this->supportsRebase = $err === 0; + } + + return $this->supportsRebase; + } + + public function supportsPhases() { + if ($this->supportsPhases === null) { + list ($err) = $this->execManualLocal("help phase"); + $this->supportsPhases = $err === 0; + } + + return $this->supportsPhases; + } + public function supportsCommitRanges() { return true; } @@ -770,6 +790,10 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { } + public function isHgSubversionRepo() { + return file_exists($this->getPath('.hg/svn')); + } + public function getSubversionInfo() { $info = array(); $base_path = null; diff --git a/src/workflow/ArcanistLandWorkflow.php b/src/workflow/ArcanistLandWorkflow.php index 31492dbe..6a1e8667 100644 --- a/src/workflow/ArcanistLandWorkflow.php +++ b/src/workflow/ArcanistLandWorkflow.php @@ -189,8 +189,7 @@ EOTEXT } if ($this->isHg) { - list ($err) = $repository_api->execManualLocal('svn info'); - $this->isHgSvn = !$err; + $this->isHgSvn = $repository_api->isHgSubversionRepo(); } $branch = $this->getArgument('branch'); @@ -255,8 +254,7 @@ EOTEXT if ($this->isHg) { if ($this->useSquash) { - list ($err) = $repository_api->execManualLocal("rebase --help"); - if ($err) { + if (!$repository_api->supportsRebase()) { throw new ArcanistUsageException( "You must enable the rebase extension to use ". "the --squash strategy."); @@ -298,9 +296,11 @@ EOTEXT private function checkoutBranch() { $repository_api = $this->getRepositoryAPI(); - $repository_api->execxLocal( - 'checkout %s', - $this->branch); + if ($this->getBranchOrBookmark() != $this->branch) { + $repository_api->execxLocal( + 'checkout %s', + $this->branch); + } echo phutil_console_format( "Switched to branch **%s**. Identifying and merging...\n", @@ -378,14 +378,15 @@ EOTEXT private function pullFromRemote() { $repository_api = $this->getRepositoryAPI(); - $repository_api->execxLocal('checkout %s', $this->onto); - - echo phutil_console_format( - "Switched to branch **%s**. Updating branch...\n", - $this->onto); $local_ahead_of_remote = false; if ($this->isGit) { + $repository_api->execxLocal('checkout %s', $this->onto); + + echo phutil_console_format( + "Switched to branch **%s**. Updating branch...\n", + $this->onto); + try { $repository_api->execxLocal('pull --ff-only --no-stat'); } catch (CommandException $ex) { @@ -404,18 +405,32 @@ EOTEXT } } else if ($this->isHg) { - // execManual instead of execx because outgoing returns - // code 1 when there is nothing outgoing - list($err, $out) = $repository_api->execManualLocal( - 'outgoing -r %s', + echo phutil_console_format( + "Updating **%s**...\n", $this->onto); - // $err === 0 means something is outgoing - if ($err === 0) { - $local_ahead_of_remote = true; + if ($repository_api->supportsPhases()) { + list($out) = $repository_api->execxLocal( + 'log -r %s --template {phase}', $this->onto); + if ($out != 'public') { + $local_ahead_of_remote = true; + } } else { + // execManual instead of execx because outgoing returns + // code 1 when there is nothing outgoing + list($err, $out) = $repository_api->execManualLocal( + 'outgoing -r %s', + $this->onto); + + // $err === 0 means something is outgoing + if ($err === 0) { + $local_ahead_of_remote = true; + } + } + + if (!$local_ahead_of_remote) { try { - $repository_api->execxLocal('pull -u'); + $repository_api->execxLocal('pull'); } catch (CommandException $ex) { $err = $ex->getError(); $stdout = $ex->getStdOut(); @@ -512,9 +527,9 @@ EOTEXT private function squash() { $repository_api = $this->getRepositoryAPI(); - $repository_api->execxLocal('checkout %s', $this->onto); if ($this->isGit) { + $repository_api->execxLocal('checkout %s', $this->onto); $repository_api->execxLocal( 'merge --squash --ff-only %s', $this->branch);