mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Remove all uses of PhutilGitURI in Phabricator
Summary: Ref T11137. This class is removed in D16099. Depends on D16099. `PhutilURI` now attempts to "just work" with Git-style URIs, so at least in theory we can just delete all of this code and pretend it does not exist. (I've left "Display URI" and "Effective URI" as distinct, at least for now, because I think the distinction may be relevant in the future even though it isn't right now, and to keep this diff small, although I may go remove one after I think about this for a bit.) Test Plan: - Created a new Git repository with a Git URI. - Pulled/updated it, which now works correctly and should resolve the original issue in T11137. - Verified that daemons now align the origin to a Git-style URI with a relative path, which should resolve the original issue in T11004. - Grepped for `PhutilGitURI`. - Also grepped in `arcanist/`, but found no matches, so no patch for that. - Checked display/conduit URIs. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11137 Differential Revision: https://secure.phabricator.com/D16100
This commit is contained in:
parent
fb156af480
commit
bba53205de
4 changed files with 29 additions and 104 deletions
|
@ -69,11 +69,6 @@ EOTEXT
|
|||
$uri_object = new PhutilURI($uri);
|
||||
$domain = $uri_object->getDomain();
|
||||
|
||||
if (!strlen($domain)) {
|
||||
$uri_object = new PhutilGitURI($uri);
|
||||
$domain = $uri_object->getDomain();
|
||||
}
|
||||
|
||||
$domain = phutil_utf8_strtolower($domain);
|
||||
switch ($domain) {
|
||||
case 'github.com':
|
||||
|
|
|
@ -78,16 +78,7 @@ final class PhabricatorRepositoryURINormalizer extends Phobject {
|
|||
switch ($this->type) {
|
||||
case self::TYPE_GIT:
|
||||
$uri = new PhutilURI($this->uri);
|
||||
if ($uri->getProtocol()) {
|
||||
return $uri->getPath();
|
||||
}
|
||||
|
||||
$uri = new PhutilGitURI($this->uri);
|
||||
if ($uri->getDomain()) {
|
||||
return $uri->getPath();
|
||||
}
|
||||
|
||||
return $this->uri;
|
||||
case self::TYPE_SVN:
|
||||
case self::TYPE_MERCURIAL:
|
||||
$uri = new PhutilURI($this->uri);
|
||||
|
@ -136,14 +127,7 @@ final class PhabricatorRepositoryURINormalizer extends Phobject {
|
|||
$domain = null;
|
||||
|
||||
$uri = new PhutilURI($this->uri);
|
||||
if ($uri->getProtocol()) {
|
||||
$domain = $uri->getDomain();
|
||||
}
|
||||
|
||||
if (!strlen($domain)) {
|
||||
$uri = new PhutilGitURI($this->uri);
|
||||
$domain = $uri->getDomain();
|
||||
}
|
||||
|
||||
if (!strlen($domain)) {
|
||||
$domain = '<void>';
|
||||
|
|
|
@ -1201,27 +1201,19 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
*/
|
||||
public function getRemoteProtocol() {
|
||||
$uri = $this->getRemoteURIObject();
|
||||
|
||||
if ($uri instanceof PhutilGitURI) {
|
||||
return 'ssh';
|
||||
} else {
|
||||
return $uri->getProtocol();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a parsed object representation of the repository's remote URI. This
|
||||
* may be a normal URI (returned as a @{class@libphutil:PhutilURI}) or a git
|
||||
* URI (returned as a @{class@libphutil:PhutilGitURI}).
|
||||
* Get a parsed object representation of the repository's remote URI..
|
||||
*
|
||||
* @return wild A @{class@libphutil:PhutilURI} or
|
||||
* @{class@libphutil:PhutilGitURI}.
|
||||
* @return wild A @{class@libphutil:PhutilURI}.
|
||||
* @task uri
|
||||
*/
|
||||
public function getRemoteURIObject() {
|
||||
$raw_uri = $this->getDetail('remote-uri');
|
||||
if (!$raw_uri) {
|
||||
if (!strlen($raw_uri)) {
|
||||
return new PhutilURI('');
|
||||
}
|
||||
|
||||
|
@ -1229,17 +1221,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
return new PhutilURI('file://'.$raw_uri);
|
||||
}
|
||||
|
||||
$uri = 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));
|
||||
return new PhutilURI($raw_uri);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1666,27 +1648,14 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
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) {
|
||||
if (trim($uri) != $uri) {
|
||||
throw new Exception(
|
||||
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
|
||||
// for discussion. This is usually a user adding "ssh://" to an implicit
|
||||
|
|
|
@ -191,11 +191,6 @@ final class PhabricatorRepositoryURI
|
|||
return self::IO_NONE;
|
||||
}
|
||||
|
||||
|
||||
public function getDisplayURI() {
|
||||
return $this->getURIObject(false);
|
||||
}
|
||||
|
||||
public function getNormalizedURI() {
|
||||
$vcs = $this->getRepository()->getVersionControlSystem();
|
||||
|
||||
|
@ -216,8 +211,12 @@ final class PhabricatorRepositoryURI
|
|||
return $normal_uri->getNormalizedURI();
|
||||
}
|
||||
|
||||
public function getDisplayURI() {
|
||||
return $this->getURIObject();
|
||||
}
|
||||
|
||||
public function getEffectiveURI() {
|
||||
return $this->getURIObject(true);
|
||||
return $this->getURIObject();
|
||||
}
|
||||
|
||||
public function getURIEnvelope() {
|
||||
|
@ -243,11 +242,10 @@ final class PhabricatorRepositoryURI
|
|||
return new PhutilOpaqueEnvelope((string)$uri);
|
||||
}
|
||||
|
||||
private function getURIObject($normalize) {
|
||||
private function getURIObject() {
|
||||
// Users can provide Git/SCP-style URIs in the form "user@host:path".
|
||||
// These are equivalent to "ssh://user@host/path". We use the more standard
|
||||
// form internally, and convert to it if we need to specify a port number,
|
||||
// but try to preserve what the user typed when displaying the URI.
|
||||
// In the general case, these are not equivalent to any "ssh://..." form
|
||||
// because the path is relative.
|
||||
|
||||
if ($this->isBuiltin()) {
|
||||
$builtin_protocol = $this->getForcedProtocol();
|
||||
|
@ -271,26 +269,6 @@ final class PhabricatorRepositoryURI
|
|||
// with it; this should always be provided by the associated credential.
|
||||
$uri->setPass(null);
|
||||
|
||||
if (!$uri->getProtocol()) {
|
||||
$git_uri = new PhutilGitURI($raw_uri);
|
||||
|
||||
// We must normalize this Git-style URI into a normal URI
|
||||
$must_normalize = ($port && ($port != $default_ports['ssh']));
|
||||
if ($must_normalize || $normalize) {
|
||||
$domain = $git_uri->getDomain();
|
||||
|
||||
|
||||
$uri = id(new PhutilURI("ssh://{$domain}"))
|
||||
->setUser($git_uri->getUser())
|
||||
->setPath($git_uri->getPath());
|
||||
} else {
|
||||
$uri = $git_uri;
|
||||
}
|
||||
}
|
||||
|
||||
$is_normal = ($uri instanceof PhutilURI);
|
||||
|
||||
if ($is_normal) {
|
||||
$protocol = $this->getForcedProtocol();
|
||||
if ($protocol) {
|
||||
$uri->setProtocol($protocol);
|
||||
|
@ -308,7 +286,6 @@ final class PhabricatorRepositoryURI
|
|||
if ($uri_default && ($uri_default == $uri_port)) {
|
||||
$uri->setPort(null);
|
||||
}
|
||||
}
|
||||
|
||||
$user = $this->getForcedUser();
|
||||
if ($user) {
|
||||
|
|
Loading…
Reference in a new issue