1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00

Remove DiffusionBranchInformation in favor of DiffusionRepositoryRef

Summary: Ref T4327. At some point these two very similar classes got introduced. Collapse `DiffusionBranchInformation` into the nearly identical `DiffusionRepositoryRef`, which enjoys slightly more generality and support.

Test Plan: Viewed branch overview and detail pages. Ran `repository refs` and `repository discover`. Grepped for removed symbols.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4327

Differential Revision: https://secure.phabricator.com/D8002
This commit is contained in:
epriestley 2014-01-17 16:10:56 -08:00
parent a9c16fbe4e
commit 4c2696120b
12 changed files with 96 additions and 123 deletions

View file

@ -467,7 +467,6 @@ phutil_register_library_map(array(
'DifferentialUnitStatus' => 'applications/differential/constants/DifferentialUnitStatus.php',
'DifferentialUnitTestResult' => 'applications/differential/constants/DifferentialUnitTestResult.php',
'DifferentialViewPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialViewPolicyFieldSpecification.php',
'DiffusionBranchInformation' => 'applications/diffusion/data/DiffusionBranchInformation.php',
'DiffusionBranchTableController' => 'applications/diffusion/controller/DiffusionBranchTableController.php',
'DiffusionBranchTableView' => 'applications/diffusion/view/DiffusionBranchTableView.php',
'DiffusionBrowseController' => 'applications/diffusion/controller/DiffusionBrowseController.php',
@ -3014,6 +3013,7 @@ phutil_register_library_map(array(
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'DiffusionRepositoryNewController' => 'DiffusionController',
'DiffusionRepositoryRef' => 'Phobject',
'DiffusionRepositoryRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'DiffusionResolveUserQuery' => 'Phobject',
'DiffusionSSHGitReceivePackWorkflow' => 'DiffusionSSHGitWorkflow',

View file

@ -21,62 +21,53 @@ final class ConduitAPI_diffusion_branchquery_Method
);
}
protected function getGitResult(ConduitAPIRequest $request) {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$limit = $request->getValue('limit');
$offset = $request->getValue('offset');
$refs = id(new DiffusionLowLevelGitRefQuery())
->setRepository($repository)
->withIsOriginBranch(true)
->execute();
$branches = array();
foreach ($refs as $ref) {
$branch = id(new DiffusionBranchInformation())
->setName($ref->getShortName())
->setHeadCommitIdentifier($ref->getCommitIdentifier());
return $this->processBranchRefs($request, $refs);
}
if (!$repository->shouldTrackBranch($branch->getName())) {
continue;
protected function getMercurialResult(ConduitAPIRequest $request) {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$refs = id(new DiffusionLowLevelMercurialBranchesQuery())
->setRepository($repository)
->execute();
return $this->processBranchRefs($request, $refs);
}
private function processBranchRefs(ConduitAPIRequest $request, array $refs) {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$offset = $request->getValue('offset');
$limit = $request->getValue('limit');
foreach ($refs as $key => $ref) {
if (!$repository->shouldTrackBranch($ref->getShortName())) {
unset($refs[$key]);
}
$branches[] = $branch->toDictionary();
}
// NOTE: We can't apply the offset or limit until here, because we may have
// filtered untrackable branches out of the result set.
if ($offset) {
$branches = array_slice($branches, $offset);
$refs = array_slice($refs, $offset);
}
if ($limit) {
$branches = array_slice($branches, 0, $limit);
$refs = array_slice($refs, 0, $limit);
}
return $branches;
}
protected function getMercurialResult(ConduitAPIRequest $request) {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$offset = $request->getValue('offset');
$limit = $request->getValue('limit');
$branches = id(new DiffusionLowLevelMercurialBranchesQuery())
->setRepository($repository)
->execute();
if ($offset) {
$branches = array_slice($branches, $offset);
}
if ($limit) {
$branches = array_slice($branches, 0, $limit);
}
return mpull($branches, 'toDictionary');
return mpull($refs, 'toDictionary');
}
}

View file

@ -39,7 +39,7 @@ final class ConduitAPI_diffusion_commitbranchesquery_Method
$commit);
return DiffusionGitBranch::parseRemoteBranchOutput(
$contains,
DiffusionBranchInformation::DEFAULT_GIT_REMOTE);
DiffusionGitBranch::DEFAULT_GIT_REMOTE);
}
}
@ -48,7 +48,10 @@ final class ConduitAPI_diffusion_commitbranchesquery_Method
$repository = $drequest->getRepository();
$commit = $request->getValue('commit');
// TODO: This should use `branches`.
// TODO: This should use `branches`. Also, this entire method's API needs
// to be fixed to support multiple branch heads in Mercurial. We should
// probably return `DiffusionRepositoryRefs` and probably merge this into
// `diffusion.branchesquery`.
list($contains) = $repository->execxLocalCommand(
'log --template %s --limit 1 --rev %s --',

View file

@ -18,15 +18,16 @@ final class DiffusionBranchTableController extends DiffusionController {
$pager->setOffset($request->getInt('offset'));
// TODO: Add support for branches that contain commit
$branches = DiffusionBranchInformation::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.branchquery',
array(
'offset' => $pager->getOffset(),
'limit' => $pager->getPageSize() + 1
)));
$branches = $this->callConduitWithDiffusionRequest(
'diffusion.branchquery',
array(
'offset' => $pager->getOffset(),
'limit' => $pager->getPageSize() + 1
));
$branches = $pager->sliceResults($branches);
$branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches);
$content = null;
if (!$branches) {
$content = $this->renderStatusMessage(
@ -35,7 +36,7 @@ final class DiffusionBranchTableController extends DiffusionController {
} else {
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIdentifiers(mpull($branches, 'getHeadCommitIdentifier'))
->withIdentifiers(mpull($branches, 'getCommitIdentifier'))
->withRepository($repository)
->execute();

View file

@ -261,12 +261,11 @@ final class DiffusionRepositoryController extends DiffusionController {
$limit = 15;
$branches = DiffusionBranchInformation::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.branchquery',
array(
'limit' => $limit + 1,
)));
$branches = $this->callConduitWithDiffusionRequest(
'diffusion.branchquery',
array(
'limit' => $limit + 1,
));
if (!$branches) {
return null;
}
@ -274,9 +273,11 @@ final class DiffusionRepositoryController extends DiffusionController {
$more_branches = (count($branches) > $limit);
$branches = array_slice($branches, 0, $limit);
$branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches);
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIdentifiers(mpull($branches, 'getHeadCommitIdentifier'))
->withIdentifiers(mpull($branches, 'getCommitIdentifier'))
->withRepository($drequest->getRepository())
->execute();

View file

@ -1,56 +0,0 @@
<?php
final class DiffusionBranchInformation {
const DEFAULT_GIT_REMOTE = 'origin';
private $name;
private $headCommitIdentifier;
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setHeadCommitIdentifier($head_commit_identifier) {
$this->headCommitIdentifier = $head_commit_identifier;
return $this;
}
public function getHeadCommitIdentifier() {
return $this->headCommitIdentifier;
}
public static function newFromConduit(array $dicts) {
$branches = array();
foreach ($dicts as $dict) {
$branches[] = id(new DiffusionBranchInformation())
->setName($dict['name'])
->setHeadCommitIdentifier($dict['headCommitIdentifier']);
}
return $branches;
}
public function toDictionary() {
return array(
'name' => $this->getName(),
'headCommitIdentifier' => $this->getHeadCommitIdentifier()
);
}
// TODO: These are hacks to make this compatible with DiffusionRepositoryRef
// for PhabricatorRepositoryRefEngine. The two classes should be merged.
public function getShortName() {
return $this->getName();
}
public function getCommitIdentifier() {
return $this->getHeadCommitIdentifier();
}
}

View file

@ -2,6 +2,8 @@
final class DiffusionGitBranch {
const DEFAULT_GIT_REMOTE = 'origin';
/**
* Parse the output of 'git branch -r --verbose --no-abbrev' or similar into
* a map. For instance:

View file

@ -1,10 +1,13 @@
<?php
final class DiffusionRepositoryRef {
/**
* @task serialization Serializing Repository Refs
*/
final class DiffusionRepositoryRef extends Phobject {
private $shortName;
private $commitIdentifier;
private $rawFields;
private $rawFields = array();
public function setRawFields(array $raw_fields) {
$this->rawFields = $raw_fields;
@ -33,4 +36,31 @@ final class DiffusionRepositoryRef {
return $this->shortName;
}
/* -( Serialization )------------------------------------------------------ */
public function toDictionary() {
return array(
'shortName' => $this->shortName,
'commitIdentifier' => $this->commitIdentifier,
'rawFields' => $this->rawFields,
);
}
public static function newFromDictionary(array $dict) {
return id(new DiffusionRepositoryRef())
->setShortName($dict['shortName'])
->setCommitIdentifier($dict['commitIdentifier'])
->setRawFields($dict['rawFields']);
}
public static function loadAllFromDictionaries(array $dictionaries) {
$refs = array();
foreach ($dictionaries as $dictionary) {
$refs[] = self::newFromDictionary($dictionary);
}
return $refs;
}
}

View file

@ -32,7 +32,7 @@ final class DiffusionLowLevelGitRefQuery extends DiffusionLowLevelQuery {
if ($repository->isWorkingCopyBare()) {
$prefix = 'refs/heads/';
} else {
$remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE;
$remote = DiffusionGitBranch::DEFAULT_GIT_REMOTE;
$prefix = 'refs/remotes/'.$remote.'/';
}
} else {

View file

@ -18,9 +18,9 @@ final class DiffusionLowLevelMercurialBranchesQuery
$lines = ArcanistMercurialParser::parseMercurialBranches($stdout);
foreach ($lines as $name => $spec) {
$branches[] = id(new DiffusionBranchInformation())
->setName($name)
->setHeadCommitIdentifier($spec['rev']);
$branches[] = id(new DiffusionRepositoryRef())
->setShortName($name)
->setCommitIdentifier($spec['rev']);
}
return $branches;

View file

@ -39,7 +39,7 @@ final class DiffusionGitRequest extends DiffusionRequest {
if ($this->repository->isWorkingCopyBare()) {
return $branch;
} else {
$remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE;
$remote = DiffusionGitBranch::DEFAULT_GIT_REMOTE;
return $remote.'/'.$branch;
}
}

View file

@ -6,12 +6,13 @@ final class DiffusionBranchTableView extends DiffusionView {
private $commits = array();
public function setBranches(array $branches) {
assert_instances_of($branches, 'DiffusionBranchInformation');
assert_instances_of($branches, 'DiffusionRepositoryRef');
$this->branches = $branches;
return $this;
}
public function setCommits(array $commits) {
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
$this->commits = mpull($commits, null, 'getCommitIdentifier');
return $this;
}
@ -23,7 +24,7 @@ final class DiffusionBranchTableView extends DiffusionView {
$rows = array();
$rowc = array();
foreach ($this->branches as $branch) {
$commit = idx($this->commits, $branch->getHeadCommitIdentifier());
$commit = idx($this->commits, $branch->getCommitIdentifier());
if ($commit) {
$details = $commit->getSummary();
$datetime = phabricator_datetime($commit->getEpoch(), $this->user);
@ -39,7 +40,7 @@ final class DiffusionBranchTableView extends DiffusionView {
'href' => $drequest->generateURI(
array(
'action' => 'history',
'branch' => $branch->getName(),
'branch' => $branch->getShortName(),
))
),
pht('History')),
@ -49,17 +50,17 @@ final class DiffusionBranchTableView extends DiffusionView {
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'branch' => $branch->getName(),
'branch' => $branch->getShortName(),
)),
),
$branch->getName()),
$branch->getShortName()),
self::linkCommit(
$drequest->getRepository(),
$branch->getHeadCommitIdentifier()),
$branch->getCommitIdentifier()),
$datetime,
AphrontTableView::renderSingleDisplayLine($details),
);
if ($branch->getName() == $current_branch) {
if ($branch->getShortName() == $current_branch) {
$rowc[] = 'highlighted';
} else {
$rowc[] = null;