1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 00:02:40 +01:00

Support generating remote refs in Git

Summary: Ref T13546. Allow construction of remote refs in Git; previously they were only supported in Mercurial.

Test Plan: Ran "arc inspect remote(origin)" in Git, got a ref.

Maniphest Tasks: T13546

Differential Revision: https://secure.phabricator.com/D21375
This commit is contained in:
epriestley 2020-06-30 12:02:37 -07:00
parent 89f9eb66a7
commit ffb027e85c
4 changed files with 69 additions and 1 deletions

View file

@ -218,6 +218,7 @@ phutil_register_library_map(array(
'ArcanistGitRawCommit' => 'repository/raw/ArcanistGitRawCommit.php',
'ArcanistGitRawCommitTestCase' => 'repository/raw/__tests__/ArcanistGitRawCommitTestCase.php',
'ArcanistGitRepositoryMarkerQuery' => 'repository/marker/ArcanistGitRepositoryMarkerQuery.php',
'ArcanistGitRepositoryRemoteQuery' => 'repository/remote/ArcanistGitRepositoryRemoteQuery.php',
'ArcanistGitUpstreamPath' => 'repository/api/ArcanistGitUpstreamPath.php',
'ArcanistGitWorkEngine' => 'work/ArcanistGitWorkEngine.php',
'ArcanistGitWorkingCopy' => 'workingcopy/ArcanistGitWorkingCopy.php',
@ -1246,6 +1247,7 @@ phutil_register_library_map(array(
'ArcanistGitRawCommit' => 'Phobject',
'ArcanistGitRawCommitTestCase' => 'PhutilTestCase',
'ArcanistGitRepositoryMarkerQuery' => 'ArcanistRepositoryMarkerQuery',
'ArcanistGitRepositoryRemoteQuery' => 'ArcanistRepositoryRemoteQuery',
'ArcanistGitUpstreamPath' => 'Phobject',
'ArcanistGitWorkEngine' => 'ArcanistWorkEngine',
'ArcanistGitWorkingCopy' => 'ArcanistWorkingCopy',

View file

@ -1763,4 +1763,8 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
return new ArcanistGitRepositoryMarkerQuery();
}
protected function newRemoteRefQueryTemplate() {
return new ArcanistGitRepositoryRemoteQuery();
}
}

View file

@ -1014,7 +1014,6 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
return new ArcanistMercurialRepositoryRemoteQuery();
}
public function getMercurialExtensionArguments() {
$path = phutil_get_library_root('arcanist');
$path = dirname($path);

View file

@ -0,0 +1,63 @@
<?php
final class ArcanistGitRepositoryRemoteQuery
extends ArcanistRepositoryRemoteQuery {
protected function newRemoteRefs() {
$api = $this->getRepositoryAPI();
$future = $api->newFuture('remote --verbose');
list($lines) = $future->resolve();
$pattern =
'(^'.
'(?P<name>[^\t]+)'.
'\t'.
'(?P<uri>[^\s]+)'.
' '.
'\((?P<mode>fetch|push)\)'.
'\z'.
')';
$map = array();
$lines = phutil_split_lines($lines, false);
foreach ($lines as $line) {
$matches = null;
if (!preg_match($pattern, $line, $matches)) {
throw new Exception(
pht(
'Failed to match remote pattern against line "%s".',
$line));
}
$name = $matches['name'];
$uri = $matches['uri'];
$mode = $matches['mode'];
$map[$name][$mode] = $uri;
}
$refs = array();
foreach ($map as $name => $uris) {
$fetch_uri = idx($uris, 'fetch');
$push_uri = idx($uris, 'push');
$ref = id(new ArcanistRemoteRef())
->setRemoteName($name);
if ($fetch_uri !== null) {
$ref->setFetchURI($fetch_uri);
}
if ($push_uri !== null) {
$ref->setPushURI($push_uri);
}
$refs[] = $ref;
}
return $refs;
}
}