mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Diffusion - tag queries => conduit
Summary: title. Ref T2784. Test Plan: foreach of SVN, Mercurial, and Git, loaded up a repository. Verified that only git had a tags box and it showed up correctly. Went to CALLSIGN/tags and verified that only git had a tags box and it showed up correctly. Went to various commits across vcs and verified it said "none" unless it was a git commit that also was tagged. Reviewers: epriestley Reviewed By: epriestley CC: chad, aran, Korvin Maniphest Tasks: T2784 Differential Revision: https://secure.phabricator.com/D5894
This commit is contained in:
parent
48b7539d7d
commit
c36f44a014
14 changed files with 197 additions and 255 deletions
|
@ -153,6 +153,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_diffusion_getcommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getcommits_Method.php',
|
||||
'ConduitAPI_diffusion_getlintmessages_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getlintmessages_Method.php',
|
||||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getrecentcommitsbypath_Method.php',
|
||||
'ConduitAPI_diffusion_tagsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_tagsquery_Method.php',
|
||||
'ConduitAPI_feed_Method' => 'applications/feed/conduit/ConduitAPI_feed_Method.php',
|
||||
'ConduitAPI_feed_publish_Method' => 'applications/feed/conduit/ConduitAPI_feed_publish_Method.php',
|
||||
'ConduitAPI_feed_query_Method' => 'applications/feed/conduit/ConduitAPI_feed_query_Method.php',
|
||||
|
@ -417,7 +418,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionCommitParentsQuery.php',
|
||||
'DiffusionCommitQuery' => 'applications/diffusion/query/DiffusionCommitQuery.php',
|
||||
'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php',
|
||||
'DiffusionCommitTagsQuery' => 'applications/diffusion/query/committags/DiffusionCommitTagsQuery.php',
|
||||
'DiffusionContainsQuery' => 'applications/diffusion/query/contains/DiffusionContainsQuery.php',
|
||||
'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php',
|
||||
'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php',
|
||||
|
@ -429,7 +429,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionGitBranch' => 'applications/diffusion/data/DiffusionGitBranch.php',
|
||||
'DiffusionGitBranchTestCase' => 'applications/diffusion/data/__tests__/DiffusionGitBranchTestCase.php',
|
||||
'DiffusionGitCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionGitCommitParentsQuery.php',
|
||||
'DiffusionGitCommitTagsQuery' => 'applications/diffusion/query/committags/DiffusionGitCommitTagsQuery.php',
|
||||
'DiffusionGitContainsQuery' => 'applications/diffusion/query/contains/DiffusionGitContainsQuery.php',
|
||||
'DiffusionGitDiffQuery' => 'applications/diffusion/query/diff/DiffusionGitDiffQuery.php',
|
||||
'DiffusionGitFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php',
|
||||
|
@ -438,7 +437,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionGitMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionGitMergedCommitsQuery.php',
|
||||
'DiffusionGitRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php',
|
||||
'DiffusionGitRequest' => 'applications/diffusion/request/DiffusionGitRequest.php',
|
||||
'DiffusionGitTagListQuery' => 'applications/diffusion/query/taglist/DiffusionGitTagListQuery.php',
|
||||
'DiffusionHistoryController' => 'applications/diffusion/controller/DiffusionHistoryController.php',
|
||||
'DiffusionHistoryQuery' => 'applications/diffusion/query/history/DiffusionHistoryQuery.php',
|
||||
'DiffusionHistoryTableView' => 'applications/diffusion/view/DiffusionHistoryTableView.php',
|
||||
|
@ -452,7 +450,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionLintDetailsController' => 'applications/diffusion/controller/DiffusionLintDetailsController.php',
|
||||
'DiffusionLintSaveRunner' => 'applications/diffusion/DiffusionLintSaveRunner.php',
|
||||
'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php',
|
||||
'DiffusionMercurialCommitTagsQuery' => 'applications/diffusion/query/committags/DiffusionMercurialCommitTagsQuery.php',
|
||||
'DiffusionMercurialContainsQuery' => 'applications/diffusion/query/contains/DiffusionMercurialContainsQuery.php',
|
||||
'DiffusionMercurialDiffQuery' => 'applications/diffusion/query/diff/DiffusionMercurialDiffQuery.php',
|
||||
'DiffusionMercurialFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php',
|
||||
|
@ -461,7 +458,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionMercurialMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionMercurialMergedCommitsQuery.php',
|
||||
'DiffusionMercurialRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionMercurialRawDiffQuery.php',
|
||||
'DiffusionMercurialRequest' => 'applications/diffusion/request/DiffusionMercurialRequest.php',
|
||||
'DiffusionMercurialTagListQuery' => 'applications/diffusion/query/taglist/DiffusionMercurialTagListQuery.php',
|
||||
'DiffusionMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionMergedCommitsQuery.php',
|
||||
'DiffusionPathChange' => 'applications/diffusion/data/DiffusionPathChange.php',
|
||||
'DiffusionPathChangeQuery' => 'applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php',
|
||||
|
@ -481,7 +477,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionRequest' => 'applications/diffusion/request/DiffusionRequest.php',
|
||||
'DiffusionSetupException' => 'applications/diffusion/exception/DiffusionSetupException.php',
|
||||
'DiffusionSvnCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionSvnCommitParentsQuery.php',
|
||||
'DiffusionSvnCommitTagsQuery' => 'applications/diffusion/query/committags/DiffusionSvnCommitTagsQuery.php',
|
||||
'DiffusionSvnContainsQuery' => 'applications/diffusion/query/contains/DiffusionSvnContainsQuery.php',
|
||||
'DiffusionSvnDiffQuery' => 'applications/diffusion/query/diff/DiffusionSvnDiffQuery.php',
|
||||
'DiffusionSvnFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionSvnFileContentQuery.php',
|
||||
|
@ -490,11 +485,9 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionSvnMergedCommitsQuery.php',
|
||||
'DiffusionSvnRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionSvnRawDiffQuery.php',
|
||||
'DiffusionSvnRequest' => 'applications/diffusion/request/DiffusionSvnRequest.php',
|
||||
'DiffusionSvnTagListQuery' => 'applications/diffusion/query/taglist/DiffusionSvnTagListQuery.php',
|
||||
'DiffusionSymbolController' => 'applications/diffusion/controller/DiffusionSymbolController.php',
|
||||
'DiffusionSymbolQuery' => 'applications/diffusion/query/DiffusionSymbolQuery.php',
|
||||
'DiffusionTagListController' => 'applications/diffusion/controller/DiffusionTagListController.php',
|
||||
'DiffusionTagListQuery' => 'applications/diffusion/query/taglist/DiffusionTagListQuery.php',
|
||||
'DiffusionTagListView' => 'applications/diffusion/view/DiffusionTagListView.php',
|
||||
'DiffusionURITestCase' => 'applications/diffusion/request/__tests__/DiffusionURITestCase.php',
|
||||
'DiffusionView' => 'applications/diffusion/view/DiffusionView.php',
|
||||
|
@ -1926,6 +1919,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPI_diffusion_Method',
|
||||
'ConduitAPI_diffusion_getlintmessages_Method' => 'ConduitAPI_diffusion_Method',
|
||||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPI_diffusion_Method',
|
||||
'ConduitAPI_diffusion_tagsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||
'ConduitAPI_feed_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_feed_publish_Method' => 'ConduitAPI_feed_Method',
|
||||
'ConduitAPI_feed_query_Method' => 'ConduitAPI_feed_Method',
|
||||
|
@ -2180,7 +2174,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionCommitParentsQuery' => 'DiffusionQuery',
|
||||
'DiffusionCommitQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'DiffusionCommitTagsController' => 'DiffusionController',
|
||||
'DiffusionCommitTagsQuery' => 'DiffusionQuery',
|
||||
'DiffusionContainsQuery' => 'DiffusionQuery',
|
||||
'DiffusionController' => 'PhabricatorController',
|
||||
'DiffusionDiffController' => 'DiffusionController',
|
||||
|
@ -2190,7 +2183,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionFileContentQuery' => 'DiffusionQuery',
|
||||
'DiffusionGitBranchTestCase' => 'PhabricatorTestCase',
|
||||
'DiffusionGitCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
||||
'DiffusionGitCommitTagsQuery' => 'DiffusionCommitTagsQuery',
|
||||
'DiffusionGitContainsQuery' => 'DiffusionContainsQuery',
|
||||
'DiffusionGitDiffQuery' => 'DiffusionDiffQuery',
|
||||
'DiffusionGitFileContentQuery' => 'DiffusionFileContentQuery',
|
||||
|
@ -2199,7 +2191,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionGitMergedCommitsQuery' => 'DiffusionMergedCommitsQuery',
|
||||
'DiffusionGitRawDiffQuery' => 'DiffusionRawDiffQuery',
|
||||
'DiffusionGitRequest' => 'DiffusionRequest',
|
||||
'DiffusionGitTagListQuery' => 'DiffusionTagListQuery',
|
||||
'DiffusionHistoryController' => 'DiffusionController',
|
||||
'DiffusionHistoryQuery' => 'DiffusionQuery',
|
||||
'DiffusionHistoryTableView' => 'DiffusionView',
|
||||
|
@ -2212,7 +2203,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionLintController' => 'DiffusionController',
|
||||
'DiffusionLintDetailsController' => 'DiffusionController',
|
||||
'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
||||
'DiffusionMercurialCommitTagsQuery' => 'DiffusionCommitTagsQuery',
|
||||
'DiffusionMercurialContainsQuery' => 'DiffusionContainsQuery',
|
||||
'DiffusionMercurialDiffQuery' => 'DiffusionDiffQuery',
|
||||
'DiffusionMercurialFileContentQuery' => 'DiffusionFileContentQuery',
|
||||
|
@ -2221,7 +2211,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionMercurialMergedCommitsQuery' => 'DiffusionMergedCommitsQuery',
|
||||
'DiffusionMercurialRawDiffQuery' => 'DiffusionRawDiffQuery',
|
||||
'DiffusionMercurialRequest' => 'DiffusionRequest',
|
||||
'DiffusionMercurialTagListQuery' => 'DiffusionTagListQuery',
|
||||
'DiffusionMergedCommitsQuery' => 'DiffusionQuery',
|
||||
'DiffusionPathCompleteController' => 'DiffusionController',
|
||||
'DiffusionPathQueryTestCase' => 'PhabricatorTestCase',
|
||||
|
@ -2233,7 +2222,6 @@ phutil_register_library_map(array(
|
|||
'DiffusionRepositoryController' => 'DiffusionController',
|
||||
'DiffusionSetupException' => 'AphrontUsageException',
|
||||
'DiffusionSvnCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
||||
'DiffusionSvnCommitTagsQuery' => 'DiffusionCommitTagsQuery',
|
||||
'DiffusionSvnContainsQuery' => 'DiffusionContainsQuery',
|
||||
'DiffusionSvnDiffQuery' => 'DiffusionDiffQuery',
|
||||
'DiffusionSvnFileContentQuery' => 'DiffusionFileContentQuery',
|
||||
|
@ -2242,11 +2230,9 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnMergedCommitsQuery' => 'DiffusionMergedCommitsQuery',
|
||||
'DiffusionSvnRawDiffQuery' => 'DiffusionRawDiffQuery',
|
||||
'DiffusionSvnRequest' => 'DiffusionRequest',
|
||||
'DiffusionSvnTagListQuery' => 'DiffusionTagListQuery',
|
||||
'DiffusionSymbolController' => 'DiffusionController',
|
||||
'DiffusionSymbolQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'DiffusionTagListController' => 'DiffusionController',
|
||||
'DiffusionTagListQuery' => 'DiffusionQuery',
|
||||
'DiffusionTagListView' => 'DiffusionView',
|
||||
'DiffusionURITestCase' => 'ArcanistPhutilTestCase',
|
||||
'DiffusionView' => 'AphrontView',
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_diffusion_tagsquery_Method
|
||||
extends ConduitAPI_diffusion_abstractquery_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return
|
||||
'Find tags for a given commit or list tags in the repository.';
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
protected function defineCustomParamTypes() {
|
||||
return array(
|
||||
'commit' => 'optional string',
|
||||
'offset' => 'optional int',
|
||||
'limit' => 'optional int',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getGitResult(ConduitAPIRequest $request) {
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
$commit = $drequest->getCommit();
|
||||
$offset = $request->getValue('offset');
|
||||
$limit = $request->getValue('limit');
|
||||
|
||||
if (!$commit) {
|
||||
return $this->loadGitTagList($offset, $limit);
|
||||
}
|
||||
|
||||
list($err, $stdout) = $repository->execLocalCommand(
|
||||
'tag -l --contains %s',
|
||||
$commit);
|
||||
|
||||
if ($err) {
|
||||
// Git exits with an error code if the commit is bogus.
|
||||
return array();
|
||||
}
|
||||
|
||||
$stdout = trim($stdout);
|
||||
if (!strlen($stdout)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$tag_names = explode("\n", $stdout);
|
||||
$tag_names = array_fill_keys($tag_names, true);
|
||||
|
||||
$tags = $this->loadGitTagList($offset = 0, $limit = 0, $serialize = false);
|
||||
|
||||
$result = array();
|
||||
foreach ($tags as $tag) {
|
||||
if (isset($tag_names[$tag->getName()])) {
|
||||
$result[] = $tag->toDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
if ($offset) {
|
||||
$result = array_slice($result, $offset);
|
||||
}
|
||||
if ($limit) {
|
||||
$result = array_slice($result, 0, $limit);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function loadGitTagList($offset, $limit, $serialize=true) {
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
$count = $offset + $limit;
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'for-each-ref %C --sort=-creatordate --format=%s refs/tags',
|
||||
$count ? '--count='.(int)$count : null,
|
||||
'%(objectname) %(objecttype) %(refname) %(*objectname) %(*objecttype) '.
|
||||
'%(subject)%01%(creator)');
|
||||
|
||||
$stdout = trim($stdout);
|
||||
if (!strlen($stdout)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
foreach (explode("\n", $stdout) as $line) {
|
||||
list($info, $creator) = explode("\1", $line);
|
||||
list(
|
||||
$objectname,
|
||||
$objecttype,
|
||||
$refname,
|
||||
$refobjectname,
|
||||
$refobjecttype,
|
||||
$description) = explode(' ', $info, 6);
|
||||
|
||||
$matches = null;
|
||||
if (!preg_match('/^(.*) ([0-9]+) ([0-9+-]+)$/', $creator, $matches)) {
|
||||
// It's possible a tag doesn't have a creator (tagger)
|
||||
$author = null;
|
||||
$epoch = null;
|
||||
} else {
|
||||
$author = $matches[1];
|
||||
$epoch = $matches[2];
|
||||
}
|
||||
|
||||
$tag = new DiffusionRepositoryTag();
|
||||
$tag->setAuthor($author);
|
||||
$tag->setEpoch($epoch);
|
||||
$tag->setCommitIdentifier(nonempty($refobjectname, $objectname));
|
||||
$tag->setName(preg_replace('@^refs/tags/@', '', $refname));
|
||||
$tag->setDescription($description);
|
||||
$tag->setType('git/'.$objecttype);
|
||||
|
||||
$tags[] = $tag;
|
||||
}
|
||||
|
||||
if ($offset) {
|
||||
$tags = array_slice($tags, $offset);
|
||||
}
|
||||
|
||||
if ($serialize) {
|
||||
$tags = mpull($tags, 'toDictionary');
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,9 +10,19 @@ final class DiffusionCommitTagsController extends DiffusionController {
|
|||
$request = $this->getDiffusionRequest();
|
||||
$tag_limit = 10;
|
||||
|
||||
$tag_query = DiffusionCommitTagsQuery::newFromDiffusionRequest($request);
|
||||
$tag_query->setLimit($tag_limit + 1);
|
||||
$tags = $tag_query->loadTags();
|
||||
$tags = array();
|
||||
try {
|
||||
$tags = DiffusionRepositoryTag::newFromConduit(
|
||||
$this->callConduitWithDiffusionRequest(
|
||||
'diffusion.tagsquery',
|
||||
array(
|
||||
'commit' => $request->getCommit(),
|
||||
'limit' => $tag_limit + 1)));
|
||||
} catch (ConduitException $ex) {
|
||||
if ($ex->getMessage() != 'ERR-UNSUPPORTED-VCS') {
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
$has_more_tags = (count($tags) > $tag_limit);
|
||||
$tags = array_slice($tags, 0, $tag_limit);
|
||||
|
|
|
@ -216,10 +216,17 @@ final class DiffusionRepositoryController extends DiffusionController {
|
|||
|
||||
private function buildTagListTable(DiffusionRequest $drequest) {
|
||||
$tag_limit = 15;
|
||||
|
||||
$query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
|
||||
$query->setLimit($tag_limit + 1);
|
||||
$tags = $query->loadTags();
|
||||
$tags = array();
|
||||
try {
|
||||
$tags = DiffusionRepositoryTag::newFromConduit(
|
||||
$this->callConduitWithDiffusionRequest(
|
||||
'diffusion.tagsquery',
|
||||
array('limit' => $tag_limit + 1)));
|
||||
} catch (ConduitException $e) {
|
||||
if ($e->getMessage() != 'ERR-UNSUPPORTED-VCS') {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$tags) {
|
||||
return null;
|
||||
|
|
|
@ -13,22 +13,27 @@ final class DiffusionTagListController extends DiffusionController {
|
|||
$pager->setURI($request->getRequestURI(), 'offset');
|
||||
$pager->setOffset($request->getInt('offset'));
|
||||
|
||||
$params = array(
|
||||
'limit' => $pager->getPageSize() + 1,
|
||||
'offset' => $pager->getOffset());
|
||||
if ($drequest->getRawCommit()) {
|
||||
$is_commit = true;
|
||||
|
||||
$query = DiffusionCommitTagsQuery::newFromDiffusionRequest($drequest);
|
||||
$query->setOffset($pager->getOffset());
|
||||
$query->setLimit($pager->getPageSize() + 1);
|
||||
$tags = $query->loadTags();
|
||||
$params['commit'] = $request->getCommit();
|
||||
} else {
|
||||
$is_commit = false;
|
||||
|
||||
$query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
|
||||
$query->setOffset($pager->getOffset());
|
||||
$query->setLimit($pager->getPageSize() + 1);
|
||||
$tags = $query->loadTags();
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
try {
|
||||
$conduit_result = $this->callConduitWithDiffusionRequest(
|
||||
'diffusion.tagsquery',
|
||||
$params);
|
||||
$tags = DiffusionRepositoryTag::newFromConduit($conduit_result);
|
||||
} catch (ConduitException $ex) {
|
||||
if ($ex->getMessage() != 'ERR-UNSUPPORTED-VCS') {
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
$tags = $pager->sliceResults($tags);
|
||||
|
||||
$content = null;
|
||||
|
|
|
@ -63,4 +63,28 @@ final class DiffusionRepositoryTag {
|
|||
return $this->author;
|
||||
}
|
||||
|
||||
public function toDictionary() {
|
||||
return array(
|
||||
'author' => $this->getAuthor(),
|
||||
'epoch' => $this->getEpoch(),
|
||||
'commitIdentifier' => $this->getCommitIdentifier(),
|
||||
'name' => $this->getName(),
|
||||
'description' => $this->getDescription(),
|
||||
'type' => $this->getType());
|
||||
}
|
||||
|
||||
public function newFromConduit(array $dicts) {
|
||||
$tags = array();
|
||||
foreach ($dicts as $dict) {
|
||||
$tags[] = id(new DiffusionRepositoryTag())
|
||||
->setAuthor($dict['author'])
|
||||
->setEpoch($dict['epoch'])
|
||||
->setCommitIdentifier($dict['commitIdentifier'])
|
||||
->setName($dict['name'])
|
||||
->setDescription($dict['description'])
|
||||
->setType($dict['type']);
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
abstract class DiffusionCommitTagsQuery extends DiffusionQuery {
|
||||
|
||||
private $limit;
|
||||
private $offset;
|
||||
|
||||
public function setOffset($offset) {
|
||||
$this->offset = $offset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOffset() {
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getLimit() {
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
final public static function newFromDiffusionRequest(
|
||||
DiffusionRequest $request) {
|
||||
return self::newQueryObject(__CLASS__, $request);
|
||||
}
|
||||
|
||||
final public function loadTags() {
|
||||
return $this->executeQuery();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionGitCommitTagsQuery
|
||||
extends DiffusionCommitTagsQuery {
|
||||
|
||||
protected function executeQuery() {
|
||||
$drequest = $this->getRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
list($err, $stdout) = $repository->execLocalCommand(
|
||||
'tag -l --contains %s',
|
||||
$drequest->getCommit());
|
||||
|
||||
if ($err) {
|
||||
// Git exits with an error code if the commit is bogus.
|
||||
return array();
|
||||
}
|
||||
|
||||
$stdout = trim($stdout);
|
||||
if (!strlen($stdout)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$tag_names = explode("\n", $stdout);
|
||||
$tag_names = array_fill_keys($tag_names, true);
|
||||
|
||||
$tag_query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
|
||||
$tags = $tag_query->loadTags();
|
||||
|
||||
$result = array();
|
||||
foreach ($tags as $tag) {
|
||||
if (isset($tag_names[$tag->getName()])) {
|
||||
$result[] = $tag;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getOffset()) {
|
||||
$result = array_slice($result, $this->getOffset());
|
||||
}
|
||||
|
||||
if ($this->getLimit()) {
|
||||
$result = array_slice($result, 0, $this->getLimit());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionMercurialCommitTagsQuery
|
||||
extends DiffusionCommitTagsQuery {
|
||||
|
||||
protected function executeQuery() {
|
||||
// TODO: Implement this.
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionSvnCommitTagsQuery
|
||||
extends DiffusionCommitTagsQuery {
|
||||
|
||||
protected function executeQuery() {
|
||||
// No meaningful concept of tags in Subversion.
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionGitTagListQuery extends DiffusionTagListQuery {
|
||||
|
||||
protected function executeQuery() {
|
||||
$drequest = $this->getRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
$count = $this->getOffset() + $this->getLimit();
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'for-each-ref %C --sort=-creatordate --format=%s refs/tags',
|
||||
$count ? '--count='.(int)$count : null,
|
||||
'%(objectname) %(objecttype) %(refname) %(*objectname) %(*objecttype) '.
|
||||
'%(subject)%01%(creator)');
|
||||
|
||||
$stdout = trim($stdout);
|
||||
if (!strlen($stdout)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
foreach (explode("\n", $stdout) as $line) {
|
||||
list($info, $creator) = explode("\1", $line);
|
||||
list(
|
||||
$objectname,
|
||||
$objecttype,
|
||||
$refname,
|
||||
$refobjectname,
|
||||
$refobjecttype,
|
||||
$description) = explode(' ', $info, 6);
|
||||
|
||||
$matches = null;
|
||||
if (!preg_match('/^(.*) ([0-9]+) ([0-9+-]+)$/', $creator, $matches)) {
|
||||
// It's possible a tag doesn't have a creator (tagger)
|
||||
$author = null;
|
||||
$epoch = null;
|
||||
} else {
|
||||
$author = $matches[1];
|
||||
$epoch = $matches[2];
|
||||
}
|
||||
|
||||
$tag = new DiffusionRepositoryTag();
|
||||
$tag->setAuthor($author);
|
||||
$tag->setEpoch($epoch);
|
||||
$tag->setCommitIdentifier(nonempty($refobjectname, $objectname));
|
||||
$tag->setName(preg_replace('@^refs/tags/@', '', $refname));
|
||||
$tag->setDescription($description);
|
||||
$tag->setType('git/'.$objecttype);
|
||||
|
||||
$tags[] = $tag;
|
||||
}
|
||||
|
||||
$offset = $this->getOffset();
|
||||
if ($offset) {
|
||||
$tags = array_slice($tags, $offset);
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionMercurialTagListQuery extends DiffusionTagListQuery {
|
||||
|
||||
protected function executeQuery() {
|
||||
// TODO: Implement this for Mercurial.
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionSvnTagListQuery extends DiffusionTagListQuery {
|
||||
|
||||
protected function executeQuery() {
|
||||
// Nothing meaningful to be done in Subversion.
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
abstract class DiffusionTagListQuery extends DiffusionQuery {
|
||||
|
||||
private $limit;
|
||||
private $offset;
|
||||
|
||||
public function setOffset($offset) {
|
||||
$this->offset = $offset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOffset() {
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getLimit() {
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
final public static function newFromDiffusionRequest(
|
||||
DiffusionRequest $request) {
|
||||
return self::newQueryObject(__CLASS__, $request);
|
||||
}
|
||||
|
||||
final public function loadTags() {
|
||||
return $this->executeQuery();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue