@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.

Index all repository URIs, not just the "primary" repository URI

Summary:
Ref T10923. When regenerating the URI index for a repository, index every URI.

- Also, make the index slightly stricter (domain + path instead of just path). Excluding the domain made more sense when we were generating only first-party URIs.
- Make the index smarter about `/diffusion/123/` URIs.
- Show normalized URIs in `diffusion.repository.search` results.

Test Plan:
- Ran migration.
- Verified sensible-looking results in database.
- Searched for a repository URI by first-party clone URI.
- Searched for a repository URI by mirror URI.
- Used `diffusion.repository.search` to get information about repository URIs.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10923

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

+93 -44
+2 -5
resources/sql/autopatches/20160112.repo.02.uri.index.php
··· 1 1 <?php 2 2 3 - $table = new PhabricatorRepository(); 4 - 5 - foreach (new LiskMigrationIterator($table) as $repo) { 6 - $repo->updateURIIndex(); 7 - } 3 + // A later patch ("20160510.repo.01.uriindex.php") performs an identical 4 + // regeneration of the index, so we no longer need to do it here.
+10
resources/sql/autopatches/20160510.repo.01.uriindex.php
··· 1 + <?php 2 + 3 + $repos = id(new PhabricatorRepositoryQuery()) 4 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 5 + ->needURIs(true) 6 + ->execute(); 7 + 8 + foreach ($repos as $repo) { 9 + $repo->updateURIIndex(); 10 + }
+34 -1
src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
··· 59 59 $this->uri = $uri; 60 60 } 61 61 62 + public static function getAllURITypes() { 63 + return array( 64 + self::TYPE_GIT, 65 + self::TYPE_SVN, 66 + self::TYPE_MERCURIAL, 67 + ); 68 + } 69 + 62 70 63 71 /* -( Normalizing URIs )--------------------------------------------------- */ 64 72 ··· 91 99 } 92 100 } 93 101 102 + public function getNormalizedURI() { 103 + return $this->getNormalizedDomain().'/'.$this->getNormalizedPath(); 104 + } 105 + 94 106 95 107 /** 96 108 * @task normal ··· 113 125 // example. 114 126 115 127 $matches = null; 116 - if (preg_match('@^(diffusion/[A-Z]+)@', $path, $matches)) { 128 + if (preg_match('@^(diffusion/(?:[A-Z]+|\d+))@', $path, $matches)) { 117 129 $path = $matches[1]; 118 130 } 119 131 120 132 return $path; 121 133 } 134 + 135 + public function getNormalizedDomain() { 136 + $domain = null; 137 + 138 + $uri = new PhutilURI($this->uri); 139 + if ($uri->getProtocol()) { 140 + $domain = $uri->getDomain(); 141 + } 142 + 143 + if (!strlen($domain)) { 144 + $uri = new PhutilGitURI($this->uri); 145 + $domain = $uri->getDomain(); 146 + } 147 + 148 + if (!strlen($domain)) { 149 + $domain = '<void>'; 150 + } 151 + 152 + return phutil_utf8_strtolower($domain); 153 + } 154 + 122 155 123 156 }
+8 -12
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 650 650 } 651 651 652 652 if ($this->uris !== null) { 653 - $try_uris = $this->getNormalizedPaths(); 653 + $try_uris = $this->getNormalizedURIs(); 654 654 $try_uris = array_fuse($try_uris); 655 655 656 656 $where[] = qsprintf( ··· 666 666 return 'PhabricatorDiffusionApplication'; 667 667 } 668 668 669 - private function getNormalizedPaths() { 669 + private function getNormalizedURIs() { 670 670 $normalized_uris = array(); 671 671 672 672 // Since we don't know which type of repository this URI is in the general ··· 675 675 // or an `svn+ssh` URI, we could deduce how to normalize it. However, this 676 676 // would be more complicated and it's not clear if it matters in practice. 677 677 678 + $types = PhabricatorRepositoryURINormalizer::getAllURITypes(); 678 679 foreach ($this->uris as $uri) { 679 - $normalized_uris[] = new PhabricatorRepositoryURINormalizer( 680 - PhabricatorRepositoryURINormalizer::TYPE_GIT, 681 - $uri); 682 - $normalized_uris[] = new PhabricatorRepositoryURINormalizer( 683 - PhabricatorRepositoryURINormalizer::TYPE_SVN, 684 - $uri); 685 - $normalized_uris[] = new PhabricatorRepositoryURINormalizer( 686 - PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, 687 - $uri); 680 + foreach ($types as $type) { 681 + $normalized_uri = new PhabricatorRepositoryURINormalizer($type, $uri); 682 + $normalized_uris[] = $normalized_uri->getNormalizedURI(); 683 + } 688 684 } 689 685 690 - return array_unique(mpull($normalized_uris, 'getNormalizedPath')); 686 + return array_unique($normalized_uris); 691 687 } 692 688 693 689 }
+9
src/applications/repository/query/PhabricatorRepositorySearchEngine.php
··· 38 38 ->setLabel(pht('Types')) 39 39 ->setKey('types') 40 40 ->setOptions(PhabricatorRepositoryType::getAllRepositoryTypes()), 41 + id(new PhabricatorSearchStringListField()) 42 + ->setLabel(pht('URIs')) 43 + ->setKey('uris') 44 + ->setDescription( 45 + pht('Search for repositories by clone/checkout URI.')), 41 46 ); 42 47 } 43 48 ··· 68 73 69 74 if (strlen($map['name'])) { 70 75 $query->withNameContains($map['name']); 76 + } 77 + 78 + if ($map['uris']) { 79 + $query->withURIs($map['uris']); 71 80 } 72 81 73 82 return $query;
+9 -26
src/applications/repository/storage/PhabricatorRepository.php
··· 803 803 } 804 804 805 805 public function updateURIIndex() { 806 - $uris = array( 807 - (string)$this->getCloneURIObject(), 808 - ); 806 + $indexes = array(); 809 807 810 - foreach ($uris as $key => $uri) { 811 - $uris[$key] = $this->getNormalizedURI($uri) 812 - ->getNormalizedPath(); 808 + $uris = $this->getURIs(); 809 + foreach ($uris as $uri) { 810 + if ($uri->getIsDisabled()) { 811 + continue; 812 + } 813 + 814 + $indexes[] = $uri->getNormalizedURI(); 813 815 } 814 816 815 817 PhabricatorRepositoryURIIndex::updateRepositoryURIs( 816 818 $this->getPHID(), 817 - $uris); 819 + $indexes); 818 820 819 821 return $this; 820 - } 821 - 822 - private function getNormalizedURI($uri) { 823 - switch ($this->getVersionControlSystem()) { 824 - case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 825 - return new PhabricatorRepositoryURINormalizer( 826 - PhabricatorRepositoryURINormalizer::TYPE_GIT, 827 - $uri); 828 - case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 829 - return new PhabricatorRepositoryURINormalizer( 830 - PhabricatorRepositoryURINormalizer::TYPE_SVN, 831 - $uri); 832 - case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 833 - return new PhabricatorRepositoryURINormalizer( 834 - PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, 835 - $uri); 836 - default: 837 - throw new Exception(pht('Unrecognized version control system.')); 838 - } 839 822 } 840 823 841 824 public function isTracked() {
+21
src/applications/repository/storage/PhabricatorRepositoryURI.php
··· 196 196 return $this->getURIObject(false); 197 197 } 198 198 199 + public function getNormalizedURI() { 200 + $vcs = $this->getRepository()->getVersionControlSystem(); 201 + 202 + $map = array( 203 + PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => 204 + PhabricatorRepositoryURINormalizer::TYPE_GIT, 205 + PhabricatorRepositoryType::REPOSITORY_TYPE_SVN => 206 + PhabricatorRepositoryURINormalizer::TYPE_SVN, 207 + PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => 208 + PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, 209 + ); 210 + 211 + $type = $map[$vcs]; 212 + $display = (string)$this->getDisplayURI(); 213 + 214 + $normal_uri = new PhabricatorRepositoryURINormalizer($type, $display); 215 + 216 + return $normal_uri->getNormalizedURI(); 217 + } 218 + 199 219 public function getEffectiveURI() { 200 220 return $this->getURIObject(true); 201 221 } ··· 693 713 'raw' => $this->getURI(), 694 714 'display' => (string)$this->getDisplayURI(), 695 715 'effective' => (string)$this->getEffectiveURI(), 716 + 'normalized' => (string)$this->getNormalizedURI(), 696 717 ), 697 718 'io' => array( 698 719 'raw' => $this->getIOType(),