private function getBlockers(PhabricatorRepositoryCommit $commit, HarbormasterBuildPlan $plan, HarbormasterBuild $source)
 {
     $call = new ConduitCall('diffusion.commitparentsquery', array('commit' => $commit->getCommitIdentifier(), 'repository' => $commit->getRepository()->getPHID()));
     $call->setUser(PhabricatorUser::getOmnipotentUser());
     $parents = $call->execute();
     $parents = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withRepository($commit->getRepository())->withIdentifiers($parents)->execute();
     $blockers = array();
     $build_objects = array();
     foreach ($parents as $parent) {
         if (!$parent->isImported()) {
             $blockers[] = pht('Commit %s', $parent->getCommitIdentifier());
         } else {
             $build_objects[] = $parent->getPHID();
         }
     }
     if ($build_objects) {
         $buildables = id(new HarbormasterBuildableQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBuildablePHIDs($build_objects)->withManualBuildables(false)->execute();
         $buildable_phids = mpull($buildables, 'getPHID');
         if ($buildable_phids) {
             $builds = id(new HarbormasterBuildQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBuildablePHIDs($buildable_phids)->withBuildPlanPHIDs(array($plan->getPHID()))->execute();
             foreach ($builds as $build) {
                 if (!$build->isComplete()) {
                     $blockers[] = pht('Build %d', $build->getID());
                 }
             }
         }
     }
     return $blockers;
 }
 private function checkAuditReasons(PhabricatorRepositoryCommit $commit, PhabricatorOwnersPackage $package)
 {
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     $reasons = array();
     if ($data->getCommitDetail('vsDiff')) {
         $reasons[] = pht('Changed After Revision Was Accepted');
     }
     $commit_author_phid = $data->getCommitDetail('authorPHID');
     if (!$commit_author_phid) {
         $reasons[] = pht('Commit Author Not Recognized');
     }
     $revision_id = $data->getCommitDetail('differential.revisionID');
     $revision_author_phid = null;
     $commit_reviewedby_phid = null;
     if ($revision_id) {
         $revision = id(new DifferentialRevisionQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIDs(array($revision_id))->executeOne();
         if ($revision) {
             $revision_author_phid = $revision->getAuthorPHID();
             $commit_reviewedby_phid = $data->getCommitDetail('reviewerPHID');
             if ($revision_author_phid !== $commit_author_phid) {
                 $reasons[] = pht('Author Not Matching with Revision');
             }
         } else {
             $reasons[] = pht('Revision Not Found');
         }
     } else {
         $reasons[] = pht('No Revision Specified');
     }
     $owners_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($package->getID()));
     if (!($commit_author_phid && in_array($commit_author_phid, $owners_phids) || $commit_reviewedby_phid && in_array($commit_reviewedby_phid, $owners_phids))) {
         $reasons[] = pht('Owners Not Involved');
     }
     return $reasons;
 }
 public function execute()
 {
     $table = new PhabricatorRepositoryCommit();
     $conn_r = $table->establishConnection('r');
     $join = $this->buildJoinClause($conn_r);
     $where = $this->buildWhereClause($conn_r);
     $order = $this->buildOrderClause($conn_r);
     $limit = $this->buildLimitClause($conn_r);
     $data = queryfx_all($conn_r, 'SELECT c.* FROM %T c %Q %Q %Q %Q', $table->getTableName(), $join, $where, $order, $limit);
     $commits = $table->loadAllFromArray($data);
     if ($this->needCommitData && $commits) {
         $data = id(new PhabricatorRepositoryCommitData())->loadAllWhere('commitID in (%Ld)', mpull($commits, 'getID'));
         $data = mpull($data, null, 'getCommitID');
         foreach ($commits as $commit) {
             if (idx($data, $commit->getID())) {
                 $commit->attachCommitData($data[$commit->getID()]);
             } else {
                 $commit->attachCommitData(new PhabricatorRepositoryCommitData());
             }
         }
     }
     if ($this->needAudits && $commits) {
         $audits = id(new PhabricatorAuditComment())->loadAllWhere('targetPHID in (%Ls)', mpull($commits, 'getPHID'));
         $audits = mgroup($audits, 'getTargetPHID');
         foreach ($commits as $commit) {
             $commit->attachAudits(idx($audits, $commit->getPHID(), array()));
         }
     }
     return $commits;
 }
 public static function renderLastModifiedColumns(PhabricatorRepository $repository, array $handles, PhabricatorRepositoryCommit $commit = null, PhabricatorRepositoryCommitData $data = null)
 {
     if ($commit) {
         $epoch = $commit->getEpoch();
         $modified = DiffusionView::linkCommit($repository, $commit->getCommitIdentifier());
         $date = date('M j, Y', $epoch);
         $time = date('g:i A', $epoch);
     } else {
         $modified = '';
         $date = '';
         $time = '';
     }
     if ($data) {
         $author_phid = $data->getCommitDetail('authorPHID');
         if ($author_phid && isset($handles[$author_phid])) {
             $author = $handles[$author_phid]->renderLink();
         } else {
             $author = phutil_escape_html($data->getAuthorName());
         }
         $details = AphrontTableView::renderSingleDisplayLine(phutil_escape_html($data->getSummary()));
     } else {
         $author = '';
         $details = '';
     }
     return array('commit' => $modified, 'date' => $date, 'time' => $time, 'author' => $author, 'details' => $details);
 }
Пример #5
0
 public function newBranchFromCommit(PhabricatorRepositoryCommit $cut_point, $branch_date, $symbolic_name = null)
 {
     $template = $this->releephProject->getDetail('branchTemplate');
     if (!$template) {
         $template = ReleephBranchTemplate::getRequiredDefaultTemplate();
     }
     $cut_point_handle = id(new PhabricatorHandleQuery())->setViewer($this->requireActor())->withPHIDs(array($cut_point->getPHID()))->executeOne();
     list($name, $errors) = id(new ReleephBranchTemplate())->setCommitHandle($cut_point_handle)->setBranchDate($branch_date)->setReleephProjectName($this->releephProject->getName())->interpolate($template);
     $basename = last(explode('/', $name));
     $table = id(new ReleephBranch());
     $transaction = $table->openTransaction();
     $branch = id(new ReleephBranch())->setName($name)->setBasename($basename)->setReleephProjectID($this->releephProject->getID())->setCreatedByUserPHID($this->requireActor()->getPHID())->setCutPointCommitPHID($cut_point->getPHID())->setIsActive(1)->setDetail('branchDate', $branch_date)->save();
     /**
      * Steal the symbolic name from any other branch that has it (in this
      * project).
      */
     if ($symbolic_name) {
         $others = id(new ReleephBranch())->loadAllWhere('releephProjectID = %d', $this->releephProject->getID());
         foreach ($others as $other) {
             if ($other->getSymbolicName() == $symbolic_name) {
                 $other->setSymbolicName(null)->save();
             }
         }
         $branch->setSymbolicName($symbolic_name)->save();
     }
     $table->saveTransaction();
     return $branch;
 }
 protected function parseCommitWithRef(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit, DiffusionCommitRef $ref)
 {
     $this->updateCommitData($ref);
     if ($this->shouldQueueFollowupTasks()) {
         $this->queueTask('PhabricatorRepositoryMercurialCommitChangeParserWorker', array('commitID' => $commit->getID()));
     }
 }
 protected function getCommitHashes(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     list($stdout) = $repository->execxLocalCommand('log -n 1 --format=%s %s --', '%T', $commit->getCommitIdentifier());
     $commit_hash = $commit->getCommitIdentifier();
     $tree_hash = trim($stdout);
     return array(array(ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT, $commit_hash), array(ArcanistDifferentialRevisionHash::HASH_GIT_TREE, $tree_hash));
 }
 public function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $ref = id(new DiffusionLowLevelCommitQuery())->setRepository($repository)->withIdentifier($commit->getCommitIdentifier())->execute();
     $this->updateCommitData($ref);
     if ($this->shouldQueueFollowupTasks()) {
         $this->queueTask('PhabricatorRepositorySvnCommitChangeParserWorker', array('commitID' => $commit->getID()));
     }
 }
 public function didParseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommitData $data)
 {
     $user = id(new PhabricatorUser())->loadOneWhere('phid = %s', $data->getCommitDetail('authorPHID'));
     if (!$user) {
         return;
     }
     $prefixes = array('resolves' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 'fixes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 'wontfix' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, 'wontfixes' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, 'spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, 'spites' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, 'invalidate' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, 'invaldiates' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, 'close' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 'closes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 'ref' => null, 'refs' => null, 'references' => null, 'cf.' => null);
     $suffixes = array('as resolved' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 'as fixed' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 'as wontfix' => ManiphestTaskStatus::STATUS_CLOSED_WONTFIX, 'as spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, 'out of spite' => ManiphestTaskStatus::STATUS_CLOSED_SPITE, 'as invalid' => ManiphestTaskStatus::STATUS_CLOSED_INVALID, '' => null);
     $prefix_regex = array();
     foreach ($prefixes as $prefix => $resolution) {
         $prefix_regex[] = preg_quote($prefix, '/');
     }
     $prefix_regex = implode('|', $prefix_regex);
     $suffix_regex = array();
     foreach ($suffixes as $suffix => $resolution) {
         $suffix_regex[] = preg_quote($suffix, '/');
     }
     $suffix_regex = implode('|', $suffix_regex);
     $matches = null;
     $ok = preg_match_all("/({$prefix_regex})\\s+T(\\d+)\\s*({$suffix_regex})/i", $this->renderValueForCommitMessage($is_edit = false), $matches, PREG_SET_ORDER);
     if (!$ok) {
         return;
     }
     foreach ($matches as $set) {
         $prefix = strtolower($set[1]);
         $task_id = (int) $set[2];
         $suffix = strtolower($set[3]);
         $status = idx($suffixes, $suffix);
         if (!$status) {
             $status = idx($prefixes, $prefix);
         }
         $tasks = id(new ManiphestTaskQuery())->withTaskIDs(array($task_id))->execute();
         $task = idx($tasks, $task_id);
         if (!$task) {
             // Task doesn't exist, or the user can't see it.
             continue;
         }
         id(new PhabricatorEdgeEditor())->setUser($user)->addEdge($task->getPHID(), PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT, $commit->getPHID())->save();
         if (!$status) {
             // Text like "Ref T123", don't change the task status.
             continue;
         }
         if ($task->getStatus() != ManiphestTaskStatus::STATUS_OPEN) {
             // Task is already closed.
             continue;
         }
         $commit_name = $repository->formatCommitName($commit->getCommitIdentifier());
         $call = new ConduitCall('maniphest.update', array('id' => $task->getID(), 'status' => $status, 'comments' => "Closed by commit {$commit_name}."));
         $call->setUser($user);
         $call->execute();
     }
 }
 private function renderColumns(DiffusionRequest $drequest, array $handles, PhabricatorRepositoryCommit $commit = null, $lint = null)
 {
     assert_instances_of($handles, 'PhabricatorObjectHandle');
     $viewer = $this->getRequest()->getUser();
     if ($commit) {
         $epoch = $commit->getEpoch();
         $modified = DiffusionView::linkCommit($drequest->getRepository(), $commit->getCommitIdentifier());
         $date = phabricator_date($epoch, $viewer);
         $time = phabricator_time($epoch, $viewer);
     } else {
         $modified = '';
         $date = '';
         $time = '';
     }
     $data = $commit->getCommitData();
     if ($data) {
         $author_phid = $data->getCommitDetail('authorPHID');
         if ($author_phid && isset($handles[$author_phid])) {
             $author = $handles[$author_phid]->renderLink();
         } else {
             $author = DiffusionView::renderName($data->getAuthorName());
         }
         $committer = $data->getCommitDetail('committer');
         if ($committer) {
             $committer_phid = $data->getCommitDetail('committerPHID');
             if ($committer_phid && isset($handles[$committer_phid])) {
                 $committer = $handles[$committer_phid]->renderLink();
             } else {
                 $committer = DiffusionView::renderName($committer);
             }
             if ($author != $committer) {
                 $author = hsprintf('%s/%s', $author, $committer);
             }
         }
         $details = AphrontTableView::renderSingleDisplayLine($data->getSummary());
     } else {
         $author = '';
         $details = '';
     }
     $return = array('commit' => $modified, 'date' => $date, 'time' => $time, 'author' => $author, 'details' => $details);
     if ($lint !== null) {
         $return['lint'] = phutil_tag('a', array('href' => $drequest->generateURI(array('action' => 'lint', 'lint' => null))), number_format($lint));
     }
     // The client treats these results as markup, so make sure they have been
     // escaped correctly.
     foreach ($return as $key => $value) {
         $return[$key] = hsprintf('%s', $value);
     }
     return $return;
 }
 public static function loadAffectedPaths(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit, PhabricatorUser $user)
 {
     $drequest = DiffusionRequest::newFromDictionary(array('user' => $user, 'repository' => $repository, 'commit' => $commit->getCommitIdentifier()));
     $path_query = DiffusionPathChangeQuery::newFromDiffusionRequest($drequest);
     $paths = $path_query->loadChanges();
     $result = array();
     foreach ($paths as $path) {
         $basic_path = '/' . $path->getPath();
         if ($path->getFileType() == DifferentialChangeType::FILE_DIRECTORY) {
             $basic_path = rtrim($basic_path, '/') . '/';
         }
         $result[] = $basic_path;
     }
     return $result;
 }
 public function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $uri = $repository->getDetail('remote-uri');
     $log = $this->getSVNLogXMLObject($uri, $commit->getCommitIdentifier(), $verbose = false);
     $entry = $log->logentry[0];
     $author = (string) $entry->author;
     $message = (string) $entry->msg;
     $this->updateCommitData($author, $message);
     if ($this->shouldQueueFollowupTasks()) {
         $task = new PhabricatorWorkerTask();
         $task->setTaskClass('PhabricatorRepositorySvnCommitChangeParserWorker');
         $task->setData(array('commitID' => $commit->getID()));
         $task->save();
     }
 }
 public static function indexCommit(PhabricatorRepositoryCommit $commit)
 {
     $commit_data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     $date_created = $commit->getEpoch();
     $commit_message = $commit_data->getCommitMessage();
     $author_phid = $commit_data->getCommitDetail('authorPHID');
     $repository = id(new PhabricatorRepository())->loadOneWhere('id = %d', $commit->getRepositoryID());
     if (!$repository) {
         return;
     }
     $title = 'r' . $repository->getCallsign() . $commit->getCommitIdentifier() . " " . $commit_data->getSummary();
     $doc = new PhabricatorSearchAbstractDocument();
     $doc->setPHID($commit->getPHID());
     $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_CMIT);
     $doc->setDocumentCreated($date_created);
     $doc->setDocumentModified($date_created);
     $doc->setDocumentTitle($title);
     $doc->addField(PhabricatorSearchField::FIELD_BODY, $commit_message);
     if ($author_phid) {
         $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $author_phid, PhabricatorPHIDConstants::PHID_TYPE_USER, $date_created);
     }
     $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, $repository->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_REPO, $date_created);
     $comments = id(new PhabricatorAuditComment())->loadAllWhere('targetPHID = %s', $commit->getPHID());
     foreach ($comments as $comment) {
         if (strlen($comment->getContent())) {
             $doc->addField(PhabricatorSearchField::FIELD_COMMENT, $comment->getContent());
         }
     }
     self::reindexAbstractDocument($doc);
 }
 protected function recordCommit($commit_identifier, $epoch)
 {
     $repository = $this->getRepository();
     $commit = new PhabricatorRepositoryCommit();
     $commit->setRepositoryID($repository->getID());
     $commit->setCommitIdentifier($commit_identifier);
     $commit->setEpoch($epoch);
     try {
         $commit->save();
         $event = new PhabricatorTimelineEvent('cmit', array('id' => $commit->getID()));
         $event->recordEvent();
         queryfx($repository->establishConnection('w'), 'INSERT INTO %T (repositoryID, size, lastCommitID, epoch)
       VALUES (%d, 1, %d, %d)
       ON DUPLICATE KEY UPDATE
         size = size + 1,
         lastCommitID =
           IF(VALUES(epoch) > epoch, VALUES(lastCommitID), lastCommitID),
         epoch = IF(VALUES(epoch) > epoch, VALUES(epoch), epoch)', PhabricatorRepository::TABLE_SUMMARY, $repository->getID(), $commit->getID(), $epoch);
         $this->commitCache[$commit_identifier] = true;
     } catch (AphrontQueryDuplicateKeyException $ex) {
         // Ignore. This can happen because we discover the same new commit
         // more than once when looking at history, or because of races or
         // data inconsistency or cosmic radiation; in any case, we're still
         // in a good state if we ignore the failure.
         $this->commitCache[$commit_identifier] = true;
     }
     $this->stillWorking();
 }
 public function setCommit(PhabricatorRepositoryCommit $commit)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withIDs(array($commit->getRepositoryID()))->needProjectPHIDs(true)->executeOne();
     if (!$repository) {
         throw new Exception(pht('Unable to load repository!'));
     }
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     if (!$data) {
         throw new Exception(pht('Unable to load commit data!'));
     }
     $this->commit = clone $commit;
     $this->commit->attachRepository($repository);
     $this->commit->attachCommitData($data);
     $this->repository = $repository;
     $this->commitData = $data;
     return $this;
 }
 public function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $local_path = $repository->getDetail('local-path');
     // NOTE: %B was introduced somewhat recently in git's history, so pull
     // commit message information with %s and %b instead.
     list($info) = execx('(cd %s && git log -n 1 --pretty=format:%%an%%x00%%s%%n%%n%%b %s)', $local_path, $commit->getCommitIdentifier());
     list($author, $message) = explode("", $info);
     // Make sure these are valid UTF-8.
     $author = phutil_utf8ize($author);
     $message = phutil_utf8ize($message);
     $message = trim($message);
     $this->updateCommitData($author, $message);
     if ($this->shouldQueueFollowupTasks()) {
         $task = new PhabricatorWorkerTask();
         $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker');
         $task->setData(array('commitID' => $commit->getID()));
         $task->save();
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $repos = $this->loadRepositories($args, 'repos');
     if (!$repos) {
         throw new PhutilArgumentUsageException(pht('Specify one or more repositories to find importing commits for.'));
     }
     $repos = mpull($repos, null, 'getID');
     $table = new PhabricatorRepositoryCommit();
     $conn_r = $table->establishConnection('r');
     $rows = queryfx_all($conn_r, 'SELECT repositoryID, commitIdentifier, importStatus FROM %T
     WHERE repositoryID IN (%Ld)
       AND (importStatus & %d) != %d
       AND (importStatus & %d) != %d', $table->getTableName(), array_keys($repos), PhabricatorRepositoryCommit::IMPORTED_ALL, PhabricatorRepositoryCommit::IMPORTED_ALL, PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE, PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE);
     $console = PhutilConsole::getConsole();
     if ($rows) {
         foreach ($rows as $row) {
             $repo = $repos[$row['repositoryID']];
             $identifier = $row['commitIdentifier'];
             $console->writeOut('%s', $repo->formatCommitName($identifier));
             if (!$args->getArg('simple')) {
                 $status = $row['importStatus'];
                 $need = array();
                 if (!($status & PhabricatorRepositoryCommit::IMPORTED_MESSAGE)) {
                     $need[] = pht('Message');
                 }
                 if (!($status & PhabricatorRepositoryCommit::IMPORTED_CHANGE)) {
                     $need[] = pht('Change');
                 }
                 if (!($status & PhabricatorRepositoryCommit::IMPORTED_OWNERS)) {
                     $need[] = pht('Owners');
                 }
                 if (!($status & PhabricatorRepositoryCommit::IMPORTED_HERALD)) {
                     $need[] = pht('Herald');
                 }
                 $console->writeOut(' %s', implode(', ', $need));
             }
             $console->writeOut("\n");
         }
     } else {
         $console->writeErr("%s\n", pht('No importing commits found.'));
     }
     return 0;
 }
Пример #18
0
 protected final function loadCommitsByIdentifiers(array $identifiers)
 {
     if (!$identifiers) {
         return array();
     }
     $commits = array();
     $commit_data = array();
     $drequest = $this->getRequest();
     $repository = $drequest->getRepository();
     $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere('repositoryID = %d AND commitIdentifier IN (%Ls)', $repository->getID(), $identifiers);
     $commits = mpull($commits, null, 'getCommitIdentifier');
     // Build empty commit objects for every commit, so we can show unparsed
     // commits in history views as "unparsed" instead of not showing them. This
     // makes the process of importing and parsing commits much clearer to the
     // user.
     $commit_list = array();
     foreach ($identifiers as $identifier) {
         $commit_obj = idx($commits, $identifier);
         if (!$commit_obj) {
             $commit_obj = new PhabricatorRepositoryCommit();
             $commit_obj->setRepositoryID($repository->getID());
             $commit_obj->setCommitIdentifier($identifier);
             $commit_obj->setIsUnparsed(true);
             $commit_obj->makeEphemeral();
         }
         $commit_list[$identifier] = $commit_obj;
     }
     $commits = $commit_list;
     $commit_ids = array_filter(mpull($commits, 'getID'));
     if ($commit_ids) {
         $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere('commitID in (%Ld)', $commit_ids);
         $commit_data = mpull($commit_data, null, 'getCommitID');
     }
     foreach ($commits as $commit) {
         if (!$commit->getID()) {
             continue;
         }
         if (idx($commit_data, $commit->getID())) {
             $commit->attachCommitData($commit_data[$commit->getID()]);
         }
     }
     return $commits;
 }
 private function checkAuditReasons(PhabricatorRepositoryCommit $commit, PhabricatorOwnersPackage $package)
 {
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     $reasons = array();
     if ($data->getCommitDetail('vsDiff')) {
         $reasons[] = "Changed After Revision Was Accepted";
     }
     $commit_author_phid = $data->getCommitDetail('authorPHID');
     if (!$commit_author_phid) {
         $reasons[] = "Commit Author Not Recognized";
     }
     $revision_id = $data->getCommitDetail('differential.revisionID');
     $revision_author_phid = null;
     $commit_reviewedby_phid = null;
     $commit_author_phid = null;
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if ($revision) {
             $revision->loadRelationships();
             $revision_author_phid = $revision->getAuthorPHID();
             $revision_reviewedby_phid = $revision->loadReviewedBy();
             $commit_reviewedby_phid = $data->getCommitDetail('reviewerPHID');
             $commit_author_phid = $data->getCommitDetail('authorPHID');
             if ($revision_author_phid !== $commit_author_phid) {
                 $reasons[] = "Author Not Matching with Revision";
             }
             if ($revision_reviewedby_phid !== $commit_reviewedby_phid) {
                 $reasons[] = "ReviewedBy Not Matching with Revision";
             }
         } else {
             $reasons[] = "Revision Not Found";
         }
     } else {
         $reasons[] = "No Revision Specified";
     }
     $owners_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($package->getID()));
     if (!($commit_author_phid && in_array($commit_author_phid, $owners_phids) || $commit_reviewedby_phid && in_array($commit_reviewedby_phid, $owners_phids))) {
         $reasons[] = "Owners Not Involved";
     }
     return $reasons;
 }
 private function loadRawPatchText(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $drequest = DiffusionRequest::newFromDictionary(array('user' => PhabricatorUser::getOmnipotentUser(), 'repository' => $repository, 'commit' => $commit->getCommitIdentifier()));
     $raw_query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest);
     $raw_query->setLinesOfContext(3);
     $time_key = 'metamta.diffusion.time-limit';
     $byte_key = 'metamta.diffusion.byte-limit';
     $time_limit = PhabricatorEnv::getEnvConfig($time_key);
     $byte_limit = PhabricatorEnv::getEnvConfig($byte_key);
     if ($time_limit) {
         $raw_query->setTimeout($time_limit);
     }
     $raw_diff = $raw_query->loadRawDiff();
     $size = strlen($raw_diff);
     if ($byte_limit && $size > $byte_limit) {
         $pretty_size = phutil_format_bytes($size);
         $pretty_limit = phutil_format_bytes($byte_limit);
         throw new Exception(pht('Patch size of %s exceeds configured byte size limit (%s) of %s.', $pretty_size, $byte_key, $pretty_limit));
     }
     return $raw_diff;
 }
 private function writeCommitChanges(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit, array $changes)
 {
     $repository_id = (int) $repository->getID();
     $commit_id = (int) $commit->getID();
     // NOTE: This SQL is being built manually instead of with qsprintf()
     // because some SVN changes affect an enormous number of paths (millions)
     // and this showed up as significantly slow on a profile at some point.
     $changes_sql = array();
     foreach ($changes as $change) {
         $values = array($repository_id, (int) $change->getPathID(), $commit_id, nonempty((int) $change->getTargetPathID(), 'null'), nonempty((int) $change->getTargetCommitID(), 'null'), (int) $change->getChangeType(), (int) $change->getFileType(), (int) $change->getIsDirect(), (int) $change->getCommitSequence());
         $changes_sql[] = '(' . implode(', ', $values) . ')';
     }
     $conn_w = $repository->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE commitID = %d', PhabricatorRepository::TABLE_PATHCHANGE, $commit_id);
     foreach (PhabricatorLiskDAO::chunkSQL($changes_sql) as $chunk) {
         queryfx($conn_w, 'INSERT INTO %T
       (repositoryID, pathID, commitID, targetPathID, targetCommitID,
         changeType, fileType, isDirect, commitSequence)
       VALUES %Q', PhabricatorRepository::TABLE_PATHCHANGE, $chunk);
     }
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $query = $request->getStr('q');
     $repo_id = $request->getInt('repo');
     $since = $request->getInt('since');
     $limit = $request->getInt('limit');
     $now = time();
     $data = array();
     // Dummy instances used for getting connections, table names, etc.
     $pr_commit = new PhabricatorRepositoryCommit();
     $pr_commit_data = new PhabricatorRepositoryCommitData();
     $conn = $pr_commit->establishConnection('r');
     $rows = queryfx_all($conn, 'SELECT
     rc.phid as commitPHID,
     rc.authorPHID,
     rcd.authorName,
     SUBSTRING(rcd.commitMessage, 1, 100) AS shortMessage,
     rc.commitIdentifier,
     rc.epoch
     FROM %T rc
     INNER JOIN %T rcd ON rcd.commitID = rc.id
     WHERE repositoryID = %d
     AND rc.epoch >= %d
     AND (
       rcd.commitMessage LIKE %~
       OR
       rc.commitIdentifier LIKE %~
     )
     ORDER BY rc.epoch DESC
     LIMIT %d', $pr_commit->getTableName(), $pr_commit_data->getTableName(), $repo_id, $since, $query, $query, $limit);
     foreach ($rows as $row) {
         $full_commit_id = $row['commitIdentifier'];
         $short_commit_id = substr($full_commit_id, 0, 12);
         $first_line = $this->getFirstLine($row['shortMessage']);
         $data[] = array($full_commit_id, $short_commit_id, $row['authorName'], phutil_format_relative_time($now - $row['epoch']), $first_line);
     }
     return id(new AphrontAjaxResponse())->setContent($data);
 }
 private function checkAuditReasons(PhabricatorRepositoryCommit $commit, PhabricatorOwnersPackage $package)
 {
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     $reasons = array();
     if ($data->getCommitDetail('vsDiff')) {
         $reasons[] = 'Changed After Revision Was Accepted';
     }
     $commit_author_phid = $data->getCommitDetail('authorPHID');
     if (!$commit_author_phid) {
         $reasons[] = 'Commit Author Not Recognized';
     }
     $revision_id = $data->getCommitDetail('differential.revisionID');
     $revision_author_phid = null;
     $commit_reviewedby_phid = null;
     if ($revision_id) {
         // TODO: (T603) This is probably safe to use an omnipotent user on,
         // but check things more closely.
         $revision = id(new DifferentialRevision())->load($revision_id);
         if ($revision) {
             $revision_author_phid = $revision->getAuthorPHID();
             $commit_reviewedby_phid = $data->getCommitDetail('reviewerPHID');
             if ($revision_author_phid !== $commit_author_phid) {
                 $reasons[] = 'Author Not Matching with Revision';
             }
         } else {
             $reasons[] = 'Revision Not Found';
         }
     } else {
         $reasons[] = 'No Revision Specified';
     }
     $owners_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($package->getID()));
     if (!($commit_author_phid && in_array($commit_author_phid, $owners_phids) || $commit_reviewedby_phid && in_array($commit_reviewedby_phid, $owners_phids))) {
         $reasons[] = 'Owners Not Involved';
     }
     return $reasons;
 }
 /**
  * Determine why autoclose should be skipped for a commit.
  *
  * This method gives a detailed reason why autoclose will be skipped. To
  * perform a simple test, use @{method:shouldAutocloseCommit}.
  *
  * @param PhabricatorRepositoryCommit Commit to check.
  * @return const|null Constant identifying reason to skip this commit, or null
  *   if autoclose is active.
  * @task autoclose
  */
 public function shouldSkipAutocloseCommit(PhabricatorRepositoryCommit $commit)
 {
     $all_reason = $this->shouldSkipAllAutoclose();
     if ($all_reason) {
         return $all_reason;
     }
     switch ($this->getVersionControlSystem()) {
         case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
         case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
             return null;
         case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
             break;
         default:
             throw new Exception(pht('Unrecognized version control system.'));
     }
     $closeable_flag = PhabricatorRepositoryCommit::IMPORTED_CLOSEABLE;
     if (!$commit->isPartiallyImported($closeable_flag)) {
         return self::BECAUSE_NOT_ON_AUTOCLOSE_BRANCH;
     }
     return null;
 }
Пример #25
0
#!/usr/bin/env php
<?php 
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
$commit = new PhabricatorRepositoryCommit();
$conn_w = id(new PhabricatorRepository())->establishConnection('w');
$sizes = queryfx_all($conn_w, 'SELECT repositoryID, count(*) N FROM %T GROUP BY repositoryID', $commit->getTableName());
$sizes = ipull($sizes, 'N', 'repositoryID');
$maxes = queryfx_all($conn_w, 'SELECT repositoryID, max(epoch) maxEpoch FROM %T GROUP BY repositoryID', $commit->getTableName());
$maxes = ipull($maxes, 'maxEpoch', 'repositoryID');
$repository_ids = array_keys($sizes + $maxes);
echo pht('Updating %d repositories', count($repository_ids));
foreach ($repository_ids as $repository_id) {
    $last_commit = queryfx_one($conn_w, 'SELECT id FROM %T WHERE repositoryID = %d AND epoch = %d LIMIT 1', $commit->getTableName(), $repository_id, idx($maxes, $repository_id, 0));
    if ($last_commit) {
        $last_commit = $last_commit['id'];
    } else {
        $last_commit = 0;
    }
    queryfx($conn_w, 'INSERT INTO %T (repositoryID, lastCommitID, size, epoch)
      VALUES (%d, %d, %d, %d) ON DUPLICATE KEY UPDATE
        lastCommitID = VALUES(lastCommitID),
        size = VALUES(size),
        epoch = VALUES(epoch)', PhabricatorRepository::TABLE_SUMMARY, $repository_id, $last_commit, idx($sizes, $repository_id, 0), idx($maxes, $repository_id, 0));
    echo '.';
}
echo "\n" . pht('Done.') . "\n";
 protected function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $full_name = 'r' . $repository->getCallsign() . $commit->getCommitIdentifier();
     echo "Parsing {$full_name}...\n";
     if ($this->isBadCommit($full_name)) {
         echo "This commit is marked bad!\n";
         return;
     }
     // Check if the commit has parents. We're testing to see whether it is the
     // first commit in history (in which case we must use "git log") or some
     // other commit (in which case we can use "git diff"). We'd rather use
     // "git diff" because it has the right behavior for merge commits, but
     // it requires the commit to have a parent that we can diff against. The
     // first commit doesn't, so "commit^" is not a valid ref.
     list($parents) = $repository->execxLocalCommand('log -n1 --format=%s %s', '%P', $commit->getCommitIdentifier());
     $use_log = !strlen(trim($parents));
     if ($use_log) {
         // This is the first commit so we need to use "log". We know it's not a
         // merge commit because it couldn't be merging anything, so this is safe.
         // NOTE: "--pretty=format: " is to disable diff output, we only want the
         // part we get from "--raw".
         list($raw) = $repository->execxLocalCommand('log -n1 -M -C -B --find-copies-harder --raw -t ' . '--pretty=format: --abbrev=40 %s', $commit->getCommitIdentifier());
     } else {
         // Otherwise, we can use "diff", which will give us output for merges.
         // We diff against the first parent, as this is generally the expectation
         // and results in sensible behavior.
         list($raw) = $repository->execxLocalCommand('diff -n1 -M -C -B --find-copies-harder --raw -t ' . '--abbrev=40 %s^1 %s', $commit->getCommitIdentifier(), $commit->getCommitIdentifier());
     }
     $changes = array();
     $move_away = array();
     $copy_away = array();
     $lines = explode("\n", $raw);
     foreach ($lines as $line) {
         if (!strlen(trim($line))) {
             continue;
         }
         list($old_mode, $new_mode, $old_hash, $new_hash, $more_stuff) = preg_split('/ +/', $line, 5);
         // We may only have two pieces here.
         list($action, $src_path, $dst_path) = array_merge(explode("\t", $more_stuff), array(null));
         // Normalize the paths for consistency with the SVN workflow.
         $src_path = '/' . $src_path;
         if ($dst_path) {
             $dst_path = '/' . $dst_path;
         }
         $old_mode = intval($old_mode, 8);
         $new_mode = intval($new_mode, 8);
         switch ($new_mode & 0160000) {
             case 0160000:
                 $file_type = DifferentialChangeType::FILE_SUBMODULE;
                 break;
             case 0120000:
                 $file_type = DifferentialChangeType::FILE_SYMLINK;
                 break;
             case 040000:
                 $file_type = DifferentialChangeType::FILE_DIRECTORY;
                 break;
             default:
                 $file_type = DifferentialChangeType::FILE_NORMAL;
                 break;
         }
         // TODO: We can detect binary changes as git does, through a combination
         // of running 'git check-attr' for stuff like 'binary', 'merge' or 'diff',
         // and by falling back to inspecting the first 8,000 characters of the
         // buffer for null bytes (this is seriously git's algorithm, see
         // buffer_is_binary() in xdiff-interface.c).
         $change_type = null;
         $change_path = $src_path;
         $change_target = null;
         $is_direct = true;
         switch ($action[0]) {
             case 'A':
                 $change_type = DifferentialChangeType::TYPE_ADD;
                 break;
             case 'D':
                 $change_type = DifferentialChangeType::TYPE_DELETE;
                 break;
             case 'C':
                 $change_type = DifferentialChangeType::TYPE_COPY_HERE;
                 $change_path = $dst_path;
                 $change_target = $src_path;
                 $copy_away[$change_target][] = $change_path;
                 break;
             case 'R':
                 $change_type = DifferentialChangeType::TYPE_MOVE_HERE;
                 $change_path = $dst_path;
                 $change_target = $src_path;
                 $move_away[$change_target][] = $change_path;
                 break;
             case 'T':
                 // Type of the file changed, fall through and treat it as a
                 // modification. Not 100% sure this is the right thing to do but it
                 // seems reasonable.
             // Type of the file changed, fall through and treat it as a
             // modification. Not 100% sure this is the right thing to do but it
             // seems reasonable.
             case 'M':
                 if ($file_type == DifferentialChangeType::FILE_DIRECTORY) {
                     $change_type = DifferentialChangeType::TYPE_CHILD;
                     $is_direct = false;
                 } else {
                     $change_type = DifferentialChangeType::TYPE_CHANGE;
                 }
                 break;
                 // NOTE: "U" (unmerged) and "X" (unknown) statuses are also possible
                 // in theory but shouldn't appear here.
             // NOTE: "U" (unmerged) and "X" (unknown) statuses are also possible
             // in theory but shouldn't appear here.
             default:
                 throw new Exception("Failed to parse line '{$line}'.");
         }
         $changes[$change_path] = array('repositoryID' => $repository->getID(), 'commitID' => $commit->getID(), 'path' => $change_path, 'changeType' => $change_type, 'fileType' => $file_type, 'isDirect' => $is_direct, 'commitSequence' => $commit->getEpoch(), 'targetPath' => $change_target, 'targetCommitID' => $change_target ? $commit->getID() : null);
     }
     // Add a change to '/' since git doesn't mention it.
     $changes['/'] = array('repositoryID' => $repository->getID(), 'commitID' => $commit->getID(), 'path' => '/', 'changeType' => DifferentialChangeType::TYPE_CHILD, 'fileType' => DifferentialChangeType::FILE_DIRECTORY, 'isDirect' => false, 'commitSequence' => $commit->getEpoch(), 'targetPath' => null, 'targetCommitID' => null);
     foreach ($copy_away as $change_path => $destinations) {
         if (isset($move_away[$change_path])) {
             $change_type = DifferentialChangeType::TYPE_MULTICOPY;
             $is_direct = true;
             unset($move_away[$change_path]);
         } else {
             $change_type = DifferentialChangeType::TYPE_COPY_AWAY;
             $is_direct = false;
         }
         $reference = $changes[reset($destinations)];
         $changes[$change_path] = array('repositoryID' => $repository->getID(), 'commitID' => $commit->getID(), 'path' => $change_path, 'changeType' => $change_type, 'fileType' => $reference['fileType'], 'isDirect' => $is_direct, 'commitSequence' => $commit->getEpoch(), 'targetPath' => null, 'targetCommitID' => null);
     }
     foreach ($move_away as $change_path => $destinations) {
         $reference = $changes[reset($destinations)];
         $changes[$change_path] = array('repositoryID' => $repository->getID(), 'commitID' => $commit->getID(), 'path' => $change_path, 'changeType' => DifferentialChangeType::TYPE_MOVE_AWAY, 'fileType' => $reference['fileType'], 'isDirect' => true, 'commitSequence' => $commit->getEpoch(), 'targetPath' => null, 'targetCommitID' => null);
     }
     $paths = array();
     foreach ($changes as $change) {
         $paths[$change['path']] = true;
         if ($change['targetPath']) {
             $paths[$change['targetPath']] = true;
         }
     }
     $path_map = $this->lookupOrCreatePaths(array_keys($paths));
     foreach ($changes as $key => $change) {
         $changes[$key]['pathID'] = $path_map[$change['path']];
         if ($change['targetPath']) {
             $changes[$key]['targetPathID'] = $path_map[$change['targetPath']];
         } else {
             $changes[$key]['targetPathID'] = null;
         }
     }
     $conn_w = $repository->establishConnection('w');
     $changes_sql = array();
     foreach ($changes as $change) {
         $values = array((int) $change['repositoryID'], (int) $change['pathID'], (int) $change['commitID'], $change['targetPathID'] ? (int) $change['targetPathID'] : 'null', $change['targetCommitID'] ? (int) $change['targetCommitID'] : 'null', (int) $change['changeType'], (int) $change['fileType'], (int) $change['isDirect'], (int) $change['commitSequence']);
         $changes_sql[] = '(' . implode(', ', $values) . ')';
     }
     queryfx($conn_w, 'DELETE FROM %T WHERE commitID = %d', PhabricatorRepository::TABLE_PATHCHANGE, $commit->getID());
     foreach (array_chunk($changes_sql, 256) as $sql_chunk) {
         queryfx($conn_w, 'INSERT INTO %T
       (repositoryID, pathID, commitID, targetPathID, targetCommitID,
         changeType, fileType, isDirect, commitSequence)
       VALUES %Q', PhabricatorRepository::TABLE_PATHCHANGE, implode(', ', $sql_chunk));
     }
     $this->finishParse();
 }
Пример #27
0
<?php

echo pht('Migrating %s to edges...', 'differential.revisionPHID') . "\n";
$commit_table = new PhabricatorRepositoryCommit();
$data_table = new PhabricatorRepositoryCommitData();
$editor = new PhabricatorEdgeEditor();
$commit_table->establishConnection('w');
$edges = 0;
foreach (new LiskMigrationIterator($commit_table) as $commit) {
    $data = $commit->loadOneRelative($data_table, 'commitID');
    if (!$data) {
        continue;
    }
    $revision_phid = $data->getCommitDetail('differential.revisionPHID');
    if (!$revision_phid) {
        continue;
    }
    $commit_drev = DiffusionCommitHasRevisionEdgeType::EDGECONST;
    $editor->addEdge($commit->getPHID(), $commit_drev, $revision_phid);
    $edges++;
    if ($edges % 256 == 0) {
        echo '.';
        $editor->save();
        $editor = new PhabricatorEdgeEditor();
    }
}
echo '.';
$editor->save();
echo "\n" . pht('Done.') . "\n";
 /**
  * Return a map of available audit actions for rendering into a <select />.
  * This shows the user valid actions, and does not show nonsense/invalid
  * actions (like closing an already-closed commit, or resigning from a commit
  * you have no association with).
  */
 private function getAuditActions(PhabricatorRepositoryCommit $commit, array $audit_requests)
 {
     assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
     $user = $this->getRequest()->getUser();
     $user_is_author = $commit->getAuthorPHID() == $user->getPHID();
     $user_request = null;
     foreach ($audit_requests as $audit_request) {
         if ($audit_request->getAuditorPHID() == $user->getPHID()) {
             $user_request = $audit_request;
             break;
         }
     }
     $actions = array();
     $actions[PhabricatorAuditActionConstants::COMMENT] = true;
     $actions[PhabricatorAuditActionConstants::ADD_CCS] = true;
     $actions[PhabricatorAuditActionConstants::ADD_AUDITORS] = true;
     // We allow you to accept your own commits. A use case here is that you
     // notice an issue with your own commit and "Raise Concern" as an indicator
     // to other auditors that you're on top of the issue, then later resolve it
     // and "Accept". You can not accept on behalf of projects or packages,
     // however.
     $actions[PhabricatorAuditActionConstants::ACCEPT] = true;
     $actions[PhabricatorAuditActionConstants::CONCERN] = true;
     // To resign, a user must have authority on some request and not be the
     // commit's author.
     if (!$user_is_author) {
         $may_resign = false;
         $authority_map = array_fill_keys($this->auditAuthorityPHIDs, true);
         foreach ($audit_requests as $request) {
             if (empty($authority_map[$request->getAuditorPHID()])) {
                 continue;
             }
             $may_resign = true;
             break;
         }
         // If the user has already resigned, don't show "Resign...".
         $status_resigned = PhabricatorAuditStatusConstants::RESIGNED;
         if ($user_request) {
             if ($user_request->getAuditStatus() == $status_resigned) {
                 $may_resign = false;
             }
         }
         if ($may_resign) {
             $actions[PhabricatorAuditActionConstants::RESIGN] = true;
         }
     }
     $status_concern = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED;
     $concern_raised = $commit->getAuditStatus() == $status_concern;
     $can_close_option = PhabricatorEnv::getEnvConfig('audit.can-author-close-audit');
     if ($can_close_option && $user_is_author && $concern_raised) {
         $actions[PhabricatorAuditActionConstants::CLOSE] = true;
     }
     foreach ($actions as $constant => $ignored) {
         $actions[$constant] = PhabricatorAuditActionConstants::getActionName($constant);
     }
     return $actions;
 }
 public static function getMailThreading(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     return array('diffusion-audit-' . $commit->getPHID(), 'Commit r' . $repository->getCallsign() . $commit->getCommitIdentifier());
 }
Пример #30
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll();
     if ($shortcuts) {
         $shortcuts = msort($shortcuts, 'getSequence');
         $rows = array();
         foreach ($shortcuts as $shortcut) {
             $rows[] = array(phutil_render_tag('a', array('href' => $shortcut->getHref()), phutil_escape_html($shortcut->getName())), phutil_escape_html($shortcut->getDescription()));
         }
         $shortcut_table = new AphrontTableView($rows);
         $shortcut_table->setHeaders(array('Link', ''));
         $shortcut_table->setColumnClasses(array('pri', 'wide'));
         $shortcut_panel = new AphrontPanelView();
         $shortcut_panel->setHeader('Shortcuts');
         $shortcut_panel->appendChild($shortcut_table);
     } else {
         $shortcut_panel = null;
     }
     $repository = new PhabricatorRepository();
     $repositories = $repository->loadAll();
     foreach ($repositories as $key => $repo) {
         if (!$repo->isTracked()) {
             unset($repositories[$key]);
         }
     }
     $repository_ids = mpull($repositories, 'getID');
     $summaries = array();
     $commits = array();
     if ($repository_ids) {
         $summaries = queryfx_all($repository->establishConnection('r'), 'SELECT * FROM %T WHERE repositoryID IN (%Ld)', PhabricatorRepository::TABLE_SUMMARY, $repository_ids);
         $summaries = ipull($summaries, null, 'repositoryID');
         $commit_ids = array_filter(ipull($summaries, 'lastCommitID'));
         if ($commit_ids) {
             $commit = new PhabricatorRepositoryCommit();
             $commits = $commit->loadAllWhere('id IN (%Ld)', $commit_ids);
             $commits = mpull($commits, null, 'getRepositoryID');
         }
     }
     $rows = array();
     foreach ($repositories as $repository) {
         $id = $repository->getID();
         $commit = idx($commits, $id);
         $size = idx(idx($summaries, $id, array()), 'size', 0);
         $date = '-';
         $time = '-';
         if ($commit) {
             $date = phabricator_date($commit->getEpoch(), $user);
             $time = phabricator_time($commit->getEpoch(), $user);
         }
         $rows[] = array(phutil_render_tag('a', array('href' => '/diffusion/' . $repository->getCallsign() . '/'), phutil_escape_html($repository->getName())), phutil_escape_html($repository->getDetail('description')), PhabricatorRepositoryType::getNameForRepositoryType($repository->getVersionControlSystem()), $size ? number_format($size) : '-', $commit ? DiffusionView::linkCommit($repository, $commit->getCommitIdentifier()) : '-', $date, $time);
     }
     $repository_tool_uri = PhabricatorEnv::getProductionURI('/repository/');
     $repository_tool = phutil_render_tag('a', array('href' => $repository_tool_uri), 'repository tool');
     $no_repositories_txt = 'This instance of Phabricator does not have any ' . 'configured repositories. ';
     if ($user->getIsAdmin()) {
         $no_repositories_txt .= 'To setup one or more repositories, visit the ' . $repository_tool . '.';
     } else {
         $no_repositories_txt .= 'Ask an administrator to setup one or more ' . 'repositories via the ' . $repository_tool . '.';
     }
     $table = new AphrontTableView($rows);
     $table->setNoDataString($no_repositories_txt);
     $table->setHeaders(array('Repository', 'Description', 'VCS', 'Commits', 'Last', 'Date', 'Time'));
     $table->setColumnClasses(array('pri', 'wide', '', 'n', 'n', '', 'right'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Browse Repositories');
     $panel->appendChild($table);
     $crumbs = $this->buildCrumbs();
     return $this->buildStandardPageResponse(array($crumbs, $shortcut_panel, $panel), array('title' => 'Diffusion'));
 }