protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $repository_phid = $request->getValue('repositoryPHID');
     $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne();
     if (!$repository) {
         throw new Exception(pht('No repository exists with PHID "%s".', $repository_phid));
     }
     $commit_name = $request->getValue('commit');
     $commit = id(new DiffusionCommitQuery())->setViewer($viewer)->withRepository($repository)->withIdentifiers(array($commit_name))->executeOne();
     if (!$commit) {
         throw new Exception(pht('No commit exists with identifier "%s".', $commit_name));
     }
     $branch = PhabricatorRepositoryBranch::loadOrCreateBranch($repository->getID(), $request->getValue('branch'));
     $coverage = $request->getValue('coverage');
     $path_map = id(new DiffusionPathIDQuery(array_keys($coverage)))->loadPathIDs();
     $conn = $repository->establishConnection('w');
     $sql = array();
     foreach ($coverage as $path => $coverage_info) {
         $sql[] = qsprintf($conn, '(%d, %d, %d, %s)', $branch->getID(), $path_map[$path], $commit->getID(), $coverage_info);
     }
     $table_name = 'repository_coverage';
     $conn->openTransaction();
     queryfx($conn, 'DELETE FROM %T WHERE branchID = %d', $table_name, $branch->getID());
     foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
         queryfx($conn, 'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %Q', $table_name, $chunk);
     }
     $conn->saveTransaction();
 }
 private function loadLintMessages(PhabricatorRepositoryBranch $branch, $limit, $offset)
 {
     $drequest = $this->getDiffusionRequest();
     if (!$branch) {
         return array();
     }
     $conn = $branch->establishConnection('r');
     $where = array(qsprintf($conn, 'branchID = %d', $branch->getID()));
     if ($drequest->getPath() != '') {
         $path = '/' . $drequest->getPath();
         $is_dir = substr($path, -1) == '/';
         $where[] = $is_dir ? qsprintf($conn, 'path LIKE %>', $path) : qsprintf($conn, 'path = %s', $path);
     }
     if ($drequest->getLint() != '') {
         $where[] = qsprintf($conn, 'code = %s', $drequest->getLint());
     }
     return queryfx_all($conn, 'SELECT *
     FROM %T
     WHERE %Q
     ORDER BY path, code, line LIMIT %d OFFSET %d', PhabricatorRepository::TABLE_LINTMESSAGE, implode(' AND ', $where), $limit, $offset);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $repository_phid = $request->getValue('repositoryPHID');
     $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne();
     if (!$repository) {
         throw new Exception(pht('No repository exists with PHID "%s".', $repository_phid));
     }
     $commit_name = $request->getValue('commit');
     $commit = id(new DiffusionCommitQuery())->setViewer($viewer)->withRepository($repository)->withIdentifiers(array($commit_name))->executeOne();
     if (!$commit) {
         throw new Exception(pht('No commit exists with identifier "%s".', $commit_name));
     }
     $branch = PhabricatorRepositoryBranch::loadOrCreateBranch($repository->getID(), $request->getValue('branch'));
     $coverage = $request->getValue('coverage');
     $path_map = id(new DiffusionPathIDQuery(array_keys($coverage)))->loadPathIDs();
     $conn = $repository->establishConnection('w');
     $sql = array();
     foreach ($coverage as $path => $coverage_info) {
         $sql[] = qsprintf($conn, '(%d, %d, %d, %s)', $branch->getID(), $path_map[$path], $commit->getID(), $coverage_info);
     }
     $table_name = 'repository_coverage';
     $conn->openTransaction();
     $mode = $request->getValue('mode');
     switch ($mode) {
         case '':
         case 'overwrite':
             // sets the coverage for the whole branch, deleting all previous
             // coverage information
             queryfx($conn, 'DELETE FROM %T WHERE branchID = %d', $table_name, $branch->getID());
             break;
         case 'update':
             // sets the coverage for the provided files on the specified commit
             break;
         default:
             $conn->killTransaction();
             throw new Exception(pht('Invalid mode "%s".', $mode));
     }
     foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
         queryfx($conn, 'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %Q' . ' ON DUPLICATE KEY UPDATE coverage=VALUES(coverage)', $table_name, $chunk);
     }
     $conn->saveTransaction();
 }
 public function run($dir)
 {
     $working_copy = ArcanistWorkingCopyIdentity::newFromPath($dir);
     $configuration_manager = new ArcanistConfigurationManager();
     $configuration_manager->setWorkingCopyIdentity($working_copy);
     $api = ArcanistRepositoryAPI::newAPIFromConfigurationManager($configuration_manager);
     $this->svnRoot = id(new PhutilURI($api->getSourceControlPath()))->getPath();
     if ($api instanceof ArcanistGitAPI) {
         $svn_fetch = $api->getGitConfig('svn-remote.svn.fetch');
         list($this->svnRoot) = explode(':', $svn_fetch);
         if ($this->svnRoot != '') {
             $this->svnRoot = '/' . $this->svnRoot;
         }
     }
     $callsign = $configuration_manager->getConfigFromAnySource('repository.callsign');
     $uuid = $api->getRepositoryUUID();
     $remote_uri = $api->getRemoteURI();
     $repository_query = id(new PhabricatorRepositoryQuery())->setViewer(PhabricatorUser::getOmnipotentUser());
     if ($callsign) {
         $repository_query->withCallsigns(array($callsign));
     } else {
         if ($uuid) {
             $repository_query->withUUIDs(array($uuid));
         } else {
             if ($remote_uri) {
                 $repository_query->withRemoteURIs(array($remote_uri));
             }
         }
     }
     $repository = $repository_query->executeOne();
     $branch_name = $api->getBranchName();
     if (!$repository) {
         throw new Exception(pht('No repository was found.'));
     }
     $this->branch = PhabricatorRepositoryBranch::loadOrCreateBranch($repository->getID(), $branch_name);
     $this->conn = $this->branch->establishConnection('w');
     $this->lintCommit = null;
     if (!$this->all) {
         $this->lintCommit = $this->branch->getLintCommit();
     }
     if ($this->lintCommit) {
         try {
             $commit = $this->lintCommit;
             if ($this->svnRoot) {
                 $commit = $api->getCanonicalRevisionName('@' . $commit);
             }
             $all_files = $api->getChangedFiles($commit);
         } catch (ArcanistCapabilityNotSupportedException $ex) {
             $this->lintCommit = null;
         }
     }
     if (!$this->lintCommit) {
         $where = $this->svnRoot ? qsprintf($this->conn, 'AND path LIKE %>', $this->svnRoot . '/') : '';
         queryfx($this->conn, 'DELETE FROM %T WHERE branchID = %d %Q', PhabricatorRepository::TABLE_LINTMESSAGE, $this->branch->getID(), $where);
         $all_files = $api->getAllFiles();
     }
     $count = 0;
     $files = array();
     foreach ($all_files as $file => $val) {
         $count++;
         if (!$this->lintCommit) {
             $file = $val;
         } else {
             $this->deletes[] = $this->svnRoot . '/' . $file;
             if ($val & ArcanistRepositoryAPI::FLAG_DELETED) {
                 continue;
             }
         }
         $files[$file] = $file;
         if (count($files) >= $this->chunkSize) {
             $this->runArcLint($files);
             $files = array();
         }
     }
     $this->runArcLint($files);
     $this->saveLintMessages();
     $this->lintCommit = $api->getUnderlyingWorkingCopyRevision();
     $this->branch->setLintCommit($this->lintCommit);
     $this->branch->save();
     if ($this->blame) {
         $this->blameAuthors();
         $this->blame = array();
     }
     return $count;
 }
Beispiel #5
0
 public function loadBranch()
 {
     // TODO: Get rid of this and do real Queries on real objects.
     if ($this->branchObject === false) {
         $this->branchObject = PhabricatorRepositoryBranch::loadBranch($this->getRepository()->getID(), $this->getArcanistBranch());
     }
     return $this->branchObject;
 }
 protected function buildPropertyView(DiffusionRequest $drequest, PhabricatorRepositoryBranch $branch, $total, PhabricatorActionListView $actions)
 {
     $viewer = $this->getRequest()->getUser();
     $view = id(new PHUIPropertyListView())->setUser($viewer)->setActionList($actions);
     $lint_commit = $branch->getLintCommit();
     $view->addProperty(pht('Lint Commit'), phutil_tag('a', array('href' => $drequest->generateURI(array('action' => 'commit', 'commit' => $lint_commit))), $drequest->getRepository()->formatCommitName($lint_commit)));
     $view->addProperty(pht('Total Messages'), pht('%s', new PhutilNumber($total)));
     return $view;
 }
 public function run($dir)
 {
     $working_copy = ArcanistWorkingCopyIdentity::newFromPath($dir);
     $configuration_manager = new ArcanistConfigurationManager();
     $configuration_manager->setWorkingCopyIdentity($working_copy);
     $api = ArcanistRepositoryAPI::newAPIFromConfigurationManager($configuration_manager);
     $this->svnRoot = id(new PhutilURI($api->getSourceControlPath()))->getPath();
     if ($api instanceof ArcanistGitAPI) {
         $svn_fetch = $api->getGitConfig('svn-remote.svn.fetch');
         list($this->svnRoot) = explode(':', $svn_fetch);
         if ($this->svnRoot != '') {
             $this->svnRoot = '/' . $this->svnRoot;
         }
     }
     $project_id = $working_copy->getProjectID();
     $project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere('name = %s', $project_id);
     if (!$project || !$project->getRepositoryID()) {
         throw new Exception("Couldn't find repository for {$project_id}.");
     }
     $branch_name = $api->getBranchName();
     $this->branch = PhabricatorRepositoryBranch::loadOrCreateBranch($project->getRepositoryID(), $branch_name);
     $this->conn = $this->branch->establishConnection('w');
     $this->lintCommit = null;
     if (!$this->all) {
         $this->lintCommit = $this->branch->getLintCommit();
     }
     if ($this->lintCommit) {
         try {
             $commit = $this->lintCommit;
             if ($this->svnRoot) {
                 $commit = $api->getCanonicalRevisionName('@' . $commit);
             }
             $all_files = $api->getChangedFiles($commit);
         } catch (ArcanistCapabilityNotSupportedException $ex) {
             $this->lintCommit = null;
         }
     }
     if (!$this->lintCommit) {
         $where = $this->svnRoot ? qsprintf($this->conn, 'AND path LIKE %>', $this->svnRoot . '/') : '';
         queryfx($this->conn, 'DELETE FROM %T WHERE branchID = %d %Q', PhabricatorRepository::TABLE_LINTMESSAGE, $this->branch->getID(), $where);
         $all_files = $api->getAllFiles();
     }
     $count = 0;
     $files = array();
     foreach ($all_files as $file => $val) {
         $count++;
         if (!$this->lintCommit) {
             $file = $val;
         } else {
             $this->deletes[] = $this->svnRoot . '/' . $file;
             if ($val & ArcanistRepositoryAPI::FLAG_DELETED) {
                 continue;
             }
         }
         $files[$file] = $file;
         if (count($files) >= $this->chunkSize) {
             $this->runArcLint($files);
             $files = array();
         }
     }
     $this->runArcLint($files);
     $this->saveLintMessages();
     $this->lintCommit = $api->getUnderlyingWorkingCopyRevision();
     $this->branch->setLintCommit($this->lintCommit);
     $this->branch->save();
     if ($this->blame) {
         $this->blameAuthors();
         $this->blame = array();
     }
     return $count;
 }