1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 12:30: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:
epriestley 2016-06-13 05:22:00 -07:00
parent fb156af480
commit bba53205de
4 changed files with 29 additions and 104 deletions

View file

@ -69,11 +69,6 @@ EOTEXT
$uri_object = new PhutilURI($uri); $uri_object = new PhutilURI($uri);
$domain = $uri_object->getDomain(); $domain = $uri_object->getDomain();
if (!strlen($domain)) {
$uri_object = new PhutilGitURI($uri);
$domain = $uri_object->getDomain();
}
$domain = phutil_utf8_strtolower($domain); $domain = phutil_utf8_strtolower($domain);
switch ($domain) { switch ($domain) {
case 'github.com': case 'github.com':

View file

@ -78,16 +78,7 @@ final class PhabricatorRepositoryURINormalizer extends Phobject {
switch ($this->type) { switch ($this->type) {
case self::TYPE_GIT: case self::TYPE_GIT:
$uri = new PhutilURI($this->uri); $uri = new PhutilURI($this->uri);
if ($uri->getProtocol()) {
return $uri->getPath(); return $uri->getPath();
}
$uri = new PhutilGitURI($this->uri);
if ($uri->getDomain()) {
return $uri->getPath();
}
return $this->uri;
case self::TYPE_SVN: case self::TYPE_SVN:
case self::TYPE_MERCURIAL: case self::TYPE_MERCURIAL:
$uri = new PhutilURI($this->uri); $uri = new PhutilURI($this->uri);
@ -136,14 +127,7 @@ final class PhabricatorRepositoryURINormalizer extends Phobject {
$domain = null; $domain = null;
$uri = new PhutilURI($this->uri); $uri = new PhutilURI($this->uri);
if ($uri->getProtocol()) {
$domain = $uri->getDomain(); $domain = $uri->getDomain();
}
if (!strlen($domain)) {
$uri = new PhutilGitURI($this->uri);
$domain = $uri->getDomain();
}
if (!strlen($domain)) { if (!strlen($domain)) {
$domain = '<void>'; $domain = '<void>';

View file

@ -1201,27 +1201,19 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
*/ */
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('');
} }
@ -1229,17 +1221,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
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));
} }
@ -1666,27 +1648,14 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
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

View file

@ -191,11 +191,6 @@ final class PhabricatorRepositoryURI
return self::IO_NONE; return self::IO_NONE;
} }
public function getDisplayURI() {
return $this->getURIObject(false);
}
public function getNormalizedURI() { public function getNormalizedURI() {
$vcs = $this->getRepository()->getVersionControlSystem(); $vcs = $this->getRepository()->getVersionControlSystem();
@ -216,8 +211,12 @@ final class PhabricatorRepositoryURI
return $normal_uri->getNormalizedURI(); return $normal_uri->getNormalizedURI();
} }
public function getDisplayURI() {
return $this->getURIObject();
}
public function getEffectiveURI() { public function getEffectiveURI() {
return $this->getURIObject(true); return $this->getURIObject();
} }
public function getURIEnvelope() { public function getURIEnvelope() {
@ -243,11 +242,10 @@ final class PhabricatorRepositoryURI
return new PhutilOpaqueEnvelope((string)$uri); 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". // 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 // In the general case, these are not equivalent to any "ssh://..." form
// form internally, and convert to it if we need to specify a port number, // because the path is relative.
// but try to preserve what the user typed when displaying the URI.
if ($this->isBuiltin()) { if ($this->isBuiltin()) {
$builtin_protocol = $this->getForcedProtocol(); $builtin_protocol = $this->getForcedProtocol();
@ -271,26 +269,6 @@ final class PhabricatorRepositoryURI
// with it; this should always be provided by the associated credential. // with it; this should always be provided by the associated credential.
$uri->setPass(null); $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(); $protocol = $this->getForcedProtocol();
if ($protocol) { if ($protocol) {
$uri->setProtocol($protocol); $uri->setProtocol($protocol);
@ -308,7 +286,6 @@ final class PhabricatorRepositoryURI
if ($uri_default && ($uri_default == $uri_port)) { if ($uri_default && ($uri_default == $uri_port)) {
$uri->setPort(null); $uri->setPort(null);
} }
}
$user = $this->getForcedUser(); $user = $this->getForcedUser();
if ($user) { if ($user) {