2013-05-14 22:53:32 +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 DiffusionLastModifiedQueryConduitAPIMethod
|
|
|
|
extends DiffusionQueryConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'diffusion.lastmodifiedquery';
|
|
|
|
}
|
2013-05-14 22:53:32 +02:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-05-11 01:46:32 +02:00
|
|
|
return pht('Get the commits at which paths were last modified.');
|
2013-05-14 22:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
2014-05-11 01:46:32 +02:00
|
|
|
return 'map<string, string>';
|
2013-05-14 22:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function defineCustomParamTypes() {
|
|
|
|
return array(
|
2014-05-11 01:46:32 +02:00
|
|
|
'paths' => 'required map<string, string>',
|
2013-05-14 22:53:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getGitResult(ConduitAPIRequest $request) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
2014-05-11 02:26:03 +02:00
|
|
|
$paths = $request->getValue('paths');
|
|
|
|
$results = $this->loadCommitsFromCache($paths);
|
|
|
|
|
|
|
|
foreach ($paths as $path => $commit) {
|
|
|
|
if (array_key_exists($path, $results)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-11 01:46:32 +02:00
|
|
|
list($hash) = $repository->execxLocalCommand(
|
|
|
|
'log -n1 --format=%%H %s -- %s',
|
|
|
|
$commit,
|
|
|
|
$path);
|
2014-05-11 02:26:03 +02:00
|
|
|
$results[$path] = trim($hash);
|
2014-05-11 01:46:32 +02:00
|
|
|
}
|
2013-05-14 22:53:32 +02:00
|
|
|
|
2014-05-11 02:26:03 +02:00
|
|
|
return $results;
|
2013-05-14 22:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getSVNResult(ConduitAPIRequest $request) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
2014-05-11 02:26:03 +02:00
|
|
|
$results = array();
|
2014-05-11 01:46:32 +02:00
|
|
|
foreach ($request->getValue('paths') as $path => $commit) {
|
|
|
|
$history_result = DiffusionQuery::callConduitWithDiffusionRequest(
|
|
|
|
$request->getUser(),
|
|
|
|
$drequest,
|
|
|
|
'diffusion.historyquery',
|
|
|
|
array(
|
|
|
|
'commit' => $commit,
|
|
|
|
'path' => $path,
|
|
|
|
'limit' => 1,
|
|
|
|
'offset' => 0,
|
|
|
|
'needDirectChanges' => true,
|
|
|
|
'needChildChanges' => true,
|
|
|
|
));
|
|
|
|
|
|
|
|
$history_array = DiffusionPathChange::newFromConduit(
|
|
|
|
$history_result['pathChanges']);
|
|
|
|
if ($history_array) {
|
2014-05-11 02:26:03 +02:00
|
|
|
$results[$path] = head($history_array)
|
2014-05-11 01:46:32 +02:00
|
|
|
->getCommit()
|
|
|
|
->getCommitIdentifier();
|
|
|
|
}
|
2013-05-14 22:53:32 +02:00
|
|
|
}
|
|
|
|
|
2014-05-11 02:26:03 +02:00
|
|
|
return $results;
|
2013-05-14 22:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMercurialResult(ConduitAPIRequest $request) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
2014-05-11 02:26:03 +02:00
|
|
|
$paths = $request->getValue('paths');
|
|
|
|
$results = $this->loadCommitsFromCache($paths);
|
|
|
|
|
|
|
|
foreach ($paths as $path => $commit) {
|
|
|
|
if (array_key_exists($path, $results)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-11 01:46:32 +02:00
|
|
|
list($hash) = $repository->execxLocalCommand(
|
|
|
|
'log --template %s --limit 1 --removed --rev %s -- %s',
|
|
|
|
'{node}',
|
|
|
|
hgsprintf('reverse(ancestors(%s))', $commit),
|
|
|
|
nonempty(ltrim($path, '/'), '.'));
|
2014-05-11 02:26:03 +02:00
|
|
|
$results[$path] = trim($hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadCommitsFromCache(array $map) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
|
|
|
$path_map = id(new DiffusionPathIDQuery(array_keys($map)))
|
|
|
|
->loadPathIDs();
|
|
|
|
|
|
|
|
$commit_query = id(new DiffusionCommitQuery())
|
|
|
|
->setViewer($drequest->getUser())
|
|
|
|
->withRepository($repository)
|
|
|
|
->withIdentifiers(array_values($map));
|
|
|
|
$commit_query->execute();
|
|
|
|
|
|
|
|
$commit_map = $commit_query->getIdentifierMap();
|
|
|
|
$commit_map = mpull($commit_map, 'getID');
|
|
|
|
|
|
|
|
$graph_cache = new PhabricatorRepositoryGraphCache();
|
|
|
|
|
|
|
|
$results = array();
|
|
|
|
foreach ($map as $path => $commit) {
|
|
|
|
$path_id = idx($path_map, $path);
|
|
|
|
if (!$path_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$commit_id = idx($commit_map, $commit);
|
|
|
|
if (!$commit_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_result = $graph_cache->loadLastModifiedCommitID(
|
|
|
|
$commit_id,
|
|
|
|
$path_id);
|
|
|
|
|
|
|
|
if ($cache_result !== false) {
|
|
|
|
$results[$path] = $cache_result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($results) {
|
|
|
|
$commits = id(new DiffusionCommitQuery())
|
|
|
|
->setViewer($drequest->getUser())
|
|
|
|
->withRepository($repository)
|
|
|
|
->withIDs($results)
|
|
|
|
->execute();
|
|
|
|
foreach ($results as $path => $id) {
|
|
|
|
$commit = idx($commits, $id);
|
|
|
|
if ($commit) {
|
|
|
|
$results[$path] = $commit->getCommitIdentifier();
|
|
|
|
} else {
|
|
|
|
unset($results[$path]);
|
|
|
|
}
|
|
|
|
}
|
2013-05-14 22:53:32 +02:00
|
|
|
}
|
|
|
|
|
2014-05-11 02:26:03 +02:00
|
|
|
return $results;
|
2013-05-14 22:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|