Page MenuHomePhabricator

D20872.id49757.diff
No OneTemporary

D20872.id49757.diff

diff --git a/resources/sql/autopatches/20191028.uriindex.01.rebuild.php b/resources/sql/autopatches/20191028.uriindex.01.rebuild.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20191028.uriindex.01.rebuild.php
@@ -0,0 +1,4 @@
+<?php
+
+PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery(
+ 'PhabricatorRepositoryQuery');
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
@@ -130,10 +130,35 @@
$domain = $uri->getDomain();
if (!strlen($domain)) {
- $domain = '<void>';
+ return '<void>';
}
- return phutil_utf8_strtolower($domain);
+ $domain = phutil_utf8_strtolower($domain);
+
+ // See T13435. If the domain for a repository URI is same as the install
+ // base URI, store it as a "<base-uri>" token instead of the actual domain
+ // so that the index does not fall out of date if the install moves.
+
+ $base_uri = PhabricatorEnv::getURI('/');
+ $base_uri = new PhutilURI($base_uri);
+ $base_domain = $base_uri->getDomain();
+ $base_domain = phutil_utf8_strtolower($base_domain);
+ if ($domain === $base_domain) {
+ return '<base-uri>';
+ }
+
+ // Likewise, store a token for the "SSH Host" domain so it can be changed
+ // without requiring an index rebuild.
+
+ $ssh_host = PhabricatorEnv::getEnvConfig('diffusion.ssh-host');
+ if (strlen($ssh_host)) {
+ $ssh_host = phutil_utf8_strtolower($ssh_host);
+ if ($domain === $ssh_host) {
+ return '<ssh-host>';
+ }
+ }
+
+ return $domain;
}
diff --git a/src/applications/repository/data/__tests__/PhabricatorRepositoryURINormalizerTestCase.php b/src/applications/repository/data/__tests__/PhabricatorRepositoryURINormalizerTestCase.php
--- a/src/applications/repository/data/__tests__/PhabricatorRepositoryURINormalizerTestCase.php
+++ b/src/applications/repository/data/__tests__/PhabricatorRepositoryURINormalizerTestCase.php
@@ -31,6 +31,36 @@
}
}
+ public function testDomainURINormalizer() {
+ $base_domain = 'base.phabricator.example.com';
+ $ssh_domain = 'ssh.phabricator.example.com';
+
+ $env = PhabricatorEnv::beginScopedEnv();
+ $env->overrideEnvConfig('phabricator.base-uri', 'http://'.$base_domain);
+ $env->overrideEnvConfig('diffusion.ssh-host', $ssh_domain);
+
+ $cases = array(
+ '/' => '<void>',
+ '/path/to/local/repo.git' => '<void>',
+ 'ssh://user@domain.com/path.git' => 'domain.com',
+ 'ssh://user@DOMAIN.COM/path.git' => 'domain.com',
+ 'http://'.$base_domain.'/diffusion/X/' => '<base-uri>',
+ 'ssh://'.$ssh_domain.'/diffusion/X/' => '<ssh-host>',
+ 'git@'.$ssh_domain.':bananas.git' => '<ssh-host>',
+ );
+
+ $type_git = PhabricatorRepositoryURINormalizer::TYPE_GIT;
+
+ foreach ($cases as $input => $expect) {
+ $normal = new PhabricatorRepositoryURINormalizer($type_git, $input);
+
+ $this->assertEqual(
+ $expect,
+ $normal->getNormalizedDomain(),
+ pht('Normalized domain for "%s".', $input));
+ }
+ }
+
public function testSVNURINormalizer() {
$cases = array(
'file:///path/to/repo' => 'path/to/repo',

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 26, 3:02 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7696350
Default Alt Text
D20872.id49757.diff (3 KB)

Event Timeline