public function run()
 {
     $revisions = $this->getConduit()->callMethodSynchronous('differential.query', array('authors' => array($this->getUserPHID()), 'status' => 'status-open'));
     if (!$revisions) {
         echo "You have no open Differential revisions.\n";
         return 0;
     }
     $repository_api = $this->getRepositoryAPI();
     $info = array();
     $status_len = 0;
     foreach ($revisions as $key => $revision) {
         $revision_path = Filesystem::resolvePath($revision['sourcePath']);
         $current_path = Filesystem::resolvePath($repository_api->getPath());
         if ($revision_path == $current_path) {
             $info[$key]['here'] = 1;
         } else {
             $info[$key]['here'] = 0;
         }
         $info[$key]['sort'] = sprintf('%d%04d%08d', $info[$key]['here'], $revision['status'], $revision['id']);
         $info[$key]['statusColorized'] = BranchInfo::renderColorizedRevisionStatus($revision['statusName']);
         $status_len = max($status_len, strlen($info[$key]['statusColorized']));
     }
     $info = isort($info, 'sort');
     foreach ($info as $key => $spec) {
         $revision = $revisions[$key];
         printf("%s %-" . ($status_len + 4) . "s D%d: %s\n", $spec['here'] ? phutil_console_format('**%s**', '*') : ' ', $spec['statusColorized'], $revision['id'], $revision['title']);
     }
     return 0;
 }
 public function run()
 {
     $repository_api = $this->getRepositoryAPI();
     if (!$repository_api instanceof ArcanistGitAPI) {
         throw new ArcanistUsageException("arc branch is only supported under git.");
     }
     $this->branches = BranchInfo::loadAll($repository_api);
     $all_revisions = array_unique(array_filter(mpull($this->branches, 'getRevisionId')));
     $revision_status = $this->loadDifferentialStatuses($all_revisions);
     $owner = $repository_api->getRepositoryOwner();
     foreach ($this->branches as $branch) {
         if ($branch->getCommitAuthor() != $owner) {
             $branch->setStatus('Not Yours');
             continue;
         }
         $rev_id = $branch->getRevisionID();
         if ($rev_id) {
             $status = idx($revision_status, $rev_id, 'Unknown Status');
             $branch->setStatus($status);
         } else {
             $branch->setStatus('No Revision');
         }
     }
     if (!$this->getArgument('view-all')) {
         $this->filterOutFinished();
     }
     $this->printInColumns();
 }
Example #3
0
 /**
  * Retrives all the branches from the current git repository,
  * and parses their commit messages.
  *
  * @return array a list of BranchInfo objects, one per branch.
  */
 public static function loadAll(ArcanistGitAPI $api)
 {
     $branches_raw = $api->getAllBranches();
     $branches = array();
     foreach ($branches_raw as $branch_raw) {
         $branch_info = new BranchInfo($branch_raw['name']);
         $branch_info->setSha1($branch_raw['sha1']);
         if ($branch_raw['current']) {
             $branch_info->setCurrent();
         }
         $branches[] = $branch_info;
     }
     $name_sha1_map = mpull($branches, 'getSha1', 'getName');
     $commits_list = $api->multigetCommitMessages(array_unique(array_values($name_sha1_map)), "%ct%n%an%n%s%n%b");
     foreach ($branches as $branch) {
         $sha1 = $name_sha1_map[$branch->getName()];
         $branch->setSha1($sha1);
         $branch->parseCommitMessage($commits_list[$sha1]);
     }
     $branches = msort($branches, 'getCommitTime');
     return $branches;
 }