Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepository.php
| Show First 20 Lines • Show All 1,195 Lines • ▼ Show 20 Lines | /* -( Repository URI Management )------------------------------------------ */ | ||||
| /** | /** | ||||
| * Get the protocol for the repository's remote. | * Get the protocol for the repository's remote. | ||||
| * | * | ||||
| * @return string Protocol, like "ssh" or "git". | * @return string Protocol, like "ssh" or "git". | ||||
| * @task uri | * @task uri | ||||
| */ | */ | ||||
| public function getRemoteProtocol() { | public function getRemoteProtocol() { | ||||
| $uri = $this->getRemoteURIObject(); | $uri = $this->getRemoteURIObject(); | ||||
| if ($uri instanceof PhutilGitURI) { | |||||
| return 'ssh'; | |||||
| } else { | |||||
| return $uri->getProtocol(); | return $uri->getProtocol(); | ||||
| } | } | ||||
| } | |||||
| /** | /** | ||||
| * Get a parsed object representation of the repository's remote URI. This | * Get a parsed object representation of the repository's remote URI.. | ||||
| * may be a normal URI (returned as a @{class@libphutil:PhutilURI}) or a git | |||||
| * URI (returned as a @{class@libphutil:PhutilGitURI}). | |||||
| * | * | ||||
| * @return wild A @{class@libphutil:PhutilURI} or | * @return wild A @{class@libphutil:PhutilURI}. | ||||
| * @{class@libphutil:PhutilGitURI}. | |||||
| * @task uri | * @task uri | ||||
| */ | */ | ||||
| public function getRemoteURIObject() { | public function getRemoteURIObject() { | ||||
| $raw_uri = $this->getDetail('remote-uri'); | $raw_uri = $this->getDetail('remote-uri'); | ||||
| if (!$raw_uri) { | if (!strlen($raw_uri)) { | ||||
| return new PhutilURI(''); | return new PhutilURI(''); | ||||
| } | } | ||||
| if (!strncmp($raw_uri, '/', 1)) { | if (!strncmp($raw_uri, '/', 1)) { | ||||
| return new PhutilURI('file://'.$raw_uri); | return new PhutilURI('file://'.$raw_uri); | ||||
| } | } | ||||
| $uri = new PhutilURI($raw_uri); | return new PhutilURI($raw_uri); | ||||
| if ($uri->getProtocol()) { | |||||
| return $uri; | |||||
| } | |||||
| $uri = new PhutilGitURI($raw_uri); | |||||
| if ($uri->getDomain()) { | |||||
| return $uri; | |||||
| } | |||||
| throw new Exception(pht("Remote URI '%s' could not be parsed!", $raw_uri)); | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the "best" clone/checkout URI for this repository, on any protocol. | * Get the "best" clone/checkout URI for this repository, on any protocol. | ||||
| */ | */ | ||||
| public function getCloneURIObject() { | public function getCloneURIObject() { | ||||
| if (!$this->isHosted()) { | if (!$this->isHosted()) { | ||||
| ▲ Show 20 Lines • Show All 410 Lines • ▼ Show 20 Lines | if ($status_code === null) { | ||||
| $status_code, | $status_code, | ||||
| json_encode($parameters), | json_encode($parameters), | ||||
| time()); | time()); | ||||
| } | } | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public static function getRemoteURIProtocol($raw_uri) { | |||||
| $uri = new PhutilURI($raw_uri); | |||||
| if ($uri->getProtocol()) { | |||||
| return strtolower($uri->getProtocol()); | |||||
| } | |||||
| $git_uri = new PhutilGitURI($raw_uri); | |||||
| if (strlen($git_uri->getDomain()) && strlen($git_uri->getPath())) { | |||||
| return 'ssh'; | |||||
| } | |||||
| return null; | |||||
| } | |||||
| public static function assertValidRemoteURI($uri) { | public static function assertValidRemoteURI($uri) { | ||||
| if (trim($uri) != $uri) { | if (trim($uri) != $uri) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht('The remote URI has leading or trailing whitespace.')); | pht('The remote URI has leading or trailing whitespace.')); | ||||
| } | } | ||||
| $protocol = self::getRemoteURIProtocol($uri); | $uri_object = new PhutilURI($uri); | ||||
| $protocol = $uri_object->getProtocol(); | |||||
| // Catch confusion between Git/SCP-style URIs and normal URIs. See T3619 | // Catch confusion between Git/SCP-style URIs and normal URIs. See T3619 | ||||
| // for discussion. This is usually a user adding "ssh://" to an implicit | // for discussion. This is usually a user adding "ssh://" to an implicit | ||||
| // SSH Git URI. | // SSH Git URI. | ||||
| if ($protocol == 'ssh') { | if ($protocol == 'ssh') { | ||||
| if (preg_match('(^[^:@]+://[^/:]+:[^\d])', $uri)) { | if (preg_match('(^[^:@]+://[^/:]+:[^\d])', $uri)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| ▲ Show 20 Lines • Show All 735 Lines • Show Last 20 Lines | |||||