[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionMergedCommitsQueryConduitAPIMethod 4 extends DiffusionQueryConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'diffusion.mergedcommitsquery'; 8 } 9 10 public function getMethodDescription() { 11 return 12 'Merged commit information for a specific commit in a repository.'; 13 } 14 15 public function defineReturnType() { 16 return 'array'; 17 } 18 19 protected function defineCustomParamTypes() { 20 return array( 21 'commit' => 'required string', 22 'limit' => 'optional int', 23 ); 24 } 25 26 private function getLimit(ConduitAPIRequest $request) { 27 return $request->getValue('limit', PHP_INT_MAX); 28 } 29 30 protected function getGitResult(ConduitAPIRequest $request) { 31 $drequest = $this->getDiffusionRequest(); 32 $repository = $drequest->getRepository(); 33 $commit = $request->getValue('commit'); 34 $limit = $this->getLimit($request); 35 36 list($parents) = $repository->execxLocalCommand( 37 'log -n 1 --format=%s %s', 38 '%P', 39 $commit); 40 41 $parents = preg_split('/\s+/', trim($parents)); 42 if (count($parents) < 2) { 43 // This is not a merge commit, so it doesn't merge anything. 44 return array(); 45 } 46 47 // Get all of the commits which are not reachable from the first parent. 48 // These are the commits this change merges. 49 50 $first_parent = head($parents); 51 list($logs) = $repository->execxLocalCommand( 52 'log -n %d --format=%s %s %s --', 53 // NOTE: "+ 1" accounts for the merge commit itself. 54 $limit + 1, 55 '%H', 56 $commit, 57 '^'.$first_parent); 58 59 $hashes = explode("\n", trim($logs)); 60 61 // Remove the merge commit. 62 $hashes = array_diff($hashes, array($commit)); 63 64 return DiffusionQuery::loadHistoryForCommitIdentifiers( 65 $hashes, 66 $drequest); 67 } 68 69 protected function getMercurialResult(ConduitAPIRequest $request) { 70 $drequest = $this->getDiffusionRequest(); 71 $repository = $drequest->getRepository(); 72 $commit = $request->getValue('commit'); 73 $limit = $this->getLimit($request); 74 75 list($parents) = $repository->execxLocalCommand( 76 'parents --template=%s --rev %s', 77 '{node}\\n', 78 $commit); 79 $parents = explode("\n", trim($parents)); 80 81 if (count($parents) < 2) { 82 // Not a merge commit. 83 return array(); 84 } 85 86 // NOTE: In Git, the first parent is the "mainline". In Mercurial, the 87 // second parent is the "mainline" (the way 'git merge' and 'hg merge' 88 // work is also reversed). 89 90 $last_parent = last($parents); 91 list($logs) = $repository->execxLocalCommand( 92 'log --template=%s --follow --limit %d --rev %s:0 --prune %s --', 93 '{node}\\n', 94 $limit + 1, 95 $commit, 96 $last_parent); 97 98 $hashes = explode("\n", trim($logs)); 99 100 // Remove the merge commit. 101 $hashes = array_diff($hashes, array($commit)); 102 103 return DiffusionQuery::loadHistoryForCommitIdentifiers( 104 $hashes, 105 $drequest); 106 } 107 108 }
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 |