protected function buildPropertyView(DiffusionRequest $drequest, PhabricatorActionListView $actions) { $viewer = $this->getRequest()->getUser(); $view = id(new PHUIPropertyListView())->setUser($viewer)->setActionList($actions); $stable_commit = $drequest->getStableCommit(); $view->addProperty(pht('Commit'), phutil_tag('a', array('href' => $drequest->generateURI(array('action' => 'commit', 'commit' => $stable_commit))), $drequest->getRepository()->formatCommitName($stable_commit))); return $view; }
protected function newBlameFuture(DiffusionRequest $request, $path) { $repository = $request->getRepository(); $commit = $request->getCommit(); // NOTE: We're using "--debug" to make "--changeset" give us the full // commit hashes. return $repository->getLocalCommandFuture('annotate --debug --changeset --rev %s -- %s', $commit, $path); }
private function newFile(DiffusionRequest $drequest, $content) { $path = $drequest->getPath(); $name = basename($path); $repository = $drequest->getRepository(); $repository_phid = $repository->getPHID(); $file = PhabricatorFile::buildFromFileDataOrHash($content, array('name' => $name, 'ttl' => time() + phutil_units('48 hours in seconds'), 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE)); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $file->attachToObject($repository_phid); unset($unguarded); return $file; }
protected static function newQueryObject($base_class, DiffusionRequest $request) { $repository = $request->getRepository(); $map = array(PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => 'Git', PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => 'Mercurial', PhabricatorRepositoryType::REPOSITORY_TYPE_SVN => 'Svn'); $name = idx($map, $repository->getVersionControlSystem()); if (!$name) { throw new Exception("Unsupported VCS!"); } $class = str_replace('Diffusion', 'Diffusion' . $name, $base_class); $obj = new $class(); $obj->request = $request; return $obj; }
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 final function newFromDiffusionRequest(DiffusionRequest $request) { $repository = $request->getRepository(); switch ($repository->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: $class = 'DiffusionGitBranchQuery'; break; default: throw new Exception("Unsupported VCS!"); } PhutilSymbolLoader::loadClass($class); $query = new $class(); $query->request = $request; return $query; }
public function processRequest() { $request = $this->getRequest(); $repository_phid = $request->getStr('repositoryPHID'); $repository = id(new PhabricatorRepository())->loadOneWhere('phid = %s', $repository_phid); if (!$repository) { return new Aphront400Response(); } $query_path = $request->getStr('q'); if (preg_match('@/$@', $query_path)) { $query_dir = $query_path; } else { $query_dir = dirname($query_path) . '/'; } $query_dir = ltrim($query_dir, '/'); $drequest = DiffusionRequest::newFromDictionary(array('repository' => $repository, 'path' => $query_dir)); $browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest); $paths = $browse_query->loadPaths(); $output = array(); foreach ($paths as $path) { $full_path = $query_dir . $path->getPath(); if ($path->getFileType() == DifferentialChangeType::FILE_DIRECTORY) { $full_path .= '/'; } $output[] = array('/' . $full_path, null, substr(md5($full_path), 0, 7)); } return id(new AphrontAjaxResponse())->setContent($output); }
public static final function newFromDiffusionRequest(DiffusionRequest $request) { $repository = $request->getRepository(); switch ($repository->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: $query = new DiffusionGitBranchQuery(); break; case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: $query = new DiffusionMercurialBranchQuery(); break; default: throw new Exception("Unsupported VCS!"); } $query->request = $request; return $query; }
public function willProcessRequest(array $data) { if (isset($data['callsign'])) { $drequest = DiffusionRequest::newFromAphrontRequestDictionary($data); $this->diffusionRequest = $drequest; } }
public function willProcessRequest(array $data) { // This controller doesn't use blob/path stuff, just pass the dictionary // in directly instead of using the AphrontRequest parsing mechanism. $drequest = DiffusionRequest::newFromDictionary($data); $this->diffusionRequest = $drequest; }
protected function processDiffusionRequest(AphrontRequest $request) { $repository_phid = $request->getStr('repositoryPHID'); $repository = id(new PhabricatorRepositoryQuery())->setViewer($request->getUser())->withPHIDs(array($repository_phid))->executeOne(); if (!$repository) { return new Aphront400Response(); } $query_path = $request->getStr('q'); if (preg_match('@/$@', $query_path)) { $query_dir = $query_path; } else { $query_dir = dirname($query_path) . '/'; } $query_dir = ltrim($query_dir, '/'); $drequest = DiffusionRequest::newFromDictionary(array('user' => $request->getUser(), 'repository' => $repository, 'path' => $query_dir)); $this->setDiffusionRequest($drequest); $browse_results = DiffusionBrowseResultSet::newFromConduit($this->callConduitWithDiffusionRequest('diffusion.browsequery', array('path' => $drequest->getPath(), 'commit' => $drequest->getCommit()))); $paths = $browse_results->getPaths(); $output = array(); foreach ($paths as $path) { $full_path = $query_dir . $path->getPath(); if ($path->getFileType() == DifferentialChangeType::FILE_DIRECTORY) { $full_path .= '/'; } $output[] = array('/' . $full_path, null, substr(md5($full_path), 0, 7)); } return id(new AphrontAjaxResponse())->setContent($output); }
public function testURIGeneration() { $map = array('/diffusion/A/browse/branch/path.ext;abc$1' => array('action' => 'browse', 'callsign' => 'A', 'branch' => 'branch', 'path' => 'path.ext', 'commit' => 'abc', 'line' => '1'), '/diffusion/A/browse/a%252Fb/path.ext' => array('action' => 'browse', 'callsign' => 'A', 'branch' => 'a/b', 'path' => 'path.ext'), '/diffusion/A/browse/%2B/%20%21' => array('action' => 'browse', 'callsign' => 'A', 'path' => '+/ !'), '/diffusion/A/browse/money/%24%24100$2' => array('action' => 'browse', 'callsign' => 'A', 'path' => 'money/$100', 'line' => '2'), '/diffusion/A/browse/path/to/file.ext?view=things' => array('action' => 'browse', 'callsign' => 'A', 'path' => 'path/to/file.ext', 'params' => array('view' => 'things')), '/diffusion/A/repository/master/' => array('action' => 'branch', 'callsign' => 'A', 'branch' => 'master'), 'path/to/file.ext;abc' => array('action' => 'rendering-ref', 'path' => 'path/to/file.ext', 'commit' => 'abc'), '/diffusion/A/browse/branch/path.ext$3-5%2C7-12%2C14' => array('action' => 'browse', 'callsign' => 'A', 'branch' => 'branch', 'path' => 'path.ext', 'line' => '3-5,7-12,14')); foreach ($map as $expect => $input) { $actual = DiffusionRequest::generateDiffusionURI($input); $this->assertEqual($expect, (string) $actual); } }
public function getURI() { if ($this->isExternal) { return $this->externalURI; } $request = DiffusionRequest::newFromDictionary(array('user' => PhabricatorUser::getOmnipotentUser(), 'repository' => $this->getRepository())); return $request->generateURI(array('action' => 'browse', 'path' => $this->getPath(), 'line' => $this->getLineNumber())); }
protected function initializeFromAphrontRequestDictionary(array $data) { parent::initializeFromAphrontRequestDictionary($data); if (!strncmp($this->path, ':', 1)) { $this->path = substr($this->path, 1); $this->path = ltrim($this->path, '/'); } }
private static function loadDiffusionChangesForCommit($commit) { $repository = id(new PhabricatorRepository())->load($commit->getRepositoryID()); $data = array('user' => PhabricatorUser::getOmnipotentUser(), 'initFromConduit' => false, 'repository' => $repository, 'commit' => $commit->getCommitIdentifier()); $drequest = DiffusionRequest::newFromDictionary($data); $change_query = DiffusionPathChangeQuery::newFromDiffusionRequest($drequest); return $change_query->loadChanges(); }
protected final function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit) { $viewer = PhabricatorUser::getOmnipotentUser(); $refs_raw = DiffusionQuery::callConduitWithDiffusionRequest($viewer, DiffusionRequest::newFromDictionary(array('repository' => $repository, 'user' => $viewer)), 'diffusion.querycommits', array('repositoryPHID' => $repository->getPHID(), 'phids' => array($commit->getPHID()), 'bypassCache' => true, 'needMessages' => true)); if (empty($refs_raw['data'])) { throw new Exception(pht('Unable to retrieve details for commit "%s"!', $commit->getPHID())); } $ref = DiffusionCommitRef::newFromConduitResult(head($refs_raw['data'])); $this->parseCommitWithRef($repository, $commit, $ref); }
public function getURI() { $repo = $this->getRepository(); $file = $this->getPath(); $line = $this->getLineNumber(); $drequest = DiffusionRequest::newFromAphrontRequestDictionary(array('callsign' => $repo->getCallsign())); $branch = $drequest->getBranchURIComponent($drequest->getBranch()); $file = $branch . ltrim($file, '/'); return '/diffusion/' . $repo->getCallsign() . '/browse/' . $file . '$' . $line; }
public function willProcessRequest(array $data) { $request = $this->getRequest(); if ($request->getStr('ref')) { $parts = explode(';', $request->getStr('ref')); $data['path'] = idx($parts, 0); $data['commit'] = idx($parts, 1); } $this->diffusionRequest = DiffusionRequest::newFromAphrontRequestDictionary($data); }
private function buildHistoryHeader(DiffusionRequest $drequest) { $viewer = $this->getViewer(); $browse_uri = $drequest->generateURI(array('action' => 'browse')); $browse_button = id(new PHUIButtonView())->setTag('a')->setText(pht('Browse'))->setHref($browse_uri)->setIcon('fa-files-o'); // TODO: Sometimes we do have a change view, we need to look at the most // recent history entry to figure it out. $request = $this->getRequest(); if ($request->getBool('copies')) { $branch_name = pht('Hide Copies/Branches'); $branch_uri = $request->getRequestURI()->alter('offset', null)->alter('copies', null); } else { $branch_name = pht('Show Copies/Branches'); $branch_uri = $request->getRequestURI()->alter('offset', null)->alter('copies', true); } $branch_button = id(new PHUIButtonView())->setTag('a')->setText($branch_name)->setIcon('fa-code-fork')->setHref($branch_uri); $header = id(new PHUIHeaderView())->setHeader(pht('History'))->addActionLink($browse_button)->addActionLink($branch_button); return $header; }
public function fromPartial($partial_string) { $this->objectPHID = null; // Look for diffs $matches = array(); if (preg_match('/^D([1-9]\\d*)$/', $partial_string, $matches)) { $diff_id = $matches[1]; $diff_rev = id(new DifferentialRevisionQuery())->setViewer($this->getUser())->withIDs(array($diff_id))->needCommitPHIDs(true)->executeOne(); if (!$diff_rev) { throw new ReleephCommitFinderException(pht('%s does not refer to an existing diff.', $partial_string)); } $commit_phids = $diff_rev->getCommitPHIDs(); if (!$commit_phids) { throw new ReleephCommitFinderException(pht('%s has no commits associated with it yet.', $partial_string)); } $this->objectPHID = $diff_rev->getPHID(); $commits = id(new DiffusionCommitQuery())->setViewer($this->getUser())->withPHIDs($commit_phids)->execute(); $commits = msort($commits, 'getEpoch'); return head($commits); } // Look for a raw commit number, or r<callsign><commit-number>. $repository = $this->releephProject->getRepository(); $dr_data = null; $matches = array(); if (preg_match('/^r(?P<callsign>[A-Z]+)(?P<commit>\\w+)$/', $partial_string, $matches)) { $callsign = $matches['callsign']; if ($callsign != $repository->getCallsign()) { throw new ReleephCommitFinderException(pht('%s is in a different repository to this Releeph project (%s).', $partial_string, $repository->getCallsign())); } else { $dr_data = $matches; } } else { $dr_data = array('callsign' => $repository->getCallsign(), 'commit' => $partial_string); } try { $dr_data['user'] = $this->getUser(); $dr = DiffusionRequest::newFromDictionary($dr_data); } catch (Exception $ex) { $message = pht('No commit matches %s: %s', $partial_string, $ex->getMessage()); throw new ReleephCommitFinderException($message); } $phabricator_repository_commit = $dr->loadCommit(); if (!$phabricator_repository_commit) { throw new ReleephCommitFinderException(pht("The commit %s doesn't exist in this repository.", $partial_string)); } // When requesting a single commit, if it has an associated review we // imply the review was requested instead. This is always correct for now // and consistent with the older behavior, although it might not be the // right rule in the future. $phids = PhabricatorEdgeQuery::loadDestinationPHIDs($phabricator_repository_commit->getPHID(), DiffusionCommitHasRevisionEdgeType::EDGECONST); if ($phids) { $this->objectPHID = head($phids); } return $phabricator_repository_commit; }
public function fromPartial($partial_string) { $this->objectPHID = null; // Look for diffs $matches = array(); if (preg_match('/^D([1-9]\\d*)$/', $partial_string, $matches)) { $diff_id = $matches[1]; // TOOD: (T603) This is all slated for annihilation. $diff_rev = id(new DifferentialRevision())->load($diff_id); if (!$diff_rev) { throw new ReleephCommitFinderException("{$partial_string} does not refer to an existing diff."); } $commit_phids = $diff_rev->loadCommitPHIDs(); if (!$commit_phids) { throw new ReleephCommitFinderException("{$partial_string} has no commits associated with it yet."); } $this->objectPHID = $diff_rev->getPHID(); $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere('phid IN (%Ls) ORDER BY epoch ASC', $commit_phids); return head($commits); } // Look for a raw commit number, or r<callsign><commit-number>. $repository = $this->releephProject->getRepository(); $dr_data = null; $matches = array(); if (preg_match('/^r(?P<callsign>[A-Z]+)(?P<commit>\\w+)$/', $partial_string, $matches)) { $callsign = $matches['callsign']; if ($callsign != $repository->getCallsign()) { throw new ReleephCommitFinderException(sprintf('%s is in a different repository to this Releeph project (%s).', $partial_string, $repository->getCallsign())); } else { $dr_data = $matches; } } else { $dr_data = array('callsign' => $repository->getCallsign(), 'commit' => $partial_string); } try { $dr_data['user'] = $this->getUser(); $dr = DiffusionRequest::newFromDictionary($dr_data); } catch (Exception $ex) { $message = "No commit matches {$partial_string}: " . $ex->getMessage(); throw new ReleephCommitFinderException($message); } $phabricator_repository_commit = $dr->loadCommit(); if (!$phabricator_repository_commit) { throw new ReleephCommitFinderException("The commit {$partial_string} doesn't exist in this repository."); } // When requesting a single commit, if it has an associated review we // imply the review was requested instead. This is always correct for now // and consistent with the older behavior, although it might not be the // right rule in the future. $phids = PhabricatorEdgeQuery::loadDestinationPHIDs($phabricator_repository_commit->getPHID(), PhabricatorEdgeConfig::TYPE_COMMIT_HAS_DREV); if ($phids) { $this->objectPHID = head($phids); } return $phabricator_repository_commit; }
protected function execute(ConduitAPIRequest $request) { $drequest = DiffusionRequest::newFromDictionary(array('callsign' => $request->getValue('callsign'), 'path' => $request->getValue('path'))); $history = DiffusionHistoryQuery::newFromDiffusionRequest($drequest)->setLimit(self::RESULT_LIMIT)->needDirectChanges(true)->needChildChanges(true)->loadHistory(); $raw_commit_identifiers = mpull($history, 'getCommitIdentifier'); $result = array(); foreach ($raw_commit_identifiers as $id) { $result[] = 'r' . $request->getValue('callsign') . $id; } return $result; }
public function getURI() { if (!$this->repository) { // This symbol is in the index, but we don't know which Repository it's // part of. Usually this means the Arcanist Project hasn't been linked // to a Repository. We can't generate a URI, so just fail. return null; } $request = DiffusionRequest::newFromDictionary(array('user' => PhabricatorUser::getOmnipotentUser(), 'repository' => $this->getRepository())); return $request->generateURI(array('action' => 'browse', 'path' => $this->getPath(), 'line' => $this->getLineNumber())); }
protected function buildPropertyView(DiffusionRequest $drequest, PhabricatorActionListView $actions) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView())->setUser($viewer)->setActionList($actions); $stable_commit = $drequest->getStableCommit(); $callsign = $drequest->getRepository()->getCallsign(); $view->addProperty(pht('Commit'), phutil_tag('a', array('href' => $drequest->generateURI(array('action' => 'commit', 'commit' => $stable_commit))), $drequest->getRepository()->formatCommitName($stable_commit))); if ($drequest->getSymbolicType() == 'tag') { $symbolic = $drequest->getSymbolicCommit(); $view->addProperty(pht('Tag'), $symbolic); $tags = $this->callConduitWithDiffusionRequest('diffusion.tagsquery', array('names' => array($symbolic), 'needMessages' => true)); $tags = DiffusionRepositoryTag::newFromConduit($tags); $tags = mpull($tags, null, 'getName'); $tag = idx($tags, $symbolic); if ($tag && strlen($tag->getMessage())) { $view->addSectionHeader(pht('Tag Content')); $view->addTextContent($this->markupText($tag->getMessage())); } } $repository = $drequest->getRepository(); $owners = 'PhabricatorOwnersApplication'; if (PhabricatorApplication::isClassInstalled($owners)) { $package_query = id(new PhabricatorOwnersPackageQuery())->setViewer($viewer)->withControl($repository->getPHID(), array($drequest->getPath())); $package_query->execute(); $packages = $package_query->getControllingPackagesForPath($repository->getPHID(), $drequest->getPath()); if ($packages) { $ownership = id(new PHUIStatusListView())->setUser($viewer); foreach ($packages as $package) { $icon = 'fa-list-alt'; $color = 'grey'; $item = id(new PHUIStatusItemView())->setIcon($icon, $color)->setTarget($viewer->renderHandle($package->getPHID())); $ownership->addItem($item); } } else { $ownership = phutil_tag('em', array(), pht('None')); } $view->addProperty(pht('Packages'), $ownership); } return $view; }
public static final function newFromDiffusionRequest(DiffusionRequest $request) { $repository = $request->getRepository(); switch ($repository->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: // TODO: Verify local-path? $class = 'DiffusionGitBrowseQuery'; break; case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: $class = 'DiffusionMercurialBrowseQuery'; break; case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: $class = 'DiffusionSvnBrowseQuery'; break; default: throw new Exception("Unsupported VCS!"); } PhutilSymbolLoader::loadClass($class); $query = new $class(); $query->request = $request; return $query; }
protected function execute(ConduitAPIRequest $request) { $drequest = DiffusionRequest::newFromDictionary(array('user' => $request->getUser(), 'callsign' => $request->getValue('callsign'), 'path' => $request->getValue('path'), 'branch' => $request->getValue('branch'))); $limit = nonempty($request->getValue('limit'), self::DEFAULT_LIMIT); $history_result = DiffusionQuery::callConduitWithDiffusionRequest($request->getUser(), $drequest, 'diffusion.historyquery', array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => 0, 'limit' => $limit, 'needDirectChanges' => true, 'needChildChanges' => true)); $history = DiffusionPathChange::newFromConduit($history_result['pathChanges']); $raw_commit_identifiers = mpull($history, 'getCommitIdentifier'); $result = array(); foreach ($raw_commit_identifiers as $id) { $result[] = 'r' . $request->getValue('callsign') . $id; } return $result; }
protected function initializeFromAphrontRequestDictionary(array $data) { parent::initializeFromAphrontRequestDictionary($data); if ($this->path === null) { $subpath = $this->repository->getDetail('svn-subpath'); if ($subpath) { $this->path = $subpath; } } if (!strncmp($this->path, ':', 1)) { $this->path = substr($this->path, 1); $this->path = ltrim($this->path, '/'); } }
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; }
protected final function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit) { if (!$this->shouldSkipImportStep()) { $viewer = PhabricatorUser::getOmnipotentUser(); $refs_raw = DiffusionQuery::callConduitWithDiffusionRequest($viewer, DiffusionRequest::newFromDictionary(array('repository' => $repository, 'user' => $viewer)), 'diffusion.querycommits', array('repositoryPHID' => $repository->getPHID(), 'phids' => array($commit->getPHID()), 'bypassCache' => true, 'needMessages' => true)); if (empty($refs_raw['data'])) { throw new Exception(pht('Unable to retrieve details for commit "%s"!', $commit->getPHID())); } $ref = DiffusionCommitRef::newFromConduitResult(head($refs_raw['data'])); $this->updateCommitData($ref); } if ($this->shouldQueueFollowupTasks()) { $this->queueTask($this->getFollowupTaskClass(), array('commitID' => $commit->getID()), array('priority' => PhabricatorWorker::PRIORITY_DEFAULT)); } }
protected function initializeFromAphrontRequestDictionary(array $data) { parent::initializeFromAphrontRequestDictionary($data); $path = $this->path; $parts = explode('/', $path); $branch = array_shift($parts); if ($branch != ':') { $this->branch = $this->decodeBranchName($branch); } foreach ($parts as $key => $part) { if ($part == '..') { unset($parts[$key]); } } $this->path = implode('/', $parts); }