[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionBranchQueryConduitAPIMethod 4 extends DiffusionQueryConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'diffusion.branchquery'; 8 } 9 10 public function getMethodDescription() { 11 return pht('Determine what branches exist for a repository.'); 12 } 13 14 public function defineReturnType() { 15 return 'list<dict>'; 16 } 17 18 protected function defineCustomParamTypes() { 19 return array( 20 'limit' => 'optional int', 21 'offset' => 'optional int', 22 'contains' => 'optional string', 23 ); 24 } 25 26 protected function getGitResult(ConduitAPIRequest $request) { 27 $drequest = $this->getDiffusionRequest(); 28 $repository = $drequest->getRepository(); 29 30 $contains = $request->getValue('contains'); 31 if (strlen($contains)) { 32 // NOTE: We can't use DiffusionLowLevelGitRefQuery here because 33 // `git for-each-ref` does not support `--contains`. 34 if ($repository->isWorkingCopyBare()) { 35 list($stdout) = $repository->execxLocalCommand( 36 'branch --verbose --no-abbrev --contains %s --', 37 $contains); 38 $ref_map = DiffusionGitBranch::parseLocalBranchOutput( 39 $stdout); 40 } else { 41 list($stdout) = $repository->execxLocalCommand( 42 'branch -r --verbose --no-abbrev --contains %s --', 43 $contains); 44 $ref_map = DiffusionGitBranch::parseRemoteBranchOutput( 45 $stdout, 46 DiffusionGitBranch::DEFAULT_GIT_REMOTE); 47 } 48 49 $refs = array(); 50 foreach ($ref_map as $ref => $commit) { 51 $refs[] = id(new DiffusionRepositoryRef()) 52 ->setShortName($ref) 53 ->setCommitIdentifier($commit); 54 } 55 } else { 56 $refs = id(new DiffusionLowLevelGitRefQuery()) 57 ->setRepository($repository) 58 ->withIsOriginBranch(true) 59 ->execute(); 60 } 61 62 return $this->processBranchRefs($request, $refs); 63 } 64 65 protected function getMercurialResult(ConduitAPIRequest $request) { 66 $drequest = $this->getDiffusionRequest(); 67 $repository = $drequest->getRepository(); 68 69 $query = id(new DiffusionLowLevelMercurialBranchesQuery()) 70 ->setRepository($repository); 71 72 $contains = $request->getValue('contains'); 73 if (strlen($contains)) { 74 $query->withContainsCommit($contains); 75 } 76 77 $refs = $query->execute(); 78 79 return $this->processBranchRefs($request, $refs); 80 } 81 82 protected function getSVNResult(ConduitAPIRequest $request) { 83 // Since SVN doesn't have meaningful branches, just return nothing for all 84 // queries. 85 return array(); 86 } 87 88 private function processBranchRefs(ConduitAPIRequest $request, array $refs) { 89 $drequest = $this->getDiffusionRequest(); 90 $repository = $drequest->getRepository(); 91 $offset = $request->getValue('offset'); 92 $limit = $request->getValue('limit'); 93 94 foreach ($refs as $key => $ref) { 95 if (!$repository->shouldTrackBranch($ref->getShortName())) { 96 unset($refs[$key]); 97 } 98 } 99 100 // NOTE: We can't apply the offset or limit until here, because we may have 101 // filtered untrackable branches out of the result set. 102 103 if ($offset) { 104 $refs = array_slice($refs, $offset); 105 } 106 107 if ($limit) { 108 $refs = array_slice($refs, 0, $limit); 109 } 110 111 return mpull($refs, 'toDictionary'); 112 } 113 114 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |