Page MenuHomePhabricator

D15876.diff
No OneTemporary

D15876.diff

diff --git a/resources/sql/autopatches/20160112.repo.02.uri.index.php b/resources/sql/autopatches/20160112.repo.02.uri.index.php
--- a/resources/sql/autopatches/20160112.repo.02.uri.index.php
+++ b/resources/sql/autopatches/20160112.repo.02.uri.index.php
@@ -1,7 +1,4 @@
<?php
-$table = new PhabricatorRepository();
-
-foreach (new LiskMigrationIterator($table) as $repo) {
- $repo->updateURIIndex();
-}
+// A later patch ("20160510.repo.01.uriindex.php") performs an identical
+// regeneration of the index, so we no longer need to do it here.
diff --git a/resources/sql/autopatches/20160510.repo.01.uriindex.php b/resources/sql/autopatches/20160510.repo.01.uriindex.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160510.repo.01.uriindex.php
@@ -0,0 +1,10 @@
+<?php
+
+$repos = id(new PhabricatorRepositoryQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->needURIs(true)
+ ->execute();
+
+foreach ($repos as $repo) {
+ $repo->updateURIIndex();
+}
diff --git a/src/applications/repository/data/PhabricatorRepositoryURINormalizer.php b/src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
--- a/src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
+++ b/src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
@@ -59,6 +59,14 @@
$this->uri = $uri;
}
+ public static function getAllURITypes() {
+ return array(
+ self::TYPE_GIT,
+ self::TYPE_SVN,
+ self::TYPE_MERCURIAL,
+ );
+ }
+
/* -( Normalizing URIs )--------------------------------------------------- */
@@ -91,6 +99,10 @@
}
}
+ public function getNormalizedURI() {
+ return $this->getNormalizedDomain().'/'.$this->getNormalizedPath();
+ }
+
/**
* @task normal
@@ -113,11 +125,32 @@
// example.
$matches = null;
- if (preg_match('@^(diffusion/[A-Z]+)@', $path, $matches)) {
+ if (preg_match('@^(diffusion/(?:[A-Z]+|\d+))@', $path, $matches)) {
$path = $matches[1];
}
return $path;
}
+ public function getNormalizedDomain() {
+ $domain = null;
+
+ $uri = new PhutilURI($this->uri);
+ if ($uri->getProtocol()) {
+ $domain = $uri->getDomain();
+ }
+
+ if (!strlen($domain)) {
+ $uri = new PhutilGitURI($this->uri);
+ $domain = $uri->getDomain();
+ }
+
+ if (!strlen($domain)) {
+ $domain = '<void>';
+ }
+
+ return phutil_utf8_strtolower($domain);
+ }
+
+
}
diff --git a/src/applications/repository/query/PhabricatorRepositoryQuery.php b/src/applications/repository/query/PhabricatorRepositoryQuery.php
--- a/src/applications/repository/query/PhabricatorRepositoryQuery.php
+++ b/src/applications/repository/query/PhabricatorRepositoryQuery.php
@@ -650,7 +650,7 @@
}
if ($this->uris !== null) {
- $try_uris = $this->getNormalizedPaths();
+ $try_uris = $this->getNormalizedURIs();
$try_uris = array_fuse($try_uris);
$where[] = qsprintf(
@@ -666,7 +666,7 @@
return 'PhabricatorDiffusionApplication';
}
- private function getNormalizedPaths() {
+ private function getNormalizedURIs() {
$normalized_uris = array();
// Since we don't know which type of repository this URI is in the general
@@ -675,19 +675,15 @@
// 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.
+ $types = PhabricatorRepositoryURINormalizer::getAllURITypes();
foreach ($this->uris 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'));
+ foreach ($types as $type) {
+ $normalized_uri = new PhabricatorRepositoryURINormalizer($type, $uri);
+ $normalized_uris[] = $normalized_uri->getNormalizedURI();
+ }
+ }
+
+ return array_unique($normalized_uris);
}
}
diff --git a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php
--- a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php
+++ b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php
@@ -38,6 +38,11 @@
->setLabel(pht('Types'))
->setKey('types')
->setOptions(PhabricatorRepositoryType::getAllRepositoryTypes()),
+ id(new PhabricatorSearchStringListField())
+ ->setLabel(pht('URIs'))
+ ->setKey('uris')
+ ->setDescription(
+ pht('Search for repositories by clone/checkout URI.')),
);
}
@@ -70,6 +75,10 @@
$query->withNameContains($map['name']);
}
+ if ($map['uris']) {
+ $query->withURIs($map['uris']);
+ }
+
return $query;
}
diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php
--- a/src/applications/repository/storage/PhabricatorRepository.php
+++ b/src/applications/repository/storage/PhabricatorRepository.php
@@ -803,41 +803,24 @@
}
public function updateURIIndex() {
- $uris = array(
- (string)$this->getCloneURIObject(),
- );
+ $indexes = array();
- foreach ($uris as $key => $uri) {
- $uris[$key] = $this->getNormalizedURI($uri)
- ->getNormalizedPath();
+ $uris = $this->getURIs();
+ foreach ($uris as $uri) {
+ if ($uri->getIsDisabled()) {
+ continue;
+ }
+
+ $indexes[] = $uri->getNormalizedURI();
}
PhabricatorRepositoryURIIndex::updateRepositoryURIs(
$this->getPHID(),
- $uris);
+ $indexes);
return $this;
}
- private function getNormalizedURI($uri) {
- switch ($this->getVersionControlSystem()) {
- case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
- return new PhabricatorRepositoryURINormalizer(
- PhabricatorRepositoryURINormalizer::TYPE_GIT,
- $uri);
- case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
- return new PhabricatorRepositoryURINormalizer(
- PhabricatorRepositoryURINormalizer::TYPE_SVN,
- $uri);
- case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
- return new PhabricatorRepositoryURINormalizer(
- PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL,
- $uri);
- default:
- throw new Exception(pht('Unrecognized version control system.'));
- }
- }
-
public function isTracked() {
$status = $this->getDetail('tracking-enabled');
$map = self::getStatusMap();
diff --git a/src/applications/repository/storage/PhabricatorRepositoryURI.php b/src/applications/repository/storage/PhabricatorRepositoryURI.php
--- a/src/applications/repository/storage/PhabricatorRepositoryURI.php
+++ b/src/applications/repository/storage/PhabricatorRepositoryURI.php
@@ -196,6 +196,26 @@
return $this->getURIObject(false);
}
+ public function getNormalizedURI() {
+ $vcs = $this->getRepository()->getVersionControlSystem();
+
+ $map = array(
+ PhabricatorRepositoryType::REPOSITORY_TYPE_GIT =>
+ PhabricatorRepositoryURINormalizer::TYPE_GIT,
+ PhabricatorRepositoryType::REPOSITORY_TYPE_SVN =>
+ PhabricatorRepositoryURINormalizer::TYPE_SVN,
+ PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL =>
+ PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL,
+ );
+
+ $type = $map[$vcs];
+ $display = (string)$this->getDisplayURI();
+
+ $normal_uri = new PhabricatorRepositoryURINormalizer($type, $display);
+
+ return $normal_uri->getNormalizedURI();
+ }
+
public function getEffectiveURI() {
return $this->getURIObject(true);
}
@@ -693,6 +713,7 @@
'raw' => $this->getURI(),
'display' => (string)$this->getDisplayURI(),
'effective' => (string)$this->getEffectiveURI(),
+ 'normalized' => (string)$this->getNormalizedURI(),
),
'io' => array(
'raw' => $this->getIOType(),

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 1, 11:34 AM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6737939
Default Alt Text
D15876.diff (8 KB)

Event Timeline