]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Speedup `arc branch`
authorvrana <jakubv@fb.com>
Wed, 18 Jul 2012 23:50:49 +0000 (16:50 -0700)
committervrana <jakubv@fb.com>
Thu, 19 Jul 2012 01:01:44 +0000 (18:01 -0700)
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

src/repository/api/ArcanistGitAPI.php
src/workflow/ArcanistBranchWorkflow.php

index 48a2912fc148de0d4a27ba2e984b3e182626b69c..2945525e5f07d863d5c5efe153ef82082652d3e4 100644 (file)
@@ -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,
       );
     }
 
index 6d786805bb9999fdc00486ed9648981d69064b9c..9d6b3a6856d4731a02092ea8db72092064b63f00 100644 (file)
@@ -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;