Support branch offset/limit in Mercurial
Summary: - Support offset/limit as added by D2442, for Mercurial. - We just list everything and slice, no clear way to do better and this isn't a major perf issue. - No clear way to easily get by-update sorting, we can implement this by looking up revs if someone asks. - Bury some of the Git implementation details inside the Git query. Test Plan: - Looked at a Git repo, clicked "View All Branches". - Looked at a Hg repo, clicked "View All Branches". - Limited page size to 1, made sure it limited properly. Reviewers: aurelijus, btrahan, vrana Reviewed By: aurelijus CC: aran Differential Revision: https://secure.phabricator.com/D2453
This commit is contained in:
parent
70e5ef92cf
commit
d24c81c5e2
|
@ -32,8 +32,7 @@ final class DiffusionBranchTableController extends DiffusionController {
|
||||||
// TODO: Add support for branches that contain commit
|
// TODO: Add support for branches that contain commit
|
||||||
$query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
$query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
||||||
$query->setOffset($pager->getOffset());
|
$query->setOffset($pager->getOffset());
|
||||||
// we add 2 here, because of removed HEAD branch
|
$query->setLimit($pager->getPageSize() + 1);
|
||||||
$query->setLimit($pager->getPageSize() + 2);
|
|
||||||
$branches = $query->loadBranches();
|
$branches = $query->loadBranches();
|
||||||
|
|
||||||
$branches = $pager->sliceResults($branches);
|
$branches = $pager->sliceResults($branches);
|
||||||
|
|
|
@ -154,8 +154,7 @@ final class DiffusionRepositoryController extends DiffusionController {
|
||||||
$limit = 15;
|
$limit = 15;
|
||||||
|
|
||||||
$branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
$branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
||||||
// we add 2 here, because of removed HEAD branch
|
$branch_query->setLimit($limit + 1);
|
||||||
$branch_query->setLimit($limit + 2);
|
|
||||||
$branches = $branch_query->loadBranches();
|
$branches = $branch_query->loadBranches();
|
||||||
|
|
||||||
if (!$branches) {
|
if (!$branches) {
|
||||||
|
@ -182,20 +181,20 @@ final class DiffusionRepositoryController extends DiffusionController {
|
||||||
$panel->setHeader('Branches');
|
$panel->setHeader('Branches');
|
||||||
|
|
||||||
if ($more_branches) {
|
if ($more_branches) {
|
||||||
$panel->setCaption('Showing the ' . $limit . ' most recent branches.');
|
$panel->setCaption('Showing ' . $limit . ' branches.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$panel->addButton(
|
$panel->addButton(
|
||||||
phutil_render_tag(
|
phutil_render_tag(
|
||||||
'a',
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => $drequest->generateURI(
|
||||||
array(
|
array(
|
||||||
'href' => $drequest->generateURI(
|
'action' => 'branches',
|
||||||
array(
|
)),
|
||||||
'action' => 'branches',
|
'class' => 'grey button',
|
||||||
)),
|
),
|
||||||
'class' => 'grey button',
|
"Show All Branches \xC2\xBB"));
|
||||||
),
|
|
||||||
"Show All Branches \xC2\xBB"));
|
|
||||||
|
|
||||||
$panel->appendChild($table);
|
$panel->appendChild($table);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,10 @@ final class DiffusionGitBranchQuery extends DiffusionBranchQuery {
|
||||||
protected function executeQuery() {
|
protected function executeQuery() {
|
||||||
$drequest = $this->getRequest();
|
$drequest = $this->getRequest();
|
||||||
$repository = $drequest->getRepository();
|
$repository = $drequest->getRepository();
|
||||||
$count = $this->getOffset() + $this->getLimit();
|
|
||||||
|
// We need to add 1 in case we pick up HEAD.
|
||||||
|
|
||||||
|
$count = $this->getOffset() + $this->getLimit() + 1;
|
||||||
|
|
||||||
list($stdout) = $repository->execxLocalCommand(
|
list($stdout) = $repository->execxLocalCommand(
|
||||||
'for-each-ref %C --sort=-creatordate --format=%s refs/remotes',
|
'for-each-ref %C --sort=-creatordate --format=%s refs/remotes',
|
||||||
|
@ -50,6 +53,13 @@ final class DiffusionGitBranchQuery extends DiffusionBranchQuery {
|
||||||
$branches = array_slice($branches, $offset);
|
$branches = array_slice($branches, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We might have too many even after offset slicing, if there was no HEAD
|
||||||
|
// for some reason.
|
||||||
|
$limit = $this->getLimit();
|
||||||
|
if ($limit) {
|
||||||
|
$branches = array_slice($branches, 0, $limit);
|
||||||
|
}
|
||||||
|
|
||||||
return $branches;
|
return $branches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Facebook, Inc.
|
* Copyright 2012 Facebook, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,7 +23,7 @@ final class DiffusionMercurialBranchQuery extends DiffusionBranchQuery {
|
||||||
$repository = $drequest->getRepository();
|
$repository = $drequest->getRepository();
|
||||||
|
|
||||||
list($stdout) = $repository->execxLocalCommand(
|
list($stdout) = $repository->execxLocalCommand(
|
||||||
'branches');
|
'--debug branches');
|
||||||
$branch_info = ArcanistMercurialParser::parseMercurialBranches($stdout);
|
$branch_info = ArcanistMercurialParser::parseMercurialBranches($stdout);
|
||||||
|
|
||||||
$branches = array();
|
$branches = array();
|
||||||
|
@ -34,6 +34,14 @@ final class DiffusionMercurialBranchQuery extends DiffusionBranchQuery {
|
||||||
$branches[] = $branch;
|
$branches[] = $branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->getOffset()) {
|
||||||
|
$branches = array_slice($branches, $this->getOffset());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getLimit()) {
|
||||||
|
$branches = array_slice($branches, 0, $this->getLimit());
|
||||||
|
}
|
||||||
|
|
||||||
return $branches;
|
return $branches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue