1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-14 02:42:40 +01:00
phorge-arcanist/src/loader/ArcanistGitRevisionHardpointLoader.php
epriestley 84857e4890 Implement a revision resolver for arc browse <commit>
Summary: Ref T10895. This allows `arc browse <commit name>` to resolve to a revision, if an associated open revision exists.

Test Plan: Ran `arc browse` with various arguments.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10895

Differential Revision: https://secure.phabricator.com/D16933
2016-11-23 13:27:26 -08:00

82 lines
1.9 KiB
PHP

<?php
final class ArcanistGitRevisionHardpointLoader
extends ArcanistGitHardpointLoader {
const LOADERKEY = 'git.revision';
public function canLoadRef(ArcanistRef $ref) {
return ($ref instanceof ArcanistWorkingCopyStateRef);
}
public function canLoadHardpoint(ArcanistRef $ref, $hardpoint) {
return ($hardpoint == 'revisionRefs');
}
public function loadHardpoints(array $refs, $hardpoint) {
$this->newQuery($refs)
->needHardpoints(
array(
'commitRef',
))
->execute();
$hashes = array();
$map = array();
foreach ($refs as $ref_key => $ref) {
$commit = $ref->getCommitRef();
$commit_hashes = array();
$commit_hashes[] = array(
'gtcm',
$commit->getCommitHash(),
);
if ($commit->getTreeHash()) {
$commit_hashes[] = array(
'gttr',
$commit->getTreeHash(),
);
}
foreach ($commit_hashes as $hash) {
$hashes[] = $hash;
$hash_key = $this->getHashKey($hash);
$map[$hash_key][$ref_key] = $ref;
}
}
$results = array();
if ($hashes) {
$revisions = $this->resolveCall(
'differential.query',
array(
'commitHashes' => $hashes,
));
foreach ($revisions as $dict) {
$revision_hashes = idx($dict, 'hashes');
if (!$revision_hashes) {
continue;
}
$revision_ref = ArcanistRevisionRef::newFromConduit($dict);
foreach ($revision_hashes as $revision_hash) {
$hash_key = $this->getHashKey($revision_hash);
$state_refs = idx($map, $hash_key, array());
foreach ($state_refs as $ref_key => $state_ref) {
$results[$ref_key][] = $revision_ref;
}
}
}
}
return $results;
}
private function getHashKey(array $hash) {
return $hash[0].':'.$hash[1];
}
}