Changeset View
Changeset View
Standalone View
Standalone View
src/browse/loader/ArcanistBrowseCommitURIHardpointLoader.php
Show All 28 Lines | if (!$repository_ref) { | ||||
'"%s" to understand how repositories are resolved.', | '"%s" to understand how repositories are resolved.', | ||||
'arc which'); | 'arc which'); | ||||
echo "\n"; | echo "\n"; | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
public function loadHardpoints(array $refs, $hardpoint) { | public function loadHardpoints(array $refs, $hardpoint) { | ||||
$api = $this->getQuery()->getRepositoryAPI(); | $query = $this->getQuery(); | ||||
$api = $query->getRepositoryAPI(); | |||||
if (!$api) { | if (!$api) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$repository_ref = $this->getQuery()->getRepositoryRef(); | $repository_ref = $query->getRepositoryRef(); | ||||
if (!$repository_ref) { | if (!$repository_ref) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$repository_phid = $repository_ref->getPHID(); | |||||
$refs = $this->getRefsWithSupportedTypes($refs); | $refs = $this->getRefsWithSupportedTypes($refs); | ||||
$commit_map = array(); | if (!$refs) { | ||||
foreach ($refs as $key => $ref) { | return array(); | ||||
$is_commit = $ref->hasType('commit'); | |||||
$token = $ref->getToken(); | |||||
if ($token === '.') { | |||||
// Git resolves "." like HEAD, but we want to treat it as "browse the | |||||
// current directory" instead in all cases. | |||||
continue; | |||||
} | } | ||||
if ($token === null) { | $this->newQuery($refs) | ||||
if ($is_commit) { | ->needHardpoints( | ||||
$token = $api->getHeadCommit(); | array( | ||||
} else { | 'commitRefs', | ||||
continue; | )) | ||||
} | ->execute(); | ||||
} | |||||
try { | $commit_refs = array(); | ||||
$commit = $api->getCanonicalRevisionName($token); | foreach ($refs as $key => $ref) { | ||||
if ($commit) { | foreach ($ref->getCommitRefs() as $commit_ref) { | ||||
$commit_map[$commit][] = $key; | $commit_refs[] = $commit_ref; | ||||
} | |||||
} catch (Exception $ex) { | |||||
// Ignore anything we can't resolve. | |||||
} | |||||
} | } | ||||
if (!$commit_map) { | |||||
return array(); | |||||
} | } | ||||
$commit_info = $this->resolveCall( | $this->newQuery($commit_refs) | ||||
'diffusion.querycommits', | ->needHardpoints( | ||||
array( | array( | ||||
'repositoryPHID' => $repository_phid, | 'upstream', | ||||
'names' => array_keys($commit_map), | )) | ||||
)); | ->execute(); | ||||
$results = array(); | $results = array(); | ||||
foreach ($commit_info['identifierMap'] as $commit_key => $commit_phid) { | foreach ($refs as $key => $ref) { | ||||
foreach ($commit_map[$commit_key] as $key) { | $commit_refs = $ref->getCommitRefs(); | ||||
$commit_uri = $commit_info['data'][$commit_phid]['uri']; | foreach ($commit_refs as $commit_ref) { | ||||
$uri = $commit_ref->getURI(); | |||||
if ($uri !== null) { | |||||
$results[$key][] = id(new ArcanistBrowseURIRef()) | $results[$key][] = id(new ArcanistBrowseURIRef()) | ||||
->setURI($commit_uri) | ->setURI() | ||||
->setType('commit'); | ->setType(self::BROWSETYPE); | ||||
} | |||||
} | } | ||||
} | } | ||||
return $results; | return $results; | ||||
} | } | ||||
} | } |