diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java index bdc9b3ecd..e6990fb83 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java @@ -549,6 +549,6 @@ public class URIishTest { public void testMissingPort() throws URISyntaxException { final String incorrectSshUrl = "ssh://some-host:/path/to/repository.git"; URIish u = new URIish(incorrectSshUrl); - assertFalse(TransportGitSsh.PROTO_SSH.canHandle(null, u, null)); + assertFalse(TransportGitSsh.PROTO_SSH.canHandle(u)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index f8c4a7bcd..d9583d015 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -542,8 +542,8 @@ public abstract class Transport { continue; } - if (proto.canHandle(local, uri, remoteName)) - return proto.open(local, uri, remoteName); + if (proto.canHandle(uri, local, remoteName)) + return proto.open(uri, local, remoteName); } throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index 0f65e0cac..d2cebd3d4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -118,7 +118,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { return Collections.unmodifiableSet(EnumSet.of(URIishField.PASS)); } - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException { return new TransportAmazonS3(local, uri); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java index 15aa1fff0..856e10536 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java @@ -78,7 +78,7 @@ class TransportBundleFile extends Transport implements TransportBundle { } @Override - public boolean canHandle(Repository local, URIish uri, String remoteName) { + public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getPath() == null || uri.getPort() > 0 || uri.getUser() != null @@ -90,7 +90,7 @@ class TransportBundleFile extends Transport implements TransportBundle { } @Override - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException, TransportException { if ("bundle".equals(uri.getScheme())) { File path = local.getFS().resolve(new File("."), uri.getPath()); @@ -102,7 +102,7 @@ class TransportBundleFile extends Transport implements TransportBundle { // resolve the path and figure out which type it is by testing // the target. // - return TransportLocal.PROTO_LOCAL.open(local, uri, remoteName); + return TransportLocal.PROTO_LOCAL.open(uri, local, remoteName); } }; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java index 081e7a90b..dedd1f694 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java @@ -96,7 +96,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport { return GIT_PORT; } - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException { return new TransportGitAnon(local, uri); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java index a0cb8a380..47959f5c9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java @@ -116,7 +116,7 @@ public class TransportGitSsh extends SshTransport implements PackTransport { } @Override - public boolean canHandle(Repository local, URIish uri, String remoteName) { + public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getScheme() == null) { // scp-style URI "host:path" does not have scheme. return uri.getHost() != null @@ -124,10 +124,10 @@ public class TransportGitSsh extends SshTransport implements PackTransport { && uri.getHost().length() != 0 && uri.getPath().length() != 0; } - return super.canHandle(local, uri, remoteName); + return super.canHandle(uri, local, remoteName); } - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException { return new TransportGitSsh(local, uri); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index bb69b8c07..43ad98985 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -163,7 +163,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, return 80; } - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException { return new TransportHttp(local, uri); } @@ -192,7 +192,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, return 21; } - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException { return new TransportHttp(local, uri); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java index 280b7c58e..5c4855118 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java @@ -104,7 +104,7 @@ class TransportLocal extends Transport implements PackTransport { } @Override - public boolean canHandle(Repository local, URIish uri, String remoteName) { + public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getPath() == null || uri.getPort() > 0 || uri.getUser() != null @@ -116,7 +116,7 @@ class TransportLocal extends Transport implements PackTransport { } @Override - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NoRemoteRepositoryException { // If the reference is to a local file, C Git behavior says // assume this is a bundle, since repositories are directories. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java index a55f495a6..32fa58046 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java @@ -138,17 +138,40 @@ public abstract class TransportProtocol { * {@link #getOptionalFields()}, returning true only if all of the fields * match the specification. * - * @param local - * the local repository that will communicate with the other Git - * repository. * @param uri * address of the Git repository; never null. + * @return true if this protocol can handle this URI; false otherwise. + */ + public boolean canHandle(URIish uri) { + return canHandle(uri, null, null); + } + + /** + * Determine if this protocol can handle a particular URI. + *
+ * Implementations should try to avoid looking at the local filesystem, but + * may look at implementation specific configuration options in the remote + * block of {@code local.getConfig()} using {@code remoteName} if the name + * is non-null. + *
+ * The default implementation of this method matches the scheme against + * {@link #getSchemes()}, required fields against + * {@link #getRequiredFields()}, and optional fields against + * {@link #getOptionalFields()}, returning true only if all of the fields + * match the specification. + * + * @param uri + * address of the Git repository; never null. + * @param local + * the local repository that will communicate with the other Git + * repository. May be null if the caller is only asking about a + * specific URI and does not have a local Repository. * @param remoteName * name of the remote, if the remote as configured in * {@code local}; otherwise null. * @return true if this protocol can handle this URI; false otherwise. */ - public boolean canHandle(Repository local, URIish uri, String remoteName) { + public boolean canHandle(URIish uri, Repository local, String remoteName) { if (!getSchemes().isEmpty() && !getSchemes().contains(uri.getScheme())) return false; @@ -213,11 +236,11 @@ public abstract class TransportProtocol { * within {@code local.getConfig()} using the remote block named by the * {@code remoteName}, if the name is non-null. * + * @param uri + * address of the Git repository. * @param local * the local repository that will communicate with the other Git * repository. - * @param uri - * address of the Git repository. * @param remoteName * name of the remote, if the remote as configured in * {@code local}; otherwise null. @@ -227,7 +250,7 @@ public abstract class TransportProtocol { * @throws TransportException * the transport cannot open this URI. */ - public abstract Transport open(Repository local, URIish uri, + public abstract Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException, TransportException; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java index c2e3662ff..9ab4a9926 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java @@ -120,7 +120,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { return 22; } - public Transport open(Repository local, URIish uri, String remoteName) + public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException { return new TransportSftp(local, uri); }