2013-05-21 02:04:51 +02:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class DiffusionMergedCommitsQueryConduitAPIMethod
|
|
|
|
extends DiffusionQueryConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'diffusion.mergedcommitsquery';
|
|
|
|
}
|
2013-05-21 02:04:51 +02:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
|
|
|
return
|
|
|
|
'Merged commit information for a specific commit in a repository.';
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2013-05-21 02:04:51 +02:00
|
|
|
return 'array';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function defineCustomParamTypes() {
|
|
|
|
return array(
|
|
|
|
'commit' => 'required string',
|
|
|
|
'limit' => 'optional int',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getLimit(ConduitAPIRequest $request) {
|
|
|
|
return $request->getValue('limit', PHP_INT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getGitResult(ConduitAPIRequest $request) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
$commit = $request->getValue('commit');
|
|
|
|
$limit = $this->getLimit($request);
|
|
|
|
|
|
|
|
list($parents) = $repository->execxLocalCommand(
|
|
|
|
'log -n 1 --format=%s %s',
|
|
|
|
'%P',
|
|
|
|
$commit);
|
|
|
|
|
|
|
|
$parents = preg_split('/\s+/', trim($parents));
|
|
|
|
if (count($parents) < 2) {
|
|
|
|
// This is not a merge commit, so it doesn't merge anything.
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all of the commits which are not reachable from the first parent.
|
|
|
|
// These are the commits this change merges.
|
|
|
|
|
|
|
|
$first_parent = head($parents);
|
|
|
|
list($logs) = $repository->execxLocalCommand(
|
|
|
|
'log -n %d --format=%s %s %s --',
|
|
|
|
// NOTE: "+ 1" accounts for the merge commit itself.
|
|
|
|
$limit + 1,
|
|
|
|
'%H',
|
|
|
|
$commit,
|
|
|
|
'^'.$first_parent);
|
|
|
|
|
|
|
|
$hashes = explode("\n", trim($logs));
|
|
|
|
|
|
|
|
// Remove the merge commit.
|
|
|
|
$hashes = array_diff($hashes, array($commit));
|
|
|
|
|
2015-02-17 22:54:59 +01:00
|
|
|
$history = DiffusionQuery::loadHistoryForCommitIdentifiers(
|
2013-05-21 02:04:51 +02:00
|
|
|
$hashes,
|
|
|
|
$drequest);
|
2015-02-17 22:54:59 +01:00
|
|
|
return mpull($history, 'toDictionary');
|
2013-05-21 02:04:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMercurialResult(ConduitAPIRequest $request) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
$commit = $request->getValue('commit');
|
|
|
|
$limit = $this->getLimit($request);
|
|
|
|
|
|
|
|
list($parents) = $repository->execxLocalCommand(
|
|
|
|
'parents --template=%s --rev %s',
|
|
|
|
'{node}\\n',
|
|
|
|
$commit);
|
|
|
|
$parents = explode("\n", trim($parents));
|
|
|
|
|
|
|
|
if (count($parents) < 2) {
|
|
|
|
// Not a merge commit.
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: In Git, the first parent is the "mainline". In Mercurial, the
|
|
|
|
// second parent is the "mainline" (the way 'git merge' and 'hg merge'
|
|
|
|
// work is also reversed).
|
|
|
|
|
|
|
|
$last_parent = last($parents);
|
|
|
|
list($logs) = $repository->execxLocalCommand(
|
|
|
|
'log --template=%s --follow --limit %d --rev %s:0 --prune %s --',
|
|
|
|
'{node}\\n',
|
|
|
|
$limit + 1,
|
|
|
|
$commit,
|
|
|
|
$last_parent);
|
|
|
|
|
|
|
|
$hashes = explode("\n", trim($logs));
|
|
|
|
|
|
|
|
// Remove the merge commit.
|
|
|
|
$hashes = array_diff($hashes, array($commit));
|
|
|
|
|
2015-02-17 22:54:59 +01:00
|
|
|
$history = DiffusionQuery::loadHistoryForCommitIdentifiers(
|
2013-05-21 02:04:51 +02:00
|
|
|
$hashes,
|
|
|
|
$drequest);
|
2015-02-17 22:54:59 +01:00
|
|
|
return mpull($history, 'toDictionary');
|
2013-05-21 02:04:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|