Page MenuHomePhabricator

D8069.diff
No OneTemporary

D8069.diff

Index: src/applications/repository/conduit/ConduitAPI_repository_query_Method.php
===================================================================
--- src/applications/repository/conduit/ConduitAPI_repository_query_Method.php
+++ src/applications/repository/conduit/ConduitAPI_repository_query_Method.php
@@ -21,6 +21,7 @@
'phids' => 'optional list<phid>',
'callsigns' => 'optional list<string>',
'vcsTypes' => 'optional list<string>',
+ 'remoteURIs' => 'optional list<string>',
);
}
@@ -57,6 +58,11 @@
$query->withTypes($vcs_types);
}
+ $remote_uris = $request->getValue('remoteURIs', array());
+ if ($remote_uris) {
+ $query->withRemoteURIs($remote_uris);
+ }
+
$repositories = $query->execute();
$results = array();
Index: src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
===================================================================
--- src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
+++ src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
@@ -40,6 +40,7 @@
const TYPE_GIT = 'git';
const TYPE_SVN = 'svn';
+ const TYPE_MERCURIAL = 'hg';
private $type;
private $uri;
@@ -48,6 +49,7 @@
switch ($type) {
case self::TYPE_GIT:
case self::TYPE_SVN:
+ case self::TYPE_MERCURIAL:
break;
default:
throw new Exception(pht('Unknown URI type "%s"!'));
@@ -79,6 +81,7 @@
return $this->uri;
case self::TYPE_SVN:
+ case self::TYPE_MERCURIAL:
$uri = new PhutilURI($this->uri);
if ($uri->getProtocol()) {
return $uri->getPath();
@@ -101,6 +104,7 @@
$path = preg_replace('/\.git$/', '', $path);
break;
case self::TYPE_SVN:
+ case self::TYPE_MERCURIAL:
break;
}
Index: src/applications/repository/query/PhabricatorRepositoryQuery.php
===================================================================
--- src/applications/repository/query/PhabricatorRepositoryQuery.php
+++ src/applications/repository/query/PhabricatorRepositoryQuery.php
@@ -9,6 +9,7 @@
private $types;
private $uuids;
private $nameContains;
+ private $remoteURIs;
const STATUS_OPEN = 'status-open';
const STATUS_CLOSED = 'status-closed';
@@ -70,6 +71,11 @@
return $this;
}
+ public function withRemoteURIs(array $uris) {
+ $this->remoteURIs = $uris;
+ return $this;
+ }
+
public function needCommitCounts($need_counts) {
$this->needCommitCounts = $need_counts;
return $this;
@@ -90,6 +96,7 @@
return $this;
}
+
protected function loadPage() {
$table = new PhabricatorRepository();
$conn_r = $table->establishConnection('r');
@@ -159,6 +166,7 @@
throw new Exception("Unknown status '{$status}'!");
}
+ // TODO: This should also be denormalized.
$hosted = $this->hosted;
switch ($hosted) {
case self::HOSTED_PHABRICATOR:
@@ -178,6 +186,17 @@
}
}
+ // TODO: Denormalize this, too.
+ if ($this->remoteURIs) {
+ $try_uris = $this->getNormalizedPaths();
+ $try_uris = array_fuse($try_uris);
+ foreach ($repositories as $key => $repository) {
+ if (!isset($try_uris[$repository->getNormalizedPath()])) {
+ unset($repositories[$key]);
+ }
+ }
+ }
+
return $repositories;
}
@@ -389,4 +408,28 @@
return 'PhabricatorApplicationDiffusion';
}
+ private function getNormalizedPaths() {
+ $normalized_uris = array();
+
+ // Since we don't know which type of repository this URI is in the general
+ // case, just generate all the normalizations. We could refine this in some
+ // cases: if the query specifies VCS types, or the URI is a git-style URI
+ // or an `svn+ssh` URI, we could deduce how to normalize it. However, this
+ // would be more complicated and it's not clear if it matters in practice.
+
+ foreach ($this->remoteURIs as $uri) {
+ $normalized_uris[] = new PhabricatorRepositoryURINormalizer(
+ PhabricatorRepositoryURINormalizer::TYPE_GIT,
+ $uri);
+ $normalized_uris[] = new PhabricatorRepositoryURINormalizer(
+ PhabricatorRepositoryURINormalizer::TYPE_SVN,
+ $uri);
+ $normalized_uris[] = new PhabricatorRepositoryURINormalizer(
+ PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL,
+ $uri);
+ }
+
+ return array_unique(mpull($normalized_uris, 'getNormalizedPath'));
+ }
+
}
Index: src/applications/repository/storage/PhabricatorRepository.php
===================================================================
--- src/applications/repository/storage/PhabricatorRepository.php
+++ src/applications/repository/storage/PhabricatorRepository.php
@@ -485,6 +485,30 @@
return '/diffusion/'.$this->getCallsign().'/';
}
+ public function getNormalizedPath() {
+ switch ($this->getVersionControlSystem()) {
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
+ $normalized_uri = new PhabricatorRepositoryURINormalizer(
+ PhabricatorRepositoryURINormalizer::TYPE_GIT,
+ $this->getURI());
+ break;
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
+ $normalized_uri = new PhabricatorRepositoryURINormalizer(
+ PhabricatorRepositoryURINormalizer::TYPE_SVN,
+ $this->getURI());
+ break;
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
+ $normalized_uri = new PhabricatorRepositoryURINormalizer(
+ PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL,
+ $this->getURI());
+ break;
+ default:
+ throw new Exception("Unrecognized version control system.");
+ }
+
+ return $normalized_uri->getNormalizedPath();
+ }
+
public function isTracked() {
return $this->getDetail('tracking-enabled', false);
}

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 6:27 AM (18 h, 27 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6917721
Default Alt Text
D8069.diff (5 KB)

Event Timeline