mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
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
4 changed files with 33 additions and 17 deletions
|
@ -32,8 +32,7 @@ final class DiffusionBranchTableController extends DiffusionController {
|
|||
// TODO: Add support for branches that contain commit
|
||||
$query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
||||
$query->setOffset($pager->getOffset());
|
||||
// we add 2 here, because of removed HEAD branch
|
||||
$query->setLimit($pager->getPageSize() + 2);
|
||||
$query->setLimit($pager->getPageSize() + 1);
|
||||
$branches = $query->loadBranches();
|
||||
|
||||
$branches = $pager->sliceResults($branches);
|
||||
|
|
|
@ -154,8 +154,7 @@ final class DiffusionRepositoryController extends DiffusionController {
|
|||
$limit = 15;
|
||||
|
||||
$branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
||||
// we add 2 here, because of removed HEAD branch
|
||||
$branch_query->setLimit($limit + 2);
|
||||
$branch_query->setLimit($limit + 1);
|
||||
$branches = $branch_query->loadBranches();
|
||||
|
||||
if (!$branches) {
|
||||
|
@ -182,20 +181,20 @@ final class DiffusionRepositoryController extends DiffusionController {
|
|||
$panel->setHeader('Branches');
|
||||
|
||||
if ($more_branches) {
|
||||
$panel->setCaption('Showing the ' . $limit . ' most recent branches.');
|
||||
$panel->setCaption('Showing ' . $limit . ' branches.');
|
||||
}
|
||||
|
||||
$panel->addButton(
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $drequest->generateURI(
|
||||
array(
|
||||
'href' => $drequest->generateURI(
|
||||
array(
|
||||
'action' => 'branches',
|
||||
)),
|
||||
'class' => 'grey button',
|
||||
),
|
||||
"Show All Branches \xC2\xBB"));
|
||||
'action' => 'branches',
|
||||
)),
|
||||
'class' => 'grey button',
|
||||
),
|
||||
"Show All Branches \xC2\xBB"));
|
||||
|
||||
$panel->appendChild($table);
|
||||
|
||||
|
|
|
@ -21,7 +21,10 @@ final class DiffusionGitBranchQuery extends DiffusionBranchQuery {
|
|||
protected function executeQuery() {
|
||||
$drequest = $this->getRequest();
|
||||
$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(
|
||||
'for-each-ref %C --sort=-creatordate --format=%s refs/remotes',
|
||||
|
@ -50,6 +53,13 @@ final class DiffusionGitBranchQuery extends DiffusionBranchQuery {
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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();
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'branches');
|
||||
'--debug branches');
|
||||
$branch_info = ArcanistMercurialParser::parseMercurialBranches($stdout);
|
||||
|
||||
$branches = array();
|
||||
|
@ -34,6 +34,14 @@ final class DiffusionMercurialBranchQuery extends DiffusionBranchQuery {
|
|||
$branches[] = $branch;
|
||||
}
|
||||
|
||||
if ($this->getOffset()) {
|
||||
$branches = array_slice($branches, $this->getOffset());
|
||||
}
|
||||
|
||||
if ($this->getLimit()) {
|
||||
$branches = array_slice($branches, 0, $this->getLimit());
|
||||
}
|
||||
|
||||
return $branches;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue