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

Distinguish between "Remote URI" and "Clone URI" in Repositories

Summary:
Hosted repositories have muddied this distinction somewhat. In some cases, we only want to use the real remote URI, and the call is only relevant for imported repositories.

In other cases, we want the URI we'd plug into `git clone`.

Move this logic into `PhabricatorRepository` and make the distinction more clear.

Test Plan: Viewed SVN, Git, and Mercurial hosted and remote repositories, all the URIs looked reasonable.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, dctrwatson

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

+120 -53
+1 -1
src/applications/diffusion/controller/DiffusionExternalController.php
··· 33 33 if ($remote_uri->getPath() == $uri_path) { 34 34 $matches[$key] = 1; 35 35 } 36 - if ($repository->getPublicRemoteURI() == $uri) { 36 + if ($repository->getPublicCloneURI() == $uri) { 37 37 $matches[$key] = 2; 38 38 } 39 39 if ($repository->getRemoteURI() == $uri) {
+9 -30
src/applications/diffusion/controller/DiffusionRepositoryController.php
··· 174 174 } 175 175 176 176 if ($repository->isHosted()) { 177 - $serve_off = PhabricatorRepository::SERVE_OFF; 178 - $callsign = $repository->getCallsign(); 179 - $repo_path = '/diffusion/'.$callsign.'/'; 180 - 181 - $serve_ssh = $repository->getServeOverSSH(); 182 - if ($serve_ssh !== $serve_off) { 183 - $uri = new PhutilURI(PhabricatorEnv::getProductionURI($repo_path)); 184 - 185 - if ($repository->isSVN()) { 186 - $uri->setProtocol('svn+ssh'); 187 - } else { 188 - $uri->setProtocol('ssh'); 189 - } 190 - 191 - $ssh_user = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); 192 - if ($ssh_user) { 193 - $uri->setUser($ssh_user); 194 - } 195 - 196 - $uri->setPort(PhabricatorEnv::getEnvConfig('diffusion.ssh-port')); 197 - 177 + $ssh_uri = $repository->getSSHCloneURIObject(); 178 + if ($ssh_uri) { 198 179 $clone_uri = $this->renderCloneURI( 199 - $uri, 200 - $serve_ssh, 180 + $ssh_uri, 181 + $repository->getServeOverSSH(), 201 182 '/settings/panel/ssh/'); 202 183 203 184 $view->addProperty(pht('Clone URI (SSH)'), $clone_uri); 204 185 } 205 186 206 - $serve_http = $repository->getServeOverHTTP(); 207 - if ($serve_http !== $serve_off) { 208 - $http_uri = PhabricatorEnv::getProductionURI($repo_path); 209 - 187 + $http_uri = $repository->getHTTPCloneURIObject(); 188 + if ($http_uri) { 210 189 $clone_uri = $this->renderCloneURI( 211 190 $http_uri, 212 - $serve_http, 191 + $repository->getServeOverHTTP(), 213 192 PhabricatorEnv::getEnvConfig('diffusion.allow-http-auth') 214 193 ? '/settings/panel/vcspassword/' 215 194 : null); ··· 223 202 $view->addProperty( 224 203 pht('Clone URI'), 225 204 $this->renderCloneURI( 226 - $repository->getPublicRemoteURI())); 205 + $repository->getPublicCloneURI())); 227 206 break; 228 207 case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 229 208 $view->addProperty( 230 209 pht('Repository Root'), 231 210 $this->renderCloneURI( 232 - $repository->getPublicRemoteURI())); 211 + $repository->getPublicCloneURI())); 233 212 break; 234 213 } 235 214 }
+1 -1
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 175 175 if ($repo) { 176 176 $results['repository.callsign'] = $repo->getCallsign(); 177 177 $results['repository.vcs'] = $repo->getVersionControlSystem(); 178 - $results['repository.uri'] = $repo->getPublicRemoteURI(); 178 + $results['repository.uri'] = $repo->getPublicCloneURI(); 179 179 } 180 180 181 181 $results['step.timestamp'] = time();
+102 -14
src/applications/repository/storage/PhabricatorRepository.php
··· 486 486 } 487 487 488 488 public function getNormalizedPath() { 489 - if ($this->isHosted()) { 490 - $uri = PhabricatorEnv::getProductionURI($this->getURI()); 491 - } else { 492 - $uri = $this->getRemoteURI(); 493 - } 489 + $uri = (string)$this->getCloneURIObject(); 494 490 495 491 switch ($this->getVersionControlSystem()) { 496 492 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: ··· 629 625 return (bool)$this->getDetail('importing', false); 630 626 } 631 627 628 + 632 629 /* -( Repository URI Management )------------------------------------------ */ 633 630 634 631 ··· 675 672 676 673 677 674 /** 678 - * Get the remote URI for this repository, without authentication information. 675 + * Get the clone (or checkout) URI for this repository, without authentication 676 + * information. 679 677 * 680 678 * @return string Repository URI. 681 679 * @task uri 682 680 */ 683 - public function getPublicRemoteURI() { 684 - $uri = $this->getRemoteURIObject(); 681 + public function getPublicCloneURI() { 682 + $uri = $this->getCloneURIObject(); 685 683 686 684 // Make sure we don't leak anything if this repo is using HTTP Basic Auth 687 685 // with the credentials in the URI or something zany like that. 688 686 689 687 // If repository is not accessed over SSH we remove both username and 690 688 // password. 691 - if (!$this->shouldUseSSH()) { 692 - $uri->setUser(null); 689 + if (!$this->isHosted()) { 690 + if (!$this->shouldUseSSH()) { 691 + $uri->setUser(null); 693 692 694 - // This might be a Git URI or a normal URI. If it's Git, there's no 695 - // password support. 696 - if ($uri instanceof PhutilURI) { 697 - $uri->setPass(null); 693 + // This might be a Git URI or a normal URI. If it's Git, there's no 694 + // password support. 695 + if ($uri instanceof PhutilURI) { 696 + $uri->setPass(null); 697 + } 698 698 } 699 699 } 700 700 ··· 749 749 } 750 750 751 751 throw new Exception("Remote URI '{$raw_uri}' could not be parsed!"); 752 + } 753 + 754 + 755 + /** 756 + * Get the "best" clone/checkout URI for this repository, on any protocol. 757 + */ 758 + public function getCloneURIObject() { 759 + if (!$this->isHosted()) { 760 + return $this->getRemoteURIObject(); 761 + } 762 + 763 + // Choose the best URI: pick a read/write URI over a URI which is not 764 + // read/write, and SSH over HTTP. 765 + 766 + $serve_ssh = $this->getServeOverSSH(); 767 + $serve_http = $this->getServeOverHTTP(); 768 + 769 + if ($serve_ssh === self::SERVE_READWRITE) { 770 + return $this->getSSHCloneURIObject(); 771 + } else if ($serve_http === self::SERVE_READWRITE) { 772 + return $this->getHTTPCloneURIObject(); 773 + } else if ($serve_ssh !== self::SERVE_OFF) { 774 + return $this->getSSHCloneURIObject(); 775 + } else if ($serve_http !== self::SERVE_OFF) { 776 + return $this->getHTTPCloneURIObject(); 777 + } else { 778 + return null; 779 + } 780 + } 781 + 782 + 783 + /** 784 + * Get the repository's SSH clone/checkout URI, if one exists. 785 + */ 786 + public function getSSHCloneURIObject() { 787 + if (!$this->isHosted()) { 788 + if ($this->shouldUseSSH()) { 789 + return $this->getRemoteURIObject(); 790 + } else { 791 + return null; 792 + } 793 + } 794 + 795 + $serve_ssh = $this->getServeOverSSH(); 796 + if ($serve_ssh === self::SERVE_OFF) { 797 + return null; 798 + } 799 + 800 + $uri = new PhutilURI(PhabricatorEnv::getProductionURI($this->getURI())); 801 + 802 + if ($this->isSVN()) { 803 + $uri->setProtocol('svn+ssh'); 804 + } else { 805 + $uri->setProtocol('ssh'); 806 + } 807 + 808 + $ssh_user = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); 809 + if ($ssh_user) { 810 + $uri->setUser($ssh_user); 811 + } 812 + 813 + $uri->setPort(PhabricatorEnv::getEnvConfig('diffusion.ssh-port')); 814 + 815 + return $uri; 816 + } 817 + 818 + 819 + /** 820 + * Get the repository's HTTP clone/checkout URI, if one exists. 821 + */ 822 + public function getHTTPCloneURIObject() { 823 + if (!$this->isHosted()) { 824 + if ($this->shouldUseHTTP()) { 825 + return $this->getRemoteURIObject(); 826 + } else { 827 + return null; 828 + } 829 + } 830 + 831 + $serve_http = $this->getServeOverHTTP(); 832 + if ($serve_http === self::SERVE_OFF) { 833 + return null; 834 + } 835 + 836 + 837 + $uri = PhabricatorEnv::getProductionURI($this->getURI()); 838 + 839 + return $uri; 752 840 } 753 841 754 842
+7 -7
src/applications/repository/storage/__tests__/PhabricatorRepositoryURITestCase.php
··· 38 38 $repo->setVersionControlSystem($svn); 39 39 40 40 $this->assertEqual('http://example.com/', $repo->getRemoteURI()); 41 - $this->assertEqual('http://example.com/', $repo->getPublicRemoteURI()); 41 + $this->assertEqual('http://example.com/', $repo->getPublicCloneURI()); 42 42 $this->assertEqual('http://example.com/', 43 43 $repo->getRemoteURIEnvelope()->openEnvelope()); 44 44 45 45 $repo->setVersionControlSystem($git); 46 46 47 47 $this->assertEqual('http://example.com/', $repo->getRemoteURI()); 48 - $this->assertEqual('http://example.com/', $repo->getPublicRemoteURI()); 48 + $this->assertEqual('http://example.com/', $repo->getPublicCloneURI()); 49 49 $this->assertEqual('http://duck:quack@example.com/', 50 50 $repo->getRemoteURIEnvelope()->openEnvelope()); 51 51 52 52 $repo->setVersionControlSystem($hg); 53 53 54 54 $this->assertEqual('http://example.com/', $repo->getRemoteURI()); 55 - $this->assertEqual('http://example.com/', $repo->getPublicRemoteURI()); 55 + $this->assertEqual('http://example.com/', $repo->getPublicCloneURI()); 56 56 $this->assertEqual('http://duck:quack@example.com/', 57 57 $repo->getRemoteURIEnvelope()->openEnvelope()); 58 58 ··· 62 62 $repo->setVersionControlSystem($svn); 63 63 64 64 $this->assertEqual('ssh://example.com/', $repo->getRemoteURI()); 65 - $this->assertEqual('ssh://example.com/', $repo->getPublicRemoteURI()); 65 + $this->assertEqual('ssh://example.com/', $repo->getPublicCloneURI()); 66 66 $this->assertEqual('ssh://example.com/', 67 67 $repo->getRemoteURIEnvelope()->openEnvelope()); 68 68 69 69 $repo->setVersionControlSystem($git); 70 70 71 71 $this->assertEqual('ssh://example.com/', $repo->getRemoteURI()); 72 - $this->assertEqual('ssh://example.com/', $repo->getPublicRemoteURI()); 72 + $this->assertEqual('ssh://example.com/', $repo->getPublicCloneURI()); 73 73 $this->assertEqual('ssh://example.com/', 74 74 $repo->getRemoteURIEnvelope()->openEnvelope()); 75 75 76 76 $repo->setVersionControlSystem($hg); 77 77 78 78 $this->assertEqual('ssh://example.com/', $repo->getRemoteURI()); 79 - $this->assertEqual('ssh://example.com/', $repo->getPublicRemoteURI()); 79 + $this->assertEqual('ssh://example.com/', $repo->getPublicCloneURI()); 80 80 $this->assertEqual('ssh://example.com/', 81 81 $repo->getRemoteURIEnvelope()->openEnvelope()); 82 82 ··· 86 86 $repo->setVersionControlSystem($git); 87 87 88 88 $this->assertEqual('git@example.com:path.git', $repo->getRemoteURI()); 89 - $this->assertEqual('git@example.com:path.git', $repo->getPublicRemoteURI()); 89 + $this->assertEqual('git@example.com:path.git', $repo->getPublicCloneURI()); 90 90 $this->assertEqual('git@example.com:path.git', 91 91 $repo->getRemoteURIEnvelope()->openEnvelope()); 92 92