From: vrana Date: Wed, 18 Jul 2012 23:50:49 +0000 (-0700) Subject: Speedup `arc branch` X-Git-Tag: conduit-6~197 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=cd2f8edb8368466ad7e93c9a09af2ce8a0957f65;p=arcanist.git Speedup `arc branch` Summary: This reduces time of `arc branch` from 13s to 7s in my repo which is faster than `git branch --verbose` (10s). The price for this speedup is that we loose the information [ahead 1, behind 21242] but we showed it only in branches with no revision so it's not a big deal. Test Plan: $ arc branch Reviewers: epriestley Reviewed By: epriestley CC: ahupp, aran, Korvin Differential Revision: https://secure.phabricator.com/D3005 --- diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php index 48a2912f..2945525e 100644 --- a/src/repository/api/ArcanistGitAPI.php +++ b/src/repository/api/ArcanistGitAPI.php @@ -641,7 +641,7 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { */ public function getAllBranches() { list($branch_info) = $this->execxLocal( - 'branch --verbose --abbrev=40 --no-color'); + 'branch --no-color'); $lines = explode("\n", rtrim($branch_info)); $result = array(); @@ -653,12 +653,10 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { continue; } - list($current, $name, $hash, $desc) = preg_split('/\s+/', $line, 4); + list($current, $name) = preg_split('/\s+/', $line, 2); $result[] = array( 'current' => !empty($current), 'name' => $name, - 'hash' => $hash, - 'desc' => $desc, ); } diff --git a/src/workflow/ArcanistBranchWorkflow.php b/src/workflow/ArcanistBranchWorkflow.php index 6d786805..9d6b3a68 100644 --- a/src/workflow/ArcanistBranchWorkflow.php +++ b/src/workflow/ArcanistBranchWorkflow.php @@ -83,10 +83,7 @@ EOTEXT throw new ArcanistUsageException('No branches in this working copy.'); } - $commit_map = $this->loadCommitInfo($branches, $repository_api); - foreach ($branches as $key => $branch) { - $branches[$key] += $commit_map[$branch['hash']]; - } + $branches = $this->loadCommitInfo($branches, $repository_api); $revisions = $this->loadRevisions($branches); @@ -99,33 +96,44 @@ EOTEXT array $branches, ArcanistRepositoryAPI $repository_api) { - // NOTE: "-s" is an option deep in git's diff argument parser that doesn't - // seem to have much documentation and has no long form. It suppresses any - // diff output. + $futures = array(); + foreach ($branches as $branch) { + // NOTE: "-s" is an option deep in git's diff argument parser that doesn't + // seem to have much documentation and has no long form. It suppresses any + // diff output. + $futures[$branch['name']] = $repository_api->execFutureLocal( + 'show -s --format=%C %s', + '%H%x01%ct%x01%T%x01%s%x01%b', + $branch['name']); + } - $commits = ipull($branches, 'hash'); - list($info) = $repository_api->execxLocal( - 'show -s --format=%C %Ls', - '%H%x01%ct%x01%T%x01%s%n%b%x02', - $commits); + $branches = ipull($branches, null, 'name'); $commit_map = array(); + foreach (Futures($futures) as $name => $future) { + list($info) = $future->resolvex(); + list($hash, $epoch, $tree, $desc, $text) = explode("\1", trim($info), 5); + + $branch = $branches[$name]; + $branch['hash'] = $hash; + $branch['desc'] = $desc; - $info = array_filter(explode("\2", trim($info))); - foreach ($info as $line) { - list($hash, $epoch, $tree, $text) = explode("\1", trim($line), 4); try { + $text = $desc."\n".$text; $message = ArcanistDifferentialCommitMessage::newFromRawCorpus($text); $id = $message->getRevisionID(); - $commit_map[$hash] = array( + $branch += array( 'epoch' => (int)$epoch, 'tree' => $tree, 'revisionID' => $id, ); } catch (ArcanistUsageException $ex) { - // In case of invalid commit message which fails the parsing, do noting. + // In case of invalid commit message which fails the parsing, + // do nothing. } + + $commit_map[$hash] = $branch; } return $commit_map;