@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

In the repository URI index, store Phabricator's own URIs as tokens

Summary:
Fixes T13435. If you move Phabricator or copy data from one environment to another, the repository URI index currently still references the old URI, since it writes the URI as a plain string. This may make "arc which" and similar workflows have difficulty identifying repositories.

Instead, store the "phabricator.base-uri" domain and the "diffusion.ssh-host" domain as tokens, so lookups continue to work correctly even after these values change.

Test Plan:
- Added unit tests to cover the normalization.
- Ran migration, ran daemons, inspected `repository_uriindex` table, saw a mixture of sensible tokens (for local domains) and static domains (like "github.com").
- Ran this thing:

```
$ echo '{"remoteURIs": ["ssh://git@local.phacility.com/diffusion/P"]}' | ./bin/conduit call --method repository.query --trace --input -
Reading input from stdin...
>>> [2] (+0) <conduit> repository.query()
>>> [3] (+3) <connect> local_repository
<<< [3] (+3) <connect> 555 us
>>> [4] (+5) <query> SELECT `r`.* FROM `repository` `r` LEFT JOIN `local_repository`.`repository_uriindex` uri ON r.phid = uri.repositoryPHID WHERE (uri.repositoryURI IN ('<base-uri>/diffusion/P')) GROUP BY `r`.phid ORDER BY `r`.`id` DESC LIMIT 101
<<< [4] (+5) <query> 596 us
<<< [2] (+6) <conduit> 6,108 us
{
"result": [
{
"id": "1",
"name": "Phabricator",
"phid": "PHID-REPO-2psrynlauicce7d3q7g2",
"callsign": "P",
"monogram": "rP",
"vcs": "git",
"uri": "http://local.phacility.com/source/phabricator/",
"remoteURI": "https://github.com/phacility/phabricator.git",
"description": "asdf",
"isActive": true,
"isHosted": false,
"isImporting": false,
"encoding": "UTF-8",
"staging": {
"supported": true,
"prefix": "phabricator",
"uri": null
}
}
]
}
```

Note the `WHERE` clause in the query normalizes the URI into "<base-uri>", and the lookup succeeds.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13435

Differential Revision: https://secure.phabricator.com/D20872

+61 -2
+4
resources/sql/autopatches/20191028.uriindex.01.rebuild.php
··· 1 + <?php 2 + 3 + PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery( 4 + 'PhabricatorRepositoryQuery');
+27 -2
src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
··· 130 130 $domain = $uri->getDomain(); 131 131 132 132 if (!strlen($domain)) { 133 - $domain = '<void>'; 133 + return '<void>'; 134 + } 135 + 136 + $domain = phutil_utf8_strtolower($domain); 137 + 138 + // See T13435. If the domain for a repository URI is same as the install 139 + // base URI, store it as a "<base-uri>" token instead of the actual domain 140 + // so that the index does not fall out of date if the install moves. 141 + 142 + $base_uri = PhabricatorEnv::getURI('/'); 143 + $base_uri = new PhutilURI($base_uri); 144 + $base_domain = $base_uri->getDomain(); 145 + $base_domain = phutil_utf8_strtolower($base_domain); 146 + if ($domain === $base_domain) { 147 + return '<base-uri>'; 134 148 } 135 149 136 - return phutil_utf8_strtolower($domain); 150 + // Likewise, store a token for the "SSH Host" domain so it can be changed 151 + // without requiring an index rebuild. 152 + 153 + $ssh_host = PhabricatorEnv::getEnvConfig('diffusion.ssh-host'); 154 + if (strlen($ssh_host)) { 155 + $ssh_host = phutil_utf8_strtolower($ssh_host); 156 + if ($domain === $ssh_host) { 157 + return '<ssh-host>'; 158 + } 159 + } 160 + 161 + return $domain; 137 162 } 138 163 139 164
+30
src/applications/repository/data/__tests__/PhabricatorRepositoryURINormalizerTestCase.php
··· 31 31 } 32 32 } 33 33 34 + public function testDomainURINormalizer() { 35 + $base_domain = 'base.phabricator.example.com'; 36 + $ssh_domain = 'ssh.phabricator.example.com'; 37 + 38 + $env = PhabricatorEnv::beginScopedEnv(); 39 + $env->overrideEnvConfig('phabricator.base-uri', 'http://'.$base_domain); 40 + $env->overrideEnvConfig('diffusion.ssh-host', $ssh_domain); 41 + 42 + $cases = array( 43 + '/' => '<void>', 44 + '/path/to/local/repo.git' => '<void>', 45 + 'ssh://user@domain.com/path.git' => 'domain.com', 46 + 'ssh://user@DOMAIN.COM/path.git' => 'domain.com', 47 + 'http://'.$base_domain.'/diffusion/X/' => '<base-uri>', 48 + 'ssh://'.$ssh_domain.'/diffusion/X/' => '<ssh-host>', 49 + 'git@'.$ssh_domain.':bananas.git' => '<ssh-host>', 50 + ); 51 + 52 + $type_git = PhabricatorRepositoryURINormalizer::TYPE_GIT; 53 + 54 + foreach ($cases as $input => $expect) { 55 + $normal = new PhabricatorRepositoryURINormalizer($type_git, $input); 56 + 57 + $this->assertEqual( 58 + $expect, 59 + $normal->getNormalizedDomain(), 60 + pht('Normalized domain for "%s".', $input)); 61 + } 62 + } 63 + 34 64 public function testSVNURINormalizer() { 35 65 $cases = array( 36 66 'file:///path/to/repo' => 'path/to/repo',