Path: blob/master/src/applications/diffusion/conduit/DiffusionMergedCommitsQueryConduitAPIMethod.php
12242 views
<?php12final class DiffusionMergedCommitsQueryConduitAPIMethod3extends DiffusionQueryConduitAPIMethod {45public function getAPIMethodName() {6return 'diffusion.mergedcommitsquery';7}89public function getMethodDescription() {10return pht(11'Merged commit information for a specific commit in a repository.');12}1314protected function defineReturnType() {15return 'array';16}1718protected function defineCustomParamTypes() {19return array(20'commit' => 'required string',21'limit' => 'optional int',22);23}2425private function getLimit(ConduitAPIRequest $request) {26// TODO: Paginate this sensibly at some point.27return $request->getValue('limit', 4096);28}2930protected function getGitResult(ConduitAPIRequest $request) {31$drequest = $this->getDiffusionRequest();32$repository = $drequest->getRepository();33$commit = $request->getValue('commit');34$limit = $this->getLimit($request);3536list($parents) = $repository->execxLocalCommand(37'log -n 1 %s %s --',38'--format=%P',39gitsprintf('%s', $commit));4041$parents = preg_split('/\s+/', trim($parents));42if (count($parents) < 2) {43// This is not a merge commit, so it doesn't merge anything.44return array();45}4647// Get all of the commits which are not reachable from the first parent.48// These are the commits this change merges.4950$first_parent = head($parents);51list($logs) = $repository->execxLocalCommand(52'log -n %d %s %s %s --',53// NOTE: "+ 1" accounts for the merge commit itself.54$limit + 1,55'--format=%H',56gitsprintf('%s', $commit),57gitsprintf('%s', '^'.$first_parent));5859$hashes = explode("\n", trim($logs));6061// Remove the merge commit.62$hashes = array_diff($hashes, array($commit));6364$history = DiffusionQuery::loadHistoryForCommitIdentifiers(65$hashes,66$drequest);67return mpull($history, 'toDictionary');68}6970protected function getMercurialResult(ConduitAPIRequest $request) {71$drequest = $this->getDiffusionRequest();72$repository = $drequest->getRepository();73$commit = $request->getValue('commit');74$limit = $this->getLimit($request);7576list($parents) = $repository->execxLocalCommand(77'parents --template=%s --rev %s',78'{node}\\n',79hgsprintf('%s', $commit));80$parents = explode("\n", trim($parents));8182if (count($parents) < 2) {83// Not a merge commit.84return array();85}8687// NOTE: In Git, the first parent is the "mainline". In Mercurial, the88// second parent is the "mainline" (the way 'git merge' and 'hg merge'89// work is also reversed).9091$last_parent = last($parents);92list($logs) = $repository->execxLocalCommand(93'log --template=%s --follow --limit %d --rev %s:0 --prune %s --',94'{node}\\n',95$limit + 1,96$commit,97$last_parent);9899$hashes = explode("\n", trim($logs));100101// Remove the merge commit.102$hashes = array_diff($hashes, array($commit));103104$history = DiffusionQuery::loadHistoryForCommitIdentifiers(105$hashes,106$drequest);107return mpull($history, 'toDictionary');108}109110}111112113