Skip to content

Commit d24c81c

Browse files
author
epriestley
committed
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
1 parent 70e5ef9 commit d24c81c

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

src/applications/diffusion/controller/branchtable/DiffusionBranchTableController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public function processRequest() {
3232
// TODO: Add support for branches that contain commit
3333
$query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
3434
$query->setOffset($pager->getOffset());
35-
// we add 2 here, because of removed HEAD branch
36-
$query->setLimit($pager->getPageSize() + 2);
35+
$query->setLimit($pager->getPageSize() + 1);
3736
$branches = $query->loadBranches();
3837

3938
$branches = $pager->sliceResults($branches);

src/applications/diffusion/controller/repository/DiffusionRepositoryController.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ private function buildBranchListTable(DiffusionRequest $drequest) {
154154
$limit = 15;
155155

156156
$branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
157-
// we add 2 here, because of removed HEAD branch
158-
$branch_query->setLimit($limit + 2);
157+
$branch_query->setLimit($limit + 1);
159158
$branches = $branch_query->loadBranches();
160159

161160
if (!$branches) {
@@ -182,20 +181,20 @@ private function buildBranchListTable(DiffusionRequest $drequest) {
182181
$panel->setHeader('Branches');
183182

184183
if ($more_branches) {
185-
$panel->setCaption('Showing the ' . $limit . ' most recent branches.');
184+
$panel->setCaption('Showing ' . $limit . ' branches.');
186185
}
187186

188187
$panel->addButton(
189-
phutil_render_tag(
190-
'a',
188+
phutil_render_tag(
189+
'a',
190+
array(
191+
'href' => $drequest->generateURI(
191192
array(
192-
'href' => $drequest->generateURI(
193-
array(
194-
'action' => 'branches',
195-
)),
196-
'class' => 'grey button',
197-
),
198-
"Show All Branches \xC2\xBB"));
193+
'action' => 'branches',
194+
)),
195+
'class' => 'grey button',
196+
),
197+
"Show All Branches \xC2\xBB"));
199198

200199
$panel->appendChild($table);
201200

src/applications/diffusion/query/branch/git/DiffusionGitBranchQuery.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ final class DiffusionGitBranchQuery extends DiffusionBranchQuery {
2121
protected function executeQuery() {
2222
$drequest = $this->getRequest();
2323
$repository = $drequest->getRepository();
24-
$count = $this->getOffset() + $this->getLimit();
24+
25+
// We need to add 1 in case we pick up HEAD.
26+
27+
$count = $this->getOffset() + $this->getLimit() + 1;
2528

2629
list($stdout) = $repository->execxLocalCommand(
2730
'for-each-ref %C --sort=-creatordate --format=%s refs/remotes',
@@ -50,6 +53,13 @@ protected function executeQuery() {
5053
$branches = array_slice($branches, $offset);
5154
}
5255

56+
// We might have too many even after offset slicing, if there was no HEAD
57+
// for some reason.
58+
$limit = $this->getLimit();
59+
if ($limit) {
60+
$branches = array_slice($branches, 0, $limit);
61+
}
62+
5363
return $branches;
5464
}
5565

src/applications/diffusion/query/branch/mercurial/DiffusionMercurialBranchQuery.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
* Copyright 2011 Facebook, Inc.
4+
* Copyright 2012 Facebook, Inc.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ protected function executeQuery() {
2323
$repository = $drequest->getRepository();
2424

2525
list($stdout) = $repository->execxLocalCommand(
26-
'branches');
26+
'--debug branches');
2727
$branch_info = ArcanistMercurialParser::parseMercurialBranches($stdout);
2828

2929
$branches = array();
@@ -34,6 +34,14 @@ protected function executeQuery() {
3434
$branches[] = $branch;
3535
}
3636

37+
if ($this->getOffset()) {
38+
$branches = array_slice($branches, $this->getOffset());
39+
}
40+
41+
if ($this->getLimit()) {
42+
$branches = array_slice($branches, 0, $this->getLimit());
43+
}
44+
3745
return $branches;
3846
}
3947

0 commit comments

Comments
 (0)