Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2893094
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
17 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/diffusion/controller/branchtable/DiffusionBranchTableController.php b/src/applications/diffusion/controller/branchtable/DiffusionBranchTableController.php
index be9a135dca..ee83f57e92 100644
--- a/src/applications/diffusion/controller/branchtable/DiffusionBranchTableController.php
+++ b/src/applications/diffusion/controller/branchtable/DiffusionBranchTableController.php
@@ -1,85 +1,84 @@
<?php
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DiffusionBranchTableController extends DiffusionController {
public function processRequest() {
$drequest = $this->getDiffusionRequest();
$request = $this->getRequest();
$user = $request->getUser();
$repository = $drequest->getRepository();
$pager = new AphrontPagerView();
$pager->setURI($request->getRequestURI(), 'offset');
$pager->setOffset($request->getInt('offset'));
// 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);
$content = null;
if (!$branches) {
$content = new AphrontErrorView();
$content->setTitle('No Branches');
$content->appendChild('This repository has no branches.');
$content->setSeverity(AphrontErrorView::SEVERITY_NODATA);
} else {
$commits = id(new PhabricatorAuditCommitQuery())
->withIdentifiers(
$drequest->getRepository()->getID(),
mpull($branches, 'getHeadCommitIdentifier'))
->needCommitData(true)
->execute();
$view = id(new DiffusionBranchTableView())
->setBranches($branches)
->setUser($user)
->setCommits($commits)
->setDiffusionRequest($drequest);
$panel = id(new AphrontPanelView())
->setHeader('Branches')
->appendChild($view)
->appendChild($pager);
$content = $panel;
}
return $this->buildStandardPageResponse(
array(
$this->buildCrumbs(
array(
'branches' => true,
)),
$content,
),
array(
'title' => array(
'Branches',
$repository->getCallsign().' Repository',
),
));
}
}
diff --git a/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php b/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php
index d75ab134e0..462e1f589f 100644
--- a/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php
+++ b/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php
@@ -1,262 +1,261 @@
<?php
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DiffusionRepositoryController extends DiffusionController {
public function processRequest() {
$drequest = $this->diffusionRequest;
$content = array();
$crumbs = $this->buildCrumbs();
$content[] = $crumbs;
$content[] = $this->buildPropertiesTable($drequest->getRepository());
$history_query = DiffusionHistoryQuery::newFromDiffusionRequest(
$drequest);
$history_query->setLimit(15);
$history_query->needParents(true);
$history = $history_query->loadHistory();
$browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
$browse_results = $browse_query->loadPaths();
$phids = array();
foreach ($history as $item) {
$data = $item->getCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
}
foreach ($browse_results as $item) {
$data = $item->getLastCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
}
$phids = array_keys($phids);
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
$history_table = new DiffusionHistoryTableView();
$history_table->setDiffusionRequest($drequest);
$history_table->setHandles($handles);
$history_table->setHistory($history);
$history_table->setParents($history_query->getParents());
$history_table->setIsHead(true);
$callsign = $drequest->getRepository()->getCallsign();
$all = phutil_render_tag(
'a',
array(
'href' => "/diffusion/{$callsign}/history/",
),
'View Full Commit History');
$panel = new AphrontPanelView();
$panel->setHeader("Recent Commits · {$all}");
$panel->appendChild($history_table);
$content[] = $panel;
$browse_table = new DiffusionBrowseTableView();
$browse_table->setDiffusionRequest($drequest);
$browse_table->setHandles($handles);
$browse_table->setPaths($browse_results);
$browse_panel = new AphrontPanelView();
$browse_panel->setHeader('Browse Repository');
$browse_panel->appendChild($browse_table);
$content[] = $browse_panel;
$content[] = $this->buildTagListTable($drequest);
$content[] = $this->buildBranchListTable($drequest);
$readme = $browse_query->renderReadme($browse_results);
if ($readme) {
$panel = new AphrontPanelView();
$panel->setHeader('README');
$panel->appendChild($readme);
$content[] = $panel;
}
return $this->buildStandardPageResponse(
$content,
array(
'title' => $drequest->getRepository()->getName(),
));
}
private function buildPropertiesTable(PhabricatorRepository $repository) {
$properties = array();
$properties['Name'] = $repository->getName();
$properties['Callsign'] = $repository->getCallsign();
$properties['Description'] = $repository->getDetail('description');
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$properties['Clone URI'] = $repository->getPublicRemoteURI();
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$properties['Repository Root'] = $repository->getPublicRemoteURI();
break;
}
$rows = array();
foreach ($properties as $key => $value) {
$rows[] = array(
phutil_escape_html($key),
phutil_escape_html($value));
}
$table = new AphrontTableView($rows);
$table->setColumnClasses(
array(
'header',
'wide',
));
$panel = new AphrontPanelView();
$panel->setHeader('Repository Properties');
$panel->appendChild($table);
return $panel;
}
private function buildBranchListTable(DiffusionRequest $drequest) {
if ($drequest->getBranch() !== null) {
$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) {
return null;
}
$more_branches = (count($branches) > $limit);
$branches = array_slice($branches, 0, $limit);
$commits = id(new PhabricatorAuditCommitQuery())
->withIdentifiers(
$drequest->getRepository()->getID(),
mpull($branches, 'getHeadCommitIdentifier'))
->needCommitData(true)
->execute();
$table = new DiffusionBranchTableView();
$table->setDiffusionRequest($drequest);
$table->setBranches($branches);
$table->setCommits($commits);
$table->setUser($this->getRequest()->getUser());
$panel = new AphrontPanelView();
$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);
return $panel;
}
return null;
}
private function buildTagListTable(DiffusionRequest $drequest) {
$tag_limit = 15;
$query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
$query->setLimit($tag_limit + 1);
$tags = $query->loadTags();
if (!$tags) {
return null;
}
$more_tags = (count($tags) > $tag_limit);
$tags = array_slice($tags, 0, $tag_limit);
$commits = id(new PhabricatorAuditCommitQuery())
->withIdentifiers(
$drequest->getRepository()->getID(),
mpull($tags, 'getCommitIdentifier'))
->needCommitData(true)
->execute();
$view = new DiffusionTagListView();
$view->setDiffusionRequest($drequest);
$view->setTags($tags);
$view->setUser($this->getRequest()->getUser());
$view->setCommits($commits);
$phids = $view->getRequiredHandlePHIDs();
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
$view->setHandles($handles);
$panel = new AphrontPanelView();
$panel->setHeader('Tags');
if ($more_tags) {
$panel->setCaption('Showing the '.$tag_limit.' most recent tags.');
}
$panel->addButton(
phutil_render_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'tags',
)),
'class' => 'grey button',
),
"Show All Tags \xC2\xBB"));
$panel->appendChild($view);
return $panel;
}
}
diff --git a/src/applications/diffusion/query/branch/git/DiffusionGitBranchQuery.php b/src/applications/diffusion/query/branch/git/DiffusionGitBranchQuery.php
index 34fb8f9e64..4be88bb28b 100644
--- a/src/applications/diffusion/query/branch/git/DiffusionGitBranchQuery.php
+++ b/src/applications/diffusion/query/branch/git/DiffusionGitBranchQuery.php
@@ -1,126 +1,136 @@
<?php
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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',
$count ? '--count='.(int)$count : null,
'%(refname:short) %(objectname)'
);
$branch_list = self::parseGitRemoteBranchOutput(
$stdout,
$only_this_remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE);
$branches = array();
foreach ($branch_list as $name => $head) {
if (!$repository->shouldTrackBranch($name)) {
continue;
}
$branch = new DiffusionBranchInformation();
$branch->setName($name);
$branch->setHeadCommitIdentifier($head);
$branches[] = $branch;
}
$offset = $this->getOffset();
if ($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;
}
/**
* Parse the output of 'git branch -r --verbose --no-abbrev' or similar into
* a map. For instance:
*
* array(
* 'origin/master' => '99a9c082f9a1b68c7264e26b9e552484a5ae5f25',
* );
*
* If you specify $only_this_remote, branches will be filtered to only those
* on the given remote, **and the remote name will be stripped**. For example:
*
* array(
* 'master' => '99a9c082f9a1b68c7264e26b9e552484a5ae5f25',
* );
*
* @param string stdout of git branch command.
* @param string Filter branches to those on a specific remote.
* @return map Map of 'branch' or 'remote/branch' to hash at HEAD.
*/
public static function parseGitRemoteBranchOutput(
$stdout,
$only_this_remote = null) {
$map = array();
$lines = array_filter(explode("\n", $stdout));
foreach ($lines as $line) {
$matches = null;
if (preg_match('/^ (\S+)\s+-> (\S+)$/', $line, $matches)) {
// This is a line like:
//
// origin/HEAD -> origin/master
//
// ...which we don't currently do anything interesting with, although
// in theory we could use it to automatically choose the default
// branch.
continue;
}
if (!preg_match('/^ *(\S+)\s+([a-z0-9]{40})/', $line, $matches)) {
throw new Exception("Failed to parse {$line}!");
}
$remote_branch = $matches[1];
$branch_head = $matches[2];
if (strpos($remote_branch, 'HEAD') !== false) {
// let's assume that no one will call their remote or branch HEAD
continue;
}
if ($only_this_remote) {
$matches = null;
if (!preg_match('#^([^/]+)/(.*)$#', $remote_branch, $matches)) {
throw new Exception(
"Failed to parse remote branch '{$remote_branch}'!");
}
$remote_name = $matches[1];
$branch_name = $matches[2];
if ($remote_name != $only_this_remote) {
continue;
}
$map[$branch_name] = $branch_head;
} else {
$map[$remote_branch] = $branch_head;
}
}
return $map;
}
}
diff --git a/src/applications/diffusion/query/branch/mercurial/DiffusionMercurialBranchQuery.php b/src/applications/diffusion/query/branch/mercurial/DiffusionMercurialBranchQuery.php
index 1e058e8b56..750c6a3e2a 100644
--- a/src/applications/diffusion/query/branch/mercurial/DiffusionMercurialBranchQuery.php
+++ b/src/applications/diffusion/query/branch/mercurial/DiffusionMercurialBranchQuery.php
@@ -1,40 +1,48 @@
<?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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DiffusionMercurialBranchQuery extends DiffusionBranchQuery {
protected function executeQuery() {
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
list($stdout) = $repository->execxLocalCommand(
- 'branches');
+ '--debug branches');
$branch_info = ArcanistMercurialParser::parseMercurialBranches($stdout);
$branches = array();
foreach ($branch_info as $name => $info) {
$branch = new DiffusionBranchInformation();
$branch->setName($name);
$branch->setHeadCommitIdentifier($info['rev']);
$branches[] = $branch;
}
+ if ($this->getOffset()) {
+ $branches = array_slice($branches, $this->getOffset());
+ }
+
+ if ($this->getLimit()) {
+ $branches = array_slice($branches, 0, $this->getLimit());
+ }
+
return $branches;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 17:50 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1127143
Default Alt Text
(17 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment